fixes #2190
This commit is contained in:
@@ -25,7 +25,7 @@ class BulkUpdateRequestsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@bulk_update_requests = BulkUpdateRequest.paginate(params[:page])
|
@bulk_update_requests = BulkUpdateRequest.order("id desc").paginate(params[:page])
|
||||||
respond_with(@bulk_update_requests)
|
respond_with(@bulk_update_requests)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,18 +1,30 @@
|
|||||||
class BulkUpdateRequest < ActiveRecord::Base
|
class BulkUpdateRequest < ActiveRecord::Base
|
||||||
|
attr_accessor :title, :reason
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :forum_topic
|
belongs_to :forum_topic
|
||||||
|
|
||||||
validates_presence_of :user
|
validates_presence_of :user
|
||||||
validates_inclusion_of :status, :in => %w(pending approved rejected)
|
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]
|
attr_accessible :status, :as => [:admin]
|
||||||
before_validation :initialize_attributes, :on => :create
|
before_validation :initialize_attributes, :on => :create
|
||||||
|
after_create :create_forum_topic
|
||||||
|
|
||||||
def approve!
|
def approve!
|
||||||
AliasAndImplicationImporter.new(script, forum_topic_id, "1").process!
|
AliasAndImplicationImporter.new(script, forum_topic_id, "1").process!
|
||||||
update_attribute(:status, "approved")
|
update_attribute(:status, "approved")
|
||||||
end
|
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!
|
def reject!
|
||||||
update_attribute(:status, "rejected")
|
update_attribute(:status, "rejected")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Creator</th>
|
<th>Creator</th>
|
||||||
|
<th>Forum</th>
|
||||||
<th>Script</th>
|
<th>Script</th>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
@@ -15,6 +16,7 @@
|
|||||||
<% @bulk_update_requests.each do |request| %>
|
<% @bulk_update_requests.each do |request| %>
|
||||||
<tr id="request-<%= request.id %>">
|
<tr id="request-<%= request.id %>">
|
||||||
<td><%= link_to_user(request.user) %></td>
|
<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.script %></td>
|
||||||
<td><%= request.status %></td>
|
<td><%= request.status %></td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -4,19 +4,27 @@
|
|||||||
<%= simple_form_for(@bulk_update_request) do |f| %>
|
<%= simple_form_for(@bulk_update_request) do |f| %>
|
||||||
<%= error_messages_for("bulk_update_request") %>
|
<%= error_messages_for("bulk_update_request") %>
|
||||||
|
|
||||||
<pre>
|
<%= f.input :title, :as => :string %>
|
||||||
Use the following format:
|
|
||||||
|
|
||||||
|
<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 alias aaa -> bbb
|
||||||
remove implication aaa -> bbb
|
remove implication aaa -> bbb
|
||||||
create alias aaa -> bbb
|
create alias aaa -> bbb
|
||||||
create implication aaa -> bbb
|
create implication aaa -> bbb
|
||||||
mass update 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" %>
|
<%= f.button :submit, :value => "Submit" %>
|
||||||
|
<%= dtext_preview_button "bulk_update_request", "reason" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<% else %>
|
<% else %>
|
||||||
<li><%= link_to "Request alias", new_tag_alias_request_path %></li>
|
<li><%= link_to "Request alias", new_tag_alias_request_path %></li>
|
||||||
<% end %>
|
<% 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>
|
<li><%= link_to "Help", wiki_pages_path(:title => "help:tag_aliases") %></li>
|
||||||
</menu>
|
</menu>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<% else %>
|
<% else %>
|
||||||
<li><%= link_to "Request implication", new_tag_implication_request_path %></li>
|
<li><%= link_to "Request implication", new_tag_implication_request_path %></li>
|
||||||
<% end %>
|
<% 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>
|
<li><%= link_to "Help", wiki_pages_path(:title => "help:tag_implications") %></li>
|
||||||
</menu>
|
</menu>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
SET statement_timeout = 0;
|
SET statement_timeout = 0;
|
||||||
|
SET lock_timeout = 0;
|
||||||
SET client_encoding = 'UTF8';
|
SET client_encoding = 'UTF8';
|
||||||
SET standard_conforming_strings = on;
|
SET standard_conforming_strings = on;
|
||||||
SET check_function_bodies = false;
|
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
|
||||||
Reference in New Issue
Block a user