permission.rb 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. module Ticket::Permission
  3. =begin
  4. check if user has access to ticket
  5. ticket = Ticket.find(123)
  6. result = ticket.permission( :current_user => User.find(123) )
  7. returns
  8. result = true|false
  9. =end
  10. def permission (data)
  11. # check customer
  12. if data[:current_user].is_role('Customer')
  13. # access ok if its own ticket
  14. return true if self.customer_id == data[:current_user].id
  15. # access ok if its organization ticket
  16. if data[:current_user].organization_id && self.organization_id
  17. return true if self.organization_id == data[:current_user].organization_id
  18. end
  19. # no access
  20. return false
  21. end
  22. # check agent
  23. # access if requestor is owner
  24. return true if self.owner_id == data[:current_user].id
  25. # access if requestor is in group
  26. data[:current_user].groups.each {|group|
  27. return true if self.group.id == group.id
  28. }
  29. return false
  30. end
  31. end