diff --git a/app/controllers/bulk_update_requests_controller.rb b/app/controllers/bulk_update_requests_controller.rb index 8e3c6c015..a34259d16 100644 --- a/app/controllers/bulk_update_requests_controller.rb +++ b/app/controllers/bulk_update_requests_controller.rb @@ -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 diff --git a/app/models/bulk_update_request.rb b/app/models/bulk_update_request.rb index 066ee95d4..7d7d3b02f 100644 --- a/app/models/bulk_update_request.rb +++ b/app/models/bulk_update_request.rb @@ -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 diff --git a/app/views/bulk_update_requests/index.html.erb b/app/views/bulk_update_requests/index.html.erb index 81e44940a..c01d5baa7 100644 --- a/app/views/bulk_update_requests/index.html.erb +++ b/app/views/bulk_update_requests/index.html.erb @@ -6,6 +6,7 @@ Creator + Forum Script Status @@ -15,6 +16,7 @@ <% @bulk_update_requests.each do |request| %> <%= link_to_user(request.user) %> + <%= link_to(request.forum_topic_id, forum_topic_path(request.forum_topic_id)) %> <%= request.script %> <%= request.status %> diff --git a/app/views/bulk_update_requests/new.html.erb b/app/views/bulk_update_requests/new.html.erb index 18ec8afb2..a78a69263 100644 --- a/app/views/bulk_update_requests/new.html.erb +++ b/app/views/bulk_update_requests/new.html.erb @@ -4,19 +4,27 @@ <%= simple_form_for(@bulk_update_request) do |f| %> <%= error_messages_for("bulk_update_request") %> -
-Use the following format:
+      <%= f.input :title, :as => :string %>
 
+      
+ +
+Use the following format:
 remove alias aaa -> bbb
 remove implication aaa -> bbb
 create alias aaa -> bbb
 create implication aaa -> bbb
 mass update aaa -> bbb
-      
+
+ <%= text_area :bulk_update_request, :script, :size => "50x10" %> + + +
+ <%= dtext_field "bulk_update_request", "reason", :name => "Reason" %> +
- <%= f.input :script, :as => :text %> - <%= f.input :forum_topic_id %> <%= f.button :submit, :value => "Submit" %> + <%= dtext_preview_button "bulk_update_request", "reason" %> <% end %> diff --git a/app/views/tag_aliases/_secondary_links.html.erb b/app/views/tag_aliases/_secondary_links.html.erb index 663069a99..f72861d32 100644 --- a/app/views/tag_aliases/_secondary_links.html.erb +++ b/app/views/tag_aliases/_secondary_links.html.erb @@ -7,6 +7,7 @@ <% else %>
  • <%= link_to "Request alias", new_tag_alias_request_path %>
  • <% end %> +
  • <%= link_to "Request bulk update", new_bulk_update_request_path %>
  • <%= link_to "Help", wiki_pages_path(:title => "help:tag_aliases") %>
  • <% end %> diff --git a/app/views/tag_implications/_secondary_links.html.erb b/app/views/tag_implications/_secondary_links.html.erb index aafe29969..3bc0b464b 100644 --- a/app/views/tag_implications/_secondary_links.html.erb +++ b/app/views/tag_implications/_secondary_links.html.erb @@ -7,6 +7,7 @@ <% else %>
  • <%= link_to "Request implication", new_tag_implication_request_path %>
  • <% end %> +
  • <%= link_to "Request bulk update", new_bulk_update_request_path %>
  • <%= link_to "Help", wiki_pages_path(:title => "help:tag_implications") %>
  • <% end %> diff --git a/db/structure.sql b/db/structure.sql index d87ae08e3..e06e6276d 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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; diff --git a/test/models/bulk_update_request_test.rb b/test/models/bulk_update_request_test.rb deleted file mode 100644 index 8b7748903..000000000 --- a/test/models/bulk_update_request_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class BulkUpdateRequestTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb new file mode 100644 index 000000000..744dc488e --- /dev/null +++ b/test/unit/bulk_update_request_test.rb @@ -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