forked from e621ng/e621ng
fixes #2190
This commit is contained in:
parent
7ea00d3ff6
commit
87ef2b8e0f
@ -25,7 +25,7 @@ class BulkUpdateRequestsController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@bulk_update_requests = BulkUpdateRequest.paginate(params[:page])
|
||||
@bulk_update_requests = BulkUpdateRequest.order("id desc").paginate(params[:page])
|
||||
respond_with(@bulk_update_requests)
|
||||
end
|
||||
end
|
||||
|
@ -1,18 +1,30 @@
|
||||
class BulkUpdateRequest < ActiveRecord::Base
|
||||
attr_accessor :title, :reason
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :forum_topic
|
||||
|
||||
validates_presence_of :user
|
||||
validates_inclusion_of :status, :in => %w(pending approved rejected)
|
||||
attr_accessible :user_id, :forum_topic_id, :script
|
||||
attr_accessible :user_id, :forum_topic_id, :script, :title, :reason
|
||||
attr_accessible :status, :as => [:admin]
|
||||
before_validation :initialize_attributes, :on => :create
|
||||
after_create :create_forum_topic
|
||||
|
||||
def approve!
|
||||
AliasAndImplicationImporter.new(script, forum_topic_id, "1").process!
|
||||
update_attribute(:status, "approved")
|
||||
end
|
||||
|
||||
def create_forum_topic
|
||||
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)
|
||||
end
|
||||
|
||||
def reason_with_link
|
||||
"[code]\n#{script}\n[/code]\n\nh4. Reason\n\n#{reason}\n\n\"Link to request\":/bulk_update_requests/#{id}\n"
|
||||
end
|
||||
|
||||
def reject!
|
||||
update_attribute(:status, "rejected")
|
||||
end
|
||||
|
@ -6,6 +6,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Creator</th>
|
||||
<th>Forum</th>
|
||||
<th>Script</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
@ -15,6 +16,7 @@
|
||||
<% @bulk_update_requests.each do |request| %>
|
||||
<tr id="request-<%= request.id %>">
|
||||
<td><%= link_to_user(request.user) %></td>
|
||||
<td><%= link_to(request.forum_topic_id, forum_topic_path(request.forum_topic_id)) %></td>
|
||||
<td><%= request.script %></td>
|
||||
<td><%= request.status %></td>
|
||||
<td>
|
||||
|
@ -4,19 +4,27 @@
|
||||
<%= simple_form_for(@bulk_update_request) do |f| %>
|
||||
<%= error_messages_for("bulk_update_request") %>
|
||||
|
||||
<pre>
|
||||
Use the following format:
|
||||
<%= 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>
|
||||
</pre>
|
||||
<%= text_area :bulk_update_request, :script, :size => "50x10" %>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<%= dtext_field "bulk_update_request", "reason", :name => "Reason" %>
|
||||
</div>
|
||||
|
||||
<%= f.input :script, :as => :text %>
|
||||
<%= f.input :forum_topic_id %>
|
||||
<%= f.button :submit, :value => "Submit" %>
|
||||
<%= dtext_preview_button "bulk_update_request", "reason" %>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
@ -7,6 +7,7 @@
|
||||
<% else %>
|
||||
<li><%= link_to "Request alias", new_tag_alias_request_path %></li>
|
||||
<% end %>
|
||||
<li><%= link_to "Request bulk update", new_bulk_update_request_path %></li>
|
||||
<li><%= link_to "Help", wiki_pages_path(:title => "help:tag_aliases") %></li>
|
||||
</menu>
|
||||
<% end %>
|
||||
|
@ -7,6 +7,7 @@
|
||||
<% else %>
|
||||
<li><%= link_to "Request implication", new_tag_implication_request_path %></li>
|
||||
<% end %>
|
||||
<li><%= link_to "Request bulk update", new_bulk_update_request_path %></li>
|
||||
<li><%= link_to "Help", wiki_pages_path(:title => "help:tag_implications") %></li>
|
||||
</menu>
|
||||
<% end %>
|
||||
|
@ -3,6 +3,7 @@
|
||||
--
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SET check_function_bodies = false;
|
||||
|
@ -1,7 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
19
test/unit/bulk_update_request_test.rb
Normal file
19
test/unit/bulk_update_request_test.rb
Normal file
@ -0,0 +1,19 @@
|
||||
require 'test_helper'
|
||||
|
||||
class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
context "creation" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
end
|
||||
|
||||
should "create a forum topic" do
|
||||
assert_difference("ForumTopic.count", 1) do
|
||||
BulkUpdateRequest.create(:title => "abc", :reason => "zzz", :script => "create alias aaa -> bbb")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user