docbrown/app/controllers/article_approvals_controller.rb
yheuhtozr c4778d832e
app/controllers & decorators i18n (#16126)
* app/controllers (& decorators) i18n etc

* tidy key names

* update keys

* delete ja.yml

* delete an involved ja.yml

* fix for PR review

* fix for spec

* delete ja.yml
2022-02-03 13:35:56 -05:00

19 lines
733 B
Ruby

class ArticleApprovalsController < ApplicationController
def create
@article = Article.find(params[:id])
unless current_user.any_admin?
# Check that user is trusted
authorize(User, :moderation_routes?)
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