diff --git a/app/controllers/bulk_update_requests_controller.rb b/app/controllers/bulk_update_requests_controller.rb index bd3e22a40..aa4bd3ca2 100644 --- a/app/controllers/bulk_update_requests_controller.rb +++ b/app/controllers/bulk_update_requests_controller.rb @@ -5,7 +5,7 @@ class BulkUpdateRequestsController < ApplicationController before_action :load_bulk_update_request, :except => [:new, :create, :index] def new - @bulk_update_request = BulkUpdateRequest.new + @bulk_update_request = BulkUpdateRequest.new(bur_params(:create)) respond_with(@bulk_update_request) end @@ -57,6 +57,6 @@ class BulkUpdateRequestsController < ApplicationController permitted_params += %i[title reason forum_topic_id] if context == :create permitted_params += %i[forum_topic_id forum_post_id] if context == :update && CurrentUser.is_admin? - params.require(:bulk_update_request).permit(permitted_params) + params.fetch(:bulk_update_request, {}).permit(permitted_params) end end diff --git a/app/controllers/tag_alias_requests_controller.rb b/app/controllers/tag_alias_requests_controller.rb deleted file mode 100644 index e776c3fd4..000000000 --- a/app/controllers/tag_alias_requests_controller.rb +++ /dev/null @@ -1,23 +0,0 @@ -class TagAliasRequestsController < ApplicationController - before_action :member_only - - def new - end - - def create - @tag_alias_request = TagAliasRequest.new(tar_params) - @tag_alias_request.create - - if @tag_alias_request.invalid? - render :action => "new" - else - redirect_to forum_topic_path(@tag_alias_request.forum_topic) - end - end - -private - - def tar_params - params.require(:tag_alias_request).permit(:antecedent_name, :consequent_name, :reason, :skip_secondary_validations) - end -end diff --git a/app/controllers/tag_implication_requests_controller.rb b/app/controllers/tag_implication_requests_controller.rb deleted file mode 100644 index a395b4ad7..000000000 --- a/app/controllers/tag_implication_requests_controller.rb +++ /dev/null @@ -1,23 +0,0 @@ -class TagImplicationRequestsController < ApplicationController - before_action :member_only - - def new - end - - def create - @tag_implication_request = TagImplicationRequest.new(tir_params) - @tag_implication_request.create - - if @tag_implication_request.invalid? - render :action => "new" - else - redirect_to forum_topic_path(@tag_implication_request.forum_topic) - end - end - -private - - def tir_params - params.require(:tag_implication_request).permit(:antecedent_name, :consequent_name, :reason, :skip_secondary_validations) - end -end diff --git a/app/helpers/bulk_update_requests_helper.rb b/app/helpers/bulk_update_requests_helper.rb index 95a762a27..9d9bd135e 100644 --- a/app/helpers/bulk_update_requests_helper.rb +++ b/app/helpers/bulk_update_requests_helper.rb @@ -1,4 +1,17 @@ module BulkUpdateRequestsHelper + def bur_script_example + <<~EOS + create alias kitty -> cat + remove alias kitty -> cat + + create implication cat -> animal + remove implication cat -> animal + + mass update kitty -> cat + category touhou -> copyright + EOS + end + def approved?(command, antecedent, consequent) return false unless CurrentUser.is_moderator? diff --git a/app/logical/tag_alias_request.rb b/app/logical/tag_alias_request.rb index decb13d41..c911e74bb 100644 --- a/app/logical/tag_alias_request.rb +++ b/app/logical/tag_alias_request.rb @@ -1,15 +1,4 @@ class TagAliasRequest - include ActiveModel::Validations - - attr_reader :antecedent_name, :consequent_name, :reason, :skip_secondary_validations, :tag_alias, :forum_topic - - validate :validate_tag_alias - validate :validate_forum_topic - - def self.topic_title(antecedent_name, consequent_name) - "Tag alias: #{antecedent_name} -> #{consequent_name}" - end - def self.command_string(antecedent_name, consequent_name, id=nil) if id return "[ta:#{id}]" @@ -17,68 +6,4 @@ class TagAliasRequest "create alias [[#{antecedent_name}]] -> [[#{consequent_name}]]" end - - def initialize(attributes) - @antecedent_name = attributes[:antecedent_name].strip.tr(" ", "_") - @consequent_name = attributes[:consequent_name].strip.tr(" ", "_") - @reason = attributes[:reason] - self.skip_secondary_validations = attributes[:skip_secondary_validations] - end - - def create - return false if invalid? - - TagAlias.transaction do - @tag_alias = build_tag_alias - @tag_alias.save - - @forum_topic = build_forum_topic(@tag_alias.id) - @forum_topic.save - - @tag_alias.forum_topic_id = @forum_topic.id - @tag_alias.forum_post_id = @forum_topic.posts.first.id - @tag_alias.save - end - end - - def build_tag_alias - x = TagAlias.new( - :antecedent_name => antecedent_name, - :consequent_name => consequent_name, - :skip_secondary_validations => skip_secondary_validations - ) - x.status = "pending" - x - end - - def build_forum_topic(tag_alias_id) - ForumTopic.new( - :title => TagAliasRequest.topic_title(antecedent_name, consequent_name), - :original_post_attributes => { - :body => TagAliasRequest.command_string(antecedent_name, consequent_name, tag_alias_id) + "\n\nReason: #{reason}" - }, - :category_id => 1 - ) - end - - def validate_tag_alias - ta = @tag_alias || build_tag_alias - - if ta.invalid? - self.errors.add(:base, ta.errors.full_messages.join("; ")) - return false - end - end - - def validate_forum_topic - ft = @forum_topic || build_forum_topic(nil) - if ft.invalid? - self.errors.add(:base, ft.errors.full_messages.join("; ")) - return false - end - end - - def skip_secondary_validations=(v) - @skip_secondary_validations = v.to_s.truthy? - end end diff --git a/app/logical/tag_implication_request.rb b/app/logical/tag_implication_request.rb index fb4b0ecc1..548875f86 100644 --- a/app/logical/tag_implication_request.rb +++ b/app/logical/tag_implication_request.rb @@ -1,15 +1,4 @@ class TagImplicationRequest - include ActiveModel::Validations - - attr_reader :antecedent_name, :consequent_name, :reason, :tag_implication, :forum_topic, :skip_secondary_validations - - validate :validate_tag_implication - validate :validate_forum_topic - - def self.topic_title(antecedent_name, consequent_name) - "Tag implication: #{antecedent_name} -> #{consequent_name}" - end - def self.command_string(antecedent_name, consequent_name, id=nil) if id return "[ti:#{id}]" @@ -17,68 +6,4 @@ class TagImplicationRequest "create implication [[#{antecedent_name}]] -> [[#{consequent_name}]]" end - - def initialize(attributes) - @antecedent_name = attributes[:antecedent_name].strip.tr(" ", "_") - @consequent_name = attributes[:consequent_name].strip.tr(" ", "_") - @reason = attributes[:reason] - self.skip_secondary_validations = attributes[:skip_secondary_validations] - end - - def create - return false if invalid? - - TagImplication.transaction do - @tag_implication = build_tag_implication - @tag_implication.save - - @forum_topic = build_forum_topic(@tag_implication.id) - @forum_topic.save - - @tag_implication.forum_topic_id = @forum_topic.id - @tag_implication.forum_post_id = @forum_topic.posts.first.id - @tag_implication.save - end - end - - def build_tag_implication - x = TagImplication.new( - :antecedent_name => antecedent_name, - :consequent_name => consequent_name, - :skip_secondary_validations => skip_secondary_validations - ) - x.status = "pending" - x - end - - def build_forum_topic(tag_implication_id) - ForumTopic.new( - :title => TagImplicationRequest.topic_title(antecedent_name, consequent_name), - :original_post_attributes => { - :body => TagImplicationRequest.command_string(antecedent_name, consequent_name, tag_implication_id) + "\n\nReason: #{reason}" - }, - :category_id => 1 - ) - end - - def validate_tag_implication - ti = @tag_implication || build_tag_implication - - if ti.invalid? - self.errors.add(:base, ti.errors.full_messages.join("; ")) - return false - end - end - - def validate_forum_topic - ft = @forum_topic || build_forum_topic(nil) - if ft.invalid? - self.errors.add(:base, ft.errors.full_messages.join("; ")) - return false - end - end - - def skip_secondary_validations=(v) - @skip_secondary_validations = v.to_s.truthy? - end end diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index e750867f4..14d63e153 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -23,7 +23,7 @@ class TagAlias < TagRelationship ForumUpdater.new( forum_topic, forum_post: post, - expected_title: TagAliasRequest.topic_title(antecedent_name, consequent_name), + expected_title: "Tag alias: #{antecedent_name} -> #{consequent_name}", skip_update: !TagRelationship::SUPPORT_HARD_CODED ) end diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index b72513f42..10fc26a74 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -202,7 +202,7 @@ class TagImplication < TagRelationship ForumUpdater.new( forum_topic, forum_post: post, - expected_title: TagImplicationRequest.topic_title(antecedent_name, consequent_name), + expected_title: "Tag implication: #{antecedent_name} -> #{consequent_name}", skip_update: !TagRelationship::SUPPORT_HARD_CODED ) end diff --git a/app/views/bulk_update_requests/_form.html.erb b/app/views/bulk_update_requests/_form.html.erb index 13549b93a..ba1fab5d5 100644 --- a/app/views/bulk_update_requests/_form.html.erb +++ b/app/views/bulk_update_requests/_form.html.erb @@ -1,23 +1,25 @@ <%= simple_form_for(@bulk_update_request) do |f| %> <%= error_messages_for("bulk_update_request") %> - <% if @bulk_update_request.new_record? %> - <%= f.input :title, :as => :string %> - <% end %> +
+ Request aliases or implications using the format shown below. An alias makes the first tag a + synonym for the second tag. An implication makes the first tag automatically add the second tag. + A mass update replaces the first tag with the second tag without making it a permanent alias. +
-+ <% if @bulk_update_request.new_record? && @bulk_update_request.forum_topic.present? %> + This request will be attached to + <%= link_to "topic ##{@bulk_update_request.forum_topic_id}: #{@bulk_update_request.forum_topic.title}" %>. + <% elsif @bulk_update_request.new_record? && @bulk_update_request.forum_topic.blank? %> + This request will create a new forum topic. To attach this request to an existing topic, find + the forum topic and click "Request alias/implication" at the top of the page. + + <%= f.input :title, label: "Forum Title", as: :string %> + <% end %> +
+ + <%= f.input :script, label: "Request", as: :text, placeholder: bur_script_example, input_html: { size: "50x15" } %> <% if @bulk_update_request.new_record? %>