permission.rb 844 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class Organization
  3. module Permission
  4. =begin
  5. check if user has access to user
  6. user = Organization.find(123)
  7. result = organization.permission(type: 'rw', 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 organization
  15. return false if data[:type] != 'ro'
  16. return false if !data[:current_user].organization_id
  17. return true if id == data[:current_user].organization_id
  18. # no access
  19. return false
  20. end
  21. # check agent
  22. return true if data[:current_user].role?(Z_ROLENAME_ADMIN)
  23. return true if data[:current_user].role?('Agent')
  24. false
  25. end
  26. end
  27. end