2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2020-03-19 09:39:51 +00:00
|
|
|
class Controllers::KnowledgeBase::AnswersControllerPolicy < Controllers::KnowledgeBase::BaseControllerPolicy
|
|
|
|
def show?
|
2022-02-24 11:15:19 +00:00
|
|
|
access(__method__)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create?
|
|
|
|
verify_category(__method__)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
|
|
|
access(__method__) && verify_category(__method__)
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy?
|
|
|
|
access(__method__)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def object
|
|
|
|
@object ||= record.klass.find(record.params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def access(method)
|
|
|
|
KnowledgeBase::AnswerPolicy.new(user, object).send(method)
|
|
|
|
end
|
|
|
|
|
|
|
|
def verify_category(method)
|
|
|
|
new_category = KnowledgeBase::Category.find(record.params[:category_id])
|
2020-03-19 09:39:51 +00:00
|
|
|
|
2022-02-24 11:15:19 +00:00
|
|
|
KnowledgeBase::CategoryPolicy.new(user, new_category).send(method)
|
2020-03-19 09:39:51 +00:00
|
|
|
end
|
|
|
|
end
|