Let mods mark articles that require approval as approved. (#6513) [deploy]
* Initial work to add approval to regular mod flow * Add article_approvals controller and tests * Add check for moderatable being article
This commit is contained in:
parent
761a961fc6
commit
4eb0080eee
5 changed files with 91 additions and 2 deletions
|
|
@ -159,6 +159,12 @@
|
|||
|
||||
.mod-container {
|
||||
padding: 30px 0px;
|
||||
h2 {
|
||||
a {
|
||||
@include themeable(color, theme-color, $black);
|
||||
}
|
||||
margin-bottom: -12px;
|
||||
}
|
||||
p {
|
||||
width: 98%;
|
||||
max-width: 720px;
|
||||
|
|
@ -332,6 +338,15 @@
|
|||
border: solid 2px;
|
||||
margin: 5px auto 15px;
|
||||
}
|
||||
.approval-button {
|
||||
font-size: 20px;
|
||||
border: 0px;
|
||||
border-radius: 3px;
|
||||
padding: 8px 16px;
|
||||
&.approval-removal {
|
||||
background: $red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.mod-link {
|
||||
|
|
|
|||
13
app/controllers/article_approvals_controller.rb
Normal file
13
app/controllers/article_approvals_controller.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class ArticleApprovalsController < ApplicationController
|
||||
def create
|
||||
@article = Article.find(params[:id])
|
||||
unless current_user.any_admin?
|
||||
authorize(User, :moderation_routes?)
|
||||
@article.decorate.cached_tag_list_array.each do |tag|
|
||||
authorize(Tag.find_by(name: tag), :update?)
|
||||
end
|
||||
end
|
||||
@article.update(approved: params[:approved])
|
||||
redirect_to "#{URI.parse(@article.path).path}/mod"
|
||||
end
|
||||
end
|
||||
|
|
@ -7,8 +7,24 @@
|
|||
<% end %>
|
||||
|
||||
<div class="container mod-container" style="text-align: center">
|
||||
<h2>Moderate: <a href="<%= @moderatable.path %>" rel="nofollow"><%= @moderatable.title %></a></h2>
|
||||
<h2>Author: <a href="<%= @moderatable.user.path %>"><%= @moderatable.user.username %></a></h2>
|
||||
<h2><a href="<%= @moderatable.path %>" rel="nofollow"><%= @moderatable.title %></a></h2>
|
||||
<h3><a href="<%= @moderatable.user.path %>">@<%= @moderatable.user.username %></a></h3>
|
||||
<% if @moderatable.class.name == "Article" &&
|
||||
(Tag.where(requires_approval: true).pluck(:name) & @moderatable.decorate.cached_tag_list_array).any? &&
|
||||
(current_user.any_admin? || @tag_moderator_tags.any? { |tag| @moderatable.tag_list.include?(tag.name) })
|
||||
%>
|
||||
<%= form_tag "/article_approvals", method: "post" do %>
|
||||
<%= hidden_field_tag(:id, @moderatable.id) %>
|
||||
<% if @moderatable.approved %>
|
||||
<%= hidden_field_tag(:approved, false) %>
|
||||
<button class="cta approval-button approval-removal">Remove approval</button>
|
||||
<% else %>
|
||||
<%= hidden_field_tag(:approved, true) %>
|
||||
<button class="cta approval-button">Mark as approved</button>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<hr />
|
||||
<% end %>
|
||||
|
||||
<button class="reaction-button <%= Reaction.cached_any_reactions_for?(@moderatable, current_user, "thumbsdown") ? "reacted" : "" %>"
|
||||
data-reactable-id="<%= @moderatable.id %>"
|
||||
|
|
|
|||
|
|
@ -212,6 +212,7 @@ Rails.application.routes.draw do
|
|||
resource :pro_membership, path: :pro, only: %i[show create update]
|
||||
resources :user_blocks, param: :blocked_id, only: %i[show create destroy]
|
||||
resources :podcasts, only: %i[new create]
|
||||
resources :article_approvals, only: %i[create]
|
||||
resolve("ProMembership") { [:pro_membership] } # see https://guides.rubyonrails.org/routing.html#using-resolve
|
||||
namespace :followings, defaults: { format: :json } do
|
||||
get :users
|
||||
|
|
|
|||
44
spec/requests/article_approvals_spec.rb
Normal file
44
spec/requests/article_approvals_spec.rb
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "ArticleApprovals", type: :request do
|
||||
describe "POST article_approvals" do
|
||||
let(:tag) { create(:tag) }
|
||||
let(:user) { create(:user) }
|
||||
let(:article) { create(:article, tags: tag.name) }
|
||||
|
||||
context "when user is not tag mod" do
|
||||
before do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it "does not allow update" do
|
||||
expect { post "/article_approvals", params: { approved: true, id: article.id } }.to raise_error(Pundit::NotAuthorizedError)
|
||||
end
|
||||
end
|
||||
|
||||
context "when user is a tag mod" do
|
||||
before do
|
||||
user.add_role(:tag_moderator, tag)
|
||||
user.add_role(:trusted)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it "does allow update" do
|
||||
post "/article_approvals", params: { approved: true, id: article.id }
|
||||
expect(article.reload.approved).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
context "when user is admin" do
|
||||
before do
|
||||
user.add_role(:admin)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it "does allow update" do
|
||||
post "/article_approvals", params: { approved: true, id: article.id }
|
||||
expect(article.reload.approved).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue