answer_policy.rb 879 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class KnowledgeBase::AnswerPolicy < ApplicationPolicy
  3. def show?
  4. return true if access_editor?
  5. record.visible? ||
  6. (access_reader? && record.visible_internally?)
  7. end
  8. def show_public?
  9. access_editor? || record.visible?
  10. end
  11. def create?
  12. access_editor?
  13. end
  14. def update?
  15. access_editor?
  16. end
  17. def destroy?
  18. access_editor?
  19. end
  20. def user_required?
  21. false
  22. end
  23. # Compatibility with Ticket policy
  24. # When using in GQL together with tickets
  25. # For example Tag mutations
  26. def agent_update_access?
  27. access_editor?
  28. end
  29. private
  30. def access
  31. @access ||= KnowledgeBase::EffectivePermission.new(user, record.category).access_effective
  32. end
  33. def access_editor?
  34. access == 'editor'
  35. end
  36. def access_reader?
  37. access == 'reader'
  38. end
  39. end