answers_controller_policy.rb 766 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Controllers::KnowledgeBase::AnswersControllerPolicy < Controllers::KnowledgeBase::BaseControllerPolicy
  3. def show?
  4. access(__method__)
  5. end
  6. def create?
  7. verify_category(__method__)
  8. end
  9. def update?
  10. access(__method__) && verify_category(__method__)
  11. end
  12. def destroy?
  13. access(__method__)
  14. end
  15. private
  16. def object
  17. @object ||= record.klass.find(record.params[:id])
  18. end
  19. def access(method)
  20. KnowledgeBase::AnswerPolicy.new(user, object).send(method)
  21. end
  22. def verify_category(method)
  23. new_category = KnowledgeBase::Category.find(record.params[:category_id])
  24. KnowledgeBase::CategoryPolicy.new(user, new_category).send(method)
  25. end
  26. end