organization_policy.rb 569 B

12345678910111213141516171819202122232425262728
  1. class OrganizationPolicy < ApplicationPolicy
  2. def show?
  3. return true if user.permissions?(['admin', 'ticket.agent'])
  4. return true if record.id == user.organization_id
  5. false
  6. end
  7. def update?
  8. return true if user.permissions?(['admin', 'ticket.agent'])
  9. false
  10. end
  11. class Scope < ApplicationPolicy::Scope
  12. def resolve
  13. if user.permissions?(['ticket.agent', 'admin.organization'])
  14. scope.all
  15. elsif user.organization_id
  16. scope.where(id: user.organization_id)
  17. else
  18. scope.none
  19. end
  20. end
  21. end
  22. end