Better fix for alias/implication moving bug

This makes it so pending alias/implication requests can't stop other
alias/implications from being created as if they were already approved.
This commit is contained in:
Toks
2014-07-15 11:38:53 -04:00
parent 4dab3e84f5
commit fed2725139
2 changed files with 14 additions and 4 deletions

View File

@@ -78,6 +78,9 @@ class TagAlias < ActiveRecord::Base
end end
def process! def process!
unless valid?
raise errors.full_messages.join("; ")
end
update_column(:status, "processing") update_column(:status, "processing")
move_aliases_and_implications move_aliases_and_implications
clear_all_cache clear_all_cache
@@ -117,7 +120,7 @@ class TagAlias < ActiveRecord::Base
def absence_of_transitive_relation def absence_of_transitive_relation
# We don't want a -> b && b -> c chains if the b -> c alias was created first. # We don't want a -> b && b -> c chains if the b -> c alias was created first.
# If the a -> b alias was created first, the new one will be allowed and the old one will be moved automatically instead. # If the a -> b alias was created first, the new one will be allowed and the old one will be moved automatically instead.
if self.class.exists?(["antecedent_name = ?", consequent_name]) if self.class.active.exists?(["antecedent_name = ?", consequent_name])
self.errors[:base] << "Tag alias can not create a transitive relation with another tag alias" self.errors[:base] << "Tag alias can not create a transitive relation with another tag alias"
false false
end end

View File

@@ -79,6 +79,10 @@ class TagImplication < ActiveRecord::Base
where("(antecedent_name like ? escape E'\\\\' or consequent_name like ? escape E'\\\\')", name.downcase.to_escaped_for_sql_like, name.downcase.to_escaped_for_sql_like) where("(antecedent_name like ? escape E'\\\\' or consequent_name like ? escape E'\\\\')", name.downcase.to_escaped_for_sql_like, name.downcase.to_escaped_for_sql_like)
end end
def active
where("status IN (?)", ["active", "processing"])
end
def search(params) def search(params)
q = where("true") q = where("true")
return q if params.blank? return q if params.blank?
@@ -118,6 +122,9 @@ class TagImplication < ActiveRecord::Base
end end
def process! def process!
unless valid?
raise errors.full_messages.join("; ")
end
update_column(:status, "processing") update_column(:status, "processing")
update_posts update_posts
update_column(:status, "active") update_column(:status, "active")
@@ -128,7 +135,7 @@ class TagImplication < ActiveRecord::Base
def absence_of_circular_relation def absence_of_circular_relation
# We don't want a -> b && b -> a chains # We don't want a -> b && b -> a chains
if self.class.exists?(["antecedent_name = ? and consequent_name = ?", consequent_name, antecedent_name]) if self.class.active.exists?(["antecedent_name = ? and consequent_name = ?", consequent_name, antecedent_name])
self.errors[:base] << "Tag implication can not create a circular relation with another tag implication" self.errors[:base] << "Tag implication can not create a circular relation with another tag implication"
false false
end end
@@ -136,7 +143,7 @@ class TagImplication < ActiveRecord::Base
def antecedent_is_not_aliased def antecedent_is_not_aliased
# We don't want to implicate a -> b if a is already aliased to c # We don't want to implicate a -> b if a is already aliased to c
if TagAlias.exists?(["antecedent_name = ?", antecedent_name]) if TagAlias.active.exists?(["antecedent_name = ?", antecedent_name])
self.errors[:base] << "Antecedent tag must not be aliased to another tag" self.errors[:base] << "Antecedent tag must not be aliased to another tag"
false false
end end
@@ -144,7 +151,7 @@ class TagImplication < ActiveRecord::Base
def consequent_is_not_aliased def consequent_is_not_aliased
# We don't want to implicate a -> b if b is already aliased to c # We don't want to implicate a -> b if b is already aliased to c
if TagAlias.exists?(["antecedent_name = ?", consequent_name]) if TagAlias.active.exists?(["antecedent_name = ?", consequent_name])
self.errors[:base] << "Consequent tag must not be aliased to another tag" self.errors[:base] << "Consequent tag must not be aliased to another tag"
false false
end end