category_policy.rb 898 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class KnowledgeBase::CategoryPolicy < ApplicationPolicy
  3. def show?
  4. access_editor? || access_reader?
  5. end
  6. def show_public?
  7. access_editor? || record.public_content?
  8. end
  9. def permissions?
  10. access_editor?
  11. end
  12. def create?
  13. parent_editor?
  14. end
  15. def update?
  16. access_editor?
  17. end
  18. def destroy?
  19. parent_editor?
  20. end
  21. private
  22. def access
  23. @access ||= KnowledgeBase::EffectivePermission.new(user, record).access_effective
  24. end
  25. def access_editor?
  26. access == 'editor'
  27. end
  28. def access_reader?
  29. access == 'reader'
  30. end
  31. def parent_access
  32. @parent_access ||= KnowledgeBase::EffectivePermission.new(user, (record.parent || record.knowledge_base)).access_effective
  33. end
  34. def parent_editor?
  35. parent_access == 'editor'
  36. end
  37. def user_required?
  38. false
  39. end
  40. end