trabajo-afectivo/app/policies/controllers/knowledge_base/answers_controller_policy.rb

36 lines
766 B
Ruby
Raw Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
class Controllers::KnowledgeBase::AnswersControllerPolicy < Controllers::KnowledgeBase::BaseControllerPolicy
def show?
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])
KnowledgeBase::CategoryPolicy.new(user, new_category).send(method)
end
end