approvals: move post approval endpoint to /post_approvals.

Move the post approval endpoint from `POST /moderator/post/approval` to
`POST /post_approvals`.
This commit is contained in:
evazion
2020-02-20 15:37:18 -06:00
parent 610ad9e119
commit f47c56d976
10 changed files with 30 additions and 48 deletions

View File

@@ -1,16 +0,0 @@
module Moderator
module Post
class ApprovalsController < ApplicationController
before_action :approver_only
skip_before_action :api_check
respond_to :json, :xml, :js
def create
cookies.permanent[:moderated] = Time.now.to_i
post = ::Post.find(params[:post_id])
@approval = post.approve!
respond_with(:moderator, @approval)
end
end
end
end

View File

@@ -1,5 +1,13 @@
class PostApprovalsController < ApplicationController
respond_to :html, :xml, :json
before_action :approver_only, only: [:create]
respond_to :html, :xml, :json, :js
def create
cookies.permanent[:moderated] = Time.now.to_i
post = Post.find(params[:post_id])
@approval = post.approve!
respond_with(@approval)
end
def index
@post_approvals = PostApproval.paginated_search(params)

View File

@@ -523,7 +523,7 @@ Post.update = function(post_id, params) {
Post.approve = function(post_id) {
$.post(
"/moderator/post/approval.json",
"/post_approvals.json",
{"post_id": post_id}
).fail(function(data) {
var message = $.map(data.responseJSON.errors, function(msg, attr) { return msg; }).join("; ");

View File

@@ -1,5 +1,5 @@
<div class="quick-mod">
<%= link_to_if post.is_approvable?, "Approve", moderator_post_approval_path(post_id: post.id), method: :post, remote: true, class: "approve-link btn" %> |
<%= link_to_if post.is_approvable?, "Approve", post_approvals_path(post_id: post.id), method: :post, remote: true, class: "approve-link btn" %> |
<%= link_to "Breaks Rules", post_disapprovals_path(post_disapproval: { post_id: post.id, reason: "breaks_rules" }), method: :post, remote: true, class: "disapprove-link btn" %> |
<%= link_to "Poor Quality", post_disapprovals_path(post_disapproval: { post_id: post.id, reason: "poor_quality" }), method: :post, remote: true, class: "disapprove-link btn" %> |
<%= link_to "No Interest", post_disapprovals_path(post_disapproval: { post_id: post.id, reason: "disinterest" }), method: :post, remote: true, class: "disapprove-link btn" %> |

View File

@@ -51,7 +51,7 @@
<% end %>
<% if post.is_approvable? && !post.is_deleted? %>
<li id="post-option-approve"><%= link_to "Approve", moderator_post_approval_path(post_id: post.id), remote: true, method: :post, id: "approve", "data-shortcut": "shift+o", "data-confirm": "Are you sure you want to approve this post?" %></li>
<li id="post-option-approve"><%= link_to "Approve", post_approvals_path(post_id: post.id), remote: true, method: :post, id: "approve", "data-shortcut": "shift+o", "data-confirm": "Are you sure you want to approve this post?" %></li>
<li id="post-option-disapprove"><%= link_to "Hide from queue", post_disapprovals_path(post_disapproval: { post_id: post.id, reason: "disinterest" }), remote: true, method: :post, id: "disapprove" %></li>
<% end %>

View File

@@ -19,7 +19,6 @@ Rails.application.routes.draw do
get :random
end
end
resource :approval, :only => [:create]
resources :posts, :only => [:delete, :undelete, :expunge, :confirm_delete] do
member do
get :confirm_delete
@@ -204,7 +203,7 @@ Rails.application.routes.draw do
end
resources :post_appeals
resources :post_flags
resources :post_approvals, only: [:index]
resources :post_approvals, only: [:create, :index]
resources :post_disapprovals, only: [:create, :show, :index]
resources :post_versions, :only => [:index, :search] do
member do

View File

@@ -62,5 +62,10 @@ FactoryBot.define do
factory(:uploader) do
created_at { 2.weeks.ago }
end
factory(:approver) do
level {32}
can_approve_posts {true}
end
end
end

View File

@@ -1,25 +0,0 @@
require 'test_helper'
module Moderator
module Post
class ApprovalsControllerTest < ActionDispatch::IntegrationTest
context "The moderator post approvals controller" do
setup do
@admin = create(:admin_user)
as_admin do
@post = create(:post, :is_pending => true)
end
end
context "create action" do
should "render" do
post_auth moderator_post_approval_path, @admin, params: {:post_id => @post.id, :format => "js"}
assert_response :success
@post.reload
assert(!@post.is_pending?)
end
end
end
end
end
end

View File

@@ -3,11 +3,22 @@ require 'test_helper'
class PostApprovalsControllerTest < ActionDispatch::IntegrationTest
context "The post approvals controller" do
setup do
@approval = FactoryBot.create(:post_approval)
@approver = create(:approver)
end
context "create action" do
should "render" do
@post = create(:post, is_pending: true)
post_auth post_approvals_path(post_id: @post.id, format: :js), @approver
assert_response :success
assert(!@post.reload.is_pending?)
end
end
context "index action" do
should "render" do
@approval = create(:post_approval)
get post_approvals_path
assert_response :success
end