role_policy.rb 567 B

12345678910111213141516171819202122232425262728
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class RolePolicy < ApplicationPolicy
  3. def show?
  4. return true if admin?
  5. if user.role_ids.include? record.id
  6. return agent? ? true : customer_field_scope
  7. end
  8. false
  9. end
  10. private
  11. def admin?
  12. user.permissions?('admin.role')
  13. end
  14. def agent?
  15. user.permissions?('ticket.agent')
  16. end
  17. def customer_field_scope
  18. # Filter out name as well.
  19. @customer_field_scope ||= ApplicationPolicy::FieldScope.new(allow: %w[id groups permissions active])
  20. end
  21. end