permission.rb 1015 B

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