add secondary validations to aliases+implications+requests

This commit is contained in:
r888888888
2016-02-10 14:52:26 -08:00
parent 01eac1e587
commit d75546a4e4
18 changed files with 239 additions and 89 deletions

View File

@@ -1,5 +1,5 @@
class BulkUpdateRequest < ActiveRecord::Base
attr_accessor :title, :reason
attr_accessor :title, :reason, :skip_secondary_validations
belongs_to :user
belongs_to :forum_topic
@@ -11,7 +11,7 @@ class BulkUpdateRequest < ActiveRecord::Base
validate :script_formatted_correctly
validate :forum_topic_id_not_invalid
validate :validate_script
attr_accessible :user_id, :forum_topic_id, :script, :title, :reason
attr_accessible :user_id, :forum_topic_id, :script, :title, :reason, :skip_secondary_validations
attr_accessible :status, :as => [:admin]
before_validation :initialize_attributes, :on => :create
before_validation :normalize_text
@@ -33,7 +33,7 @@ class BulkUpdateRequest < ActiveRecord::Base
extend SearchMethods
def approve!
AliasAndImplicationImporter.new(script, forum_topic_id, "1").process!
AliasAndImplicationImporter.new(script, forum_topic_id, "1", true).process!
update_forum_topic_for_approve
update_attribute(:status, "approved")
@@ -151,9 +151,17 @@ class BulkUpdateRequest < ActiveRecord::Base
self.script = script.downcase
end
def skip_secondary_validations=(v)
if v == "1" or v == true
@skip_secondary_validations = true
else
@skip_secondary_validations = false
end
end
def validate_script
begin
AliasAndImplicationImporter.new(script, forum_topic_id, "1").validate!
AliasAndImplicationImporter.new(script, forum_topic_id, "1", skip_secondary_validations).validate!
rescue RuntimeError => e
self.errors[:base] = e.message
return false

View File

@@ -1,4 +1,6 @@
class TagAlias < ActiveRecord::Base
attr_accessor :skip_secondary_validations
before_save :ensure_tags_exist
after_save :clear_all_cache
after_destroy :clear_all_cache
@@ -8,11 +10,11 @@ class TagAlias < ActiveRecord::Base
validates_uniqueness_of :antecedent_name
validate :absence_of_transitive_relation
validate :antecedent_and_consequent_are_different
# validate :consequent_has_wiki_page
# validate :mininum_antecedent_count
validate :consequent_has_wiki_page, :on => :create
validate :mininum_antecedent_count, :on => :create
belongs_to :creator, :class_name => "User"
belongs_to :forum_topic
attr_accessible :antecedent_name, :consequent_name, :forum_topic_id, :status
attr_accessible :antecedent_name, :consequent_name, :forum_topic_id, :status, :skip_secondary_validations
module SearchMethods
def name_matches(name)
@@ -293,7 +295,7 @@ class TagAlias < ActiveRecord::Base
end
def consequent_has_wiki_page
return if !Danbooru.config.strict_tag_requirements
return if skip_secondary_validations
unless WikiPage.titled(consequent_name).exists?
self.errors[:base] = "The #{consequent_name} tag needs a corresponding wiki page"
@@ -302,7 +304,7 @@ class TagAlias < ActiveRecord::Base
end
def mininum_antecedent_count
return if !Danbooru.config.strict_tag_requirements
return if skip_secondary_validations
unless Post.fast_count(antecedent_name) >= 50
self.errors[:base] = "The #{antecedent_name} tag must have at least 50 posts for an alias to be created"

View File

@@ -1,4 +1,6 @@
class TagImplication < ActiveRecord::Base
attr_accessor :skip_secondary_validations
before_save :update_descendant_names
after_save :update_descendant_names_for_parents
after_destroy :update_descendant_names_for_parents
@@ -12,8 +14,8 @@ class TagImplication < ActiveRecord::Base
validate :antecedent_is_not_aliased
validate :consequent_is_not_aliased
validate :antecedent_and_consequent_are_different
# validate :wiki_pages_present
attr_accessible :antecedent_name, :consequent_name, :descendant_names, :forum_topic_id, :status, :forum_topic
validate :wiki_pages_present, :on => :create
attr_accessible :antecedent_name, :consequent_name, :descendant_names, :forum_topic_id, :status, :forum_topic, :skip_secondary_validations
module DescendantMethods
extend ActiveSupport::Concern
@@ -258,7 +260,7 @@ class TagImplication < ActiveRecord::Base
end
def wiki_pages_present
return if !Danbooru.config.strict_tag_requirements
return if skip_secondary_validations
unless WikiPage.titled(consequent_name).exists?
self.errors[:base] = "The #{consequent_name} tag needs a corresponding wiki page"