docbrown/app/controllers/article_approvals_controller.rb
Arit Developer 253cb27559
Refactor :moderation_routes? method to use correct policies (#18183)
* complete implementation

* add spec coverage; remove test-db cleansers
2022-07-25 07:58:41 -04:00

19 lines
753 B
Ruby

class ArticleApprovalsController < ApplicationController
def create
@article = Article.find(params[:id])
unless current_user.any_admin?
# Check that the article can be moderated by the user
authorize(@article, :moderate?)
tags = @article.decorate.tags
# Raise if no tags require approval to begin with
raise Pundit::NotAuthorizedError unless tags.pluck(:requires_approval).include?(true)
# Raise if user is not authorized to approve any tag that requires approval.
tags.each do |tag|
authorize(Tag.find(tag.id), :update?) if tag.requires_approval
end
end
@article.update(approved: params[:approved])
redirect_to "#{Addressable::URI.parse(@article.path).path}/mod"
end
end