BURs: remove ability to skip secondary validations.
Remove the ability to skip secondary validations when creating a BUR. The only skippable validation that still existed was the requirement that both tags in an implication must have wiki pages. It's now mandatory to write wiki pages for tags before you can request an implication. This doesn't apply to empty tags.
This commit is contained in:
@@ -4,7 +4,7 @@ class BulkUpdateRequestProcessor
|
||||
class Error < StandardError; end
|
||||
|
||||
attr_reader :bulk_update_request
|
||||
delegate :script, :forum_topic_id, :skip_secondary_validations, to: :bulk_update_request
|
||||
delegate :script, :forum_topic_id, to: :bulk_update_request
|
||||
validate :validate_script
|
||||
|
||||
def initialize(bulk_update_request)
|
||||
@@ -42,17 +42,25 @@ class BulkUpdateRequestProcessor
|
||||
commands.each do |command, *args|
|
||||
case command
|
||||
when :create_alias
|
||||
tag_alias = TagAlias.new(creator: User.system, antecedent_name: args[0], consequent_name: args[1], skip_secondary_validations: skip_secondary_validations)
|
||||
tag_alias = TagAlias.new(creator: User.system, antecedent_name: args[0], consequent_name: args[1])
|
||||
if tag_alias.invalid?
|
||||
errors[:base] << "Can't create alias #{tag_alias.antecedent_name} -> #{tag_alias.consequent_name} (#{tag_alias.errors.full_messages.join("; ")})"
|
||||
end
|
||||
|
||||
when :create_implication
|
||||
tag_implication = TagImplication.new(creator: User.system, antecedent_name: args[0], consequent_name: args[1], skip_secondary_validations: skip_secondary_validations, status: "active")
|
||||
tag_implication = TagImplication.new(creator: User.system, antecedent_name: args[0], consequent_name: args[1], status: "active")
|
||||
if tag_implication.invalid?
|
||||
errors[:base] << "Can't create implication #{tag_implication.antecedent_name} -> #{tag_implication.consequent_name} (#{tag_implication.errors.full_messages.join("; ")})"
|
||||
end
|
||||
|
||||
if !tag_implication.antecedent_tag.empty? && tag_implication.antecedent_wiki.blank?
|
||||
errors[:base] << "'#{tag_implication.antecedent_tag.name}' must have a wiki page"
|
||||
end
|
||||
|
||||
if !tag_implication.consequent_tag.empty? && tag_implication.consequent_wiki.blank?
|
||||
errors[:base] << "'#{tag_implication.consequent_tag.name}' must have a wiki page"
|
||||
end
|
||||
|
||||
when :remove_alias
|
||||
tag_alias = TagAlias.active.find_by(antecedent_name: args[0], consequent_name: args[1])
|
||||
if tag_alias.nil?
|
||||
@@ -97,11 +105,11 @@ class BulkUpdateRequestProcessor
|
||||
commands.map do |command, *args|
|
||||
case command
|
||||
when :create_alias
|
||||
tag_alias = TagAlias.create!(creator: approver, forum_topic_id: forum_topic_id, status: "pending", antecedent_name: args[0], consequent_name: args[1], skip_secondary_validations: skip_secondary_validations)
|
||||
tag_alias = TagAlias.create!(creator: approver, forum_topic_id: forum_topic_id, status: "pending", antecedent_name: args[0], consequent_name: args[1])
|
||||
tag_alias.approve!(approver)
|
||||
|
||||
when :create_implication
|
||||
tag_implication = TagImplication.create!(creator: approver, forum_topic_id: forum_topic_id, status: "pending", antecedent_name: args[0], consequent_name: args[1], skip_secondary_validations: skip_secondary_validations)
|
||||
tag_implication = TagImplication.create!(creator: approver, forum_topic_id: forum_topic_id, status: "pending", antecedent_name: args[0], consequent_name: args[1])
|
||||
tag_implication.approve!(approver)
|
||||
|
||||
when :remove_alias
|
||||
|
||||
@@ -192,7 +192,7 @@ class Artist < ApplicationRecord
|
||||
|
||||
# potential race condition but unlikely
|
||||
unless TagImplication.where(:antecedent_name => name, :consequent_name => "banned_artist").exists?
|
||||
tag_implication = TagImplication.create!(antecedent_name: name, consequent_name: "banned_artist", skip_secondary_validations: true, creator: banner)
|
||||
tag_implication = TagImplication.create!(antecedent_name: name, consequent_name: "banned_artist", creator: banner)
|
||||
tag_implication.approve!(banner)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class BulkUpdateRequest < ApplicationRecord
|
||||
attr_accessor :title
|
||||
attr_accessor :reason
|
||||
attr_reader :skip_secondary_validations
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :forum_topic, optional: true
|
||||
@@ -75,7 +74,7 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
transaction do
|
||||
CurrentUser.scoped(approver) do
|
||||
processor.process!(approver)
|
||||
update!(status: "approved", approver: approver, skip_secondary_validations: true)
|
||||
update!(status: "approved", approver: approver)
|
||||
forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has been approved by @#{approver.name}.")
|
||||
end
|
||||
end
|
||||
@@ -120,10 +119,6 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
self.tags = processor.affected_tags
|
||||
end
|
||||
|
||||
def skip_secondary_validations=(v)
|
||||
@skip_secondary_validations = v.to_s.truthy?
|
||||
end
|
||||
|
||||
def processor
|
||||
@processor ||= BulkUpdateRequestProcessor.new(self)
|
||||
end
|
||||
|
||||
@@ -8,7 +8,6 @@ class TagImplication < TagRelationship
|
||||
validate :absence_of_transitive_relation
|
||||
validate :antecedent_is_not_aliased
|
||||
validate :consequent_is_not_aliased
|
||||
validate :wiki_pages_present, on: :create, unless: :skip_secondary_validations
|
||||
|
||||
module DescendantMethods
|
||||
extend ActiveSupport::Concern
|
||||
@@ -107,16 +106,6 @@ class TagImplication < TagRelationship
|
||||
errors[:base] << "Consequent tag must not be aliased to another tag"
|
||||
end
|
||||
end
|
||||
|
||||
def wiki_pages_present
|
||||
if consequent_wiki.blank?
|
||||
errors[:base] << "The #{consequent_name} tag needs a corresponding wiki page"
|
||||
end
|
||||
|
||||
if antecedent_wiki.blank?
|
||||
errors[:base] << "The #{antecedent_name} tag needs a corresponding wiki page"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module ApprovalMethods
|
||||
|
||||
@@ -4,8 +4,6 @@ class TagRelationship < ApplicationRecord
|
||||
EXPIRY = 60
|
||||
EXPIRY_WARNING = 55
|
||||
|
||||
attr_accessor :skip_secondary_validations
|
||||
|
||||
belongs_to :creator, class_name: "User"
|
||||
belongs_to :approver, class_name: "User", optional: true
|
||||
belongs_to :forum_post, optional: true
|
||||
|
||||
@@ -20,14 +20,14 @@ class BulkUpdateRequestPolicy < ApplicationPolicy
|
||||
end
|
||||
|
||||
def permitted_attributes_for_create
|
||||
[:script, :skip_secondary_validations, :title, :reason, :forum_topic_id]
|
||||
[:script, :title, :reason, :forum_topic_id]
|
||||
end
|
||||
|
||||
def permitted_attributes_for_update
|
||||
if can_update_forum?
|
||||
[:script, :skip_secondary_validations, :forum_topic_id, :forum_post_id]
|
||||
[:script, :forum_topic_id, :forum_post_id]
|
||||
else
|
||||
[:script, :skip_secondary_validations]
|
||||
[:script]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,16 +28,6 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @bulk_update_request.errors.any? %>
|
||||
<div class="input">
|
||||
<label class="checkbox optional" for="bulk_update_request_skip_secondary_validations">
|
||||
<%= check_box "bulk_update_request", "skip_secondary_validations" %>
|
||||
Skip validations
|
||||
</label>
|
||||
<p class="hint">You can ignore the wiki page and minimum count requirements</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @bulk_update_request.persisted? && policy(@bulk_update_request).can_update_forum? %>
|
||||
<%= f.input :forum_topic_id %>
|
||||
<%= f.input :forum_post_id %>
|
||||
|
||||
Reference in New Issue
Block a user