fixes #2199
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
class BulkUpdateRequestsController < ApplicationController
|
class BulkUpdateRequestsController < ApplicationController
|
||||||
respond_to :html, :xml, :json
|
respond_to :html, :xml, :json
|
||||||
before_filter :member_only
|
before_filter :member_only
|
||||||
before_filter :admin_only, :only => [:update]
|
before_filter :admin_only, :only => [:approve]
|
||||||
|
before_filter :load_bulk_update_request, :except => [:new, :create, :index]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@bulk_update_request = BulkUpdateRequest.new(:user_id => CurrentUser.user.id)
|
@bulk_update_request = BulkUpdateRequest.new(:user_id => CurrentUser.user.id)
|
||||||
@@ -13,19 +14,43 @@ class BulkUpdateRequestsController < ApplicationController
|
|||||||
respond_with(@bulk_update_request, :location => bulk_update_requests_path)
|
respond_with(@bulk_update_request, :location => bulk_update_requests_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@bulk_update_request = BulkUpdateRequest.find(params[:id])
|
if @bulk_update_request.editable?(CurrentUser.user)
|
||||||
if params[:status] == "approved"
|
@bulk_update_request.update_attributes(params[:bulk_update_request])
|
||||||
@bulk_update_request.approve!
|
flash[:notice] = "Bulk update request updated"
|
||||||
|
respond_with(@bulk_update_request, :location => bulk_update_requests_path)
|
||||||
else
|
else
|
||||||
@bulk_update_request.reject!
|
access_denied()
|
||||||
end
|
end
|
||||||
flash[:notice] = "Bulk update request updated"
|
end
|
||||||
|
|
||||||
|
def approve
|
||||||
|
@bulk_update_request.approve!
|
||||||
|
flash[:notice] = "Bulk update request approved"
|
||||||
respond_with(@bulk_update_request, :location => bulk_update_requests_path)
|
respond_with(@bulk_update_request, :location => bulk_update_requests_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @bulk_update_request.editable?(CurrentUser.user)
|
||||||
|
@bulk_update_request.destroy
|
||||||
|
flash[:notice] = "Bulk update request deleted"
|
||||||
|
respond_with(@bulk_update_request, :location => bulk_update_requests_path)
|
||||||
|
else
|
||||||
|
access_denied()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@bulk_update_requests = BulkUpdateRequest.order("(case status when 'pending' then 0 when 'approved' then 1 else 2 end), id desc").paginate(params[:page], :limit => params[:limit])
|
@bulk_update_requests = BulkUpdateRequest.order("(case status when 'pending' then 0 when 'approved' then 1 else 2 end), id desc").paginate(params[:page], :limit => params[:limit])
|
||||||
respond_with(@bulk_update_requests)
|
respond_with(@bulk_update_requests)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_bulk_update_request
|
||||||
|
@bulk_update_request = BulkUpdateRequest.find(params[:id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ class BulkUpdateRequest < ActiveRecord::Base
|
|||||||
update_attribute(:status, "approved")
|
update_attribute(:status, "approved")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def editable?(user)
|
||||||
|
user_id == user.id || user.is_janitor?
|
||||||
|
end
|
||||||
|
|
||||||
def create_forum_topic
|
def create_forum_topic
|
||||||
forum_topic = ForumTopic.create(:title => "[bulk] #{title}", :category_id => 1, :original_post_attributes => {:body => reason_with_link})
|
forum_topic = ForumTopic.create(:title => "[bulk] #{title}", :category_id => 1, :original_post_attributes => {:body => reason_with_link})
|
||||||
update_attribute(:forum_topic_id, forum_topic.id)
|
update_attribute(:forum_topic_id, forum_topic.id)
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class ForumPost < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def validate_topic_is_unlocked
|
def validate_topic_is_unlocked
|
||||||
return if CurrentUser.is_janitor?
|
return if CurrentUser.user.is_janitor?
|
||||||
return if topic.nil?
|
return if topic.nil?
|
||||||
|
|
||||||
if topic.is_locked?
|
if topic.is_locked?
|
||||||
|
|||||||
25
app/views/bulk_update_requests/_form.html.erb
Normal file
25
app/views/bulk_update_requests/_form.html.erb
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<%= simple_form_for(@bulk_update_request) do |f| %>
|
||||||
|
<%= error_messages_for("bulk_update_request") %>
|
||||||
|
|
||||||
|
<%= f.input :title, :as => :string %>
|
||||||
|
|
||||||
|
<div class="input">
|
||||||
|
<label class="text optional" for="bulk_update_request_script">Script</label>
|
||||||
|
<pre class="hint">
|
||||||
|
Use the following format:
|
||||||
|
remove alias aaa -> bbb
|
||||||
|
remove implication aaa -> bbb
|
||||||
|
create alias aaa -> bbb
|
||||||
|
create implication aaa -> bbb
|
||||||
|
mass update aaa -> bbb
|
||||||
|
</pre>
|
||||||
|
<%= text_area :bulk_update_request, :script, :size => "50x10" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input">
|
||||||
|
<%= dtext_field "bulk_update_request", "reason", :name => "Reason" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= f.button :submit, :value => "Submit" %>
|
||||||
|
<%= dtext_preview_button "bulk_update_request", "reason" %>
|
||||||
|
<% end %>
|
||||||
12
app/views/bulk_update_requests/edit.html.erb
Normal file
12
app/views/bulk_update_requests/edit.html.erb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<div class="bulk-update-requests">
|
||||||
|
<div class="new">
|
||||||
|
<h1>Edit Bulk Update Request</h1>
|
||||||
|
<%= render "form" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render "secondary_links" %>
|
||||||
|
|
||||||
|
<% content_for(:page_title) do %>
|
||||||
|
Edit Bulk Update Request - <%= Danbooru.config.app_name %>
|
||||||
|
<% end %>
|
||||||
@@ -21,8 +21,11 @@
|
|||||||
<td><%= request.status %></td>
|
<td><%= request.status %></td>
|
||||||
<td>
|
<td>
|
||||||
<% if CurrentUser.is_moderator? && request.status == "pending" %>
|
<% if CurrentUser.is_moderator? && request.status == "pending" %>
|
||||||
<%= link_to "Approve", bulk_update_request_path(request, :status => "approved"), :method => :put %>
|
<%= link_to "Approve", approve_bulk_update_request_path(request), :method => :post %> |
|
||||||
| <%= link_to "Reject", bulk_update_request_path(request, :status => "rejected"), :method => :put %>
|
<% end %>
|
||||||
|
<% if request.editable?(CurrentUser.user) %>
|
||||||
|
<%= link_to "Delete", bulk_update_request_path(request), :method => :delete %> |
|
||||||
|
<%= link_to "Edit", edit_bulk_update_request_path(request) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -1,32 +1,8 @@
|
|||||||
<div class="bulk-update-requests">
|
<div class="bulk-update-requests">
|
||||||
<div class="new">
|
<div class="new">
|
||||||
<h1>New Bulk Update Request</h1>
|
<h1>New Bulk Update Request</h1>
|
||||||
<%= simple_form_for(@bulk_update_request) do |f| %>
|
|
||||||
<%= error_messages_for("bulk_update_request") %>
|
|
||||||
|
|
||||||
<%= f.input :title, :as => :string %>
|
|
||||||
|
|
||||||
<div class="input">
|
|
||||||
<label class="text optional" for="bulk_update_request_script">Script</label>
|
|
||||||
<pre class="hint">
|
|
||||||
Use the following format:
|
|
||||||
remove alias aaa -> bbb
|
|
||||||
remove implication aaa -> bbb
|
|
||||||
create alias aaa -> bbb
|
|
||||||
create implication aaa -> bbb
|
|
||||||
mass update aaa -> bbb
|
|
||||||
</pre>
|
|
||||||
<%= text_area :bulk_update_request, :script, :size => "50x10", :required => true %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="input">
|
|
||||||
<%= dtext_field "bulk_update_request", "reason", :name => "Reason" %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<%= f.button :submit, :value => "Submit" %>
|
|
||||||
<%= dtext_preview_button "bulk_update_request", "reason" %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
|
<%= render "form" %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,11 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :bans
|
resources :bans
|
||||||
resources :bulk_update_requests
|
resources :bulk_update_requests do
|
||||||
|
member do
|
||||||
|
post :approve
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :comments do
|
resources :comments do
|
||||||
resources :votes, :controller => "comment_votes", :only => [:create, :destroy]
|
resources :votes, :controller => "comment_votes", :only => [:create, :destroy]
|
||||||
collection do
|
collection do
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
require 'test_helper'
|
|
||||||
|
|
||||||
class BulkUpdateRequestsControllerTest < ActionController::TestCase
|
|
||||||
context "BulkUpdateRequestsController" do
|
|
||||||
setup do
|
|
||||||
@user = FactoryGirl.create(:user)
|
|
||||||
@admin = FactoryGirl.create(:admin_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
context "#new" do
|
|
||||||
should "render" do
|
|
||||||
get :new, {}, {:user_id => @user.id}
|
|
||||||
assert_response :success
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "#create" do
|
|
||||||
should "succeed" do
|
|
||||||
assert_difference("BulkUpdateRequest.count", 1) do
|
|
||||||
post :create, {:bulk_update_request => {:script => "create alias aaa -> bbb"}}, {:user_id => @user.id}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "#index" do
|
|
||||||
setup do
|
|
||||||
@bulk_update_request = FactoryGirl.create(:bulk_update_request, :user_id => @admin.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "render" do
|
|
||||||
get :index, {}, {:user_id => @user.id}
|
|
||||||
assert_response :success
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "#update" do
|
|
||||||
setup do
|
|
||||||
@bulk_update_request = FactoryGirl.create(:bulk_update_request, :user_id => @admin.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
context "for a member" do
|
|
||||||
should "fail" do
|
|
||||||
post :update, {:status => "approved", :id => @bulk_update_request.id}, {:user_id => @user.id}
|
|
||||||
@bulk_update_request.reload
|
|
||||||
assert_equal("pending", @bulk_update_request.status)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "for an admin" do
|
|
||||||
should "succeed" do
|
|
||||||
post :update, {:status => "approved", :id => @bulk_update_request.id}, {:user_id => @admin.id}
|
|
||||||
@bulk_update_request.reload
|
|
||||||
assert_equal("approved", @bulk_update_request.status)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
98
test/functional/bulk_update_requests_controller_test.rb
Normal file
98
test/functional/bulk_update_requests_controller_test.rb
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class BulkUpdateRequestsControllerTest < ActionController::TestCase
|
||||||
|
context "BulkUpdateRequestsController" do
|
||||||
|
setup do
|
||||||
|
@user = FactoryGirl.create(:user)
|
||||||
|
@admin = FactoryGirl.create(:admin_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#new" do
|
||||||
|
should "render" do
|
||||||
|
get :new, {}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#create" do
|
||||||
|
should "succeed" do
|
||||||
|
assert_difference("BulkUpdateRequest.count", 1) do
|
||||||
|
post :create, {:bulk_update_request => {:script => "create alias aaa -> bbb"}}, {:user_id => @user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#index" do
|
||||||
|
setup do
|
||||||
|
CurrentUser.scoped(@user) do
|
||||||
|
@bulk_update_request = FactoryGirl.create(:bulk_update_request)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render" do
|
||||||
|
get :index, {}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#destroy" do
|
||||||
|
setup do
|
||||||
|
CurrentUser.scoped(@user) do
|
||||||
|
@bulk_update_request = FactoryGirl.create(:bulk_update_request)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for the creator" do
|
||||||
|
should "succeed" do
|
||||||
|
assert_difference("BulkUpdateRequest.count", -1) do
|
||||||
|
delete :destroy, {:id => @bulk_update_request.id}, {:user_id => @user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for another member" do
|
||||||
|
setup do
|
||||||
|
@another_user = FactoryGirl.create(:user)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "fail" do
|
||||||
|
assert_difference("BulkUpdateRequest.count", 0) do
|
||||||
|
delete :destroy, {:id => @bulk_update_request.id}, {:user_id => @another_user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for an admin" do
|
||||||
|
should "succeed" do
|
||||||
|
assert_difference("BulkUpdateRequest.count", -1) do
|
||||||
|
delete :destroy, {:id => @bulk_update_request.id}, {:user_id => @admin.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#approve" do
|
||||||
|
setup do
|
||||||
|
CurrentUser.scoped(@user) do
|
||||||
|
@bulk_update_request = FactoryGirl.create(:bulk_update_request)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for a member" do
|
||||||
|
should "fail" do
|
||||||
|
post :approve, {:id => @bulk_update_request.id}, {:user_id => @user.id}
|
||||||
|
@bulk_update_request.reload
|
||||||
|
assert_equal("pending", @bulk_update_request.status)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for an admin" do
|
||||||
|
should "succeed" do
|
||||||
|
post :approve, {:id => @bulk_update_request.id}, {:user_id => @admin.id}
|
||||||
|
@bulk_update_request.reload
|
||||||
|
assert_equal("approved", @bulk_update_request.status)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user