macro_policy.rb 592 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class MacroPolicy < ApplicationPolicy
  3. def show?
  4. return true if admin?
  5. agent_accessible?
  6. end
  7. def create?
  8. admin?
  9. end
  10. def update?
  11. admin?
  12. end
  13. def destroy?
  14. admin?
  15. end
  16. private
  17. def admin?
  18. user.permissions?('admin.group')
  19. end
  20. def agent_accessible?
  21. return false if !user.permissions?('ticket.agent')
  22. return false if !record.active
  23. group_ids = record.groups.pluck(:id)
  24. return true if group_ids.blank?
  25. group_ids.intersect? user.group_ids
  26. end
  27. end