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:
@@ -78,6 +78,9 @@ class TagAlias < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def process!
|
||||
unless valid?
|
||||
raise errors.full_messages.join("; ")
|
||||
end
|
||||
update_column(:status, "processing")
|
||||
move_aliases_and_implications
|
||||
clear_all_cache
|
||||
@@ -117,7 +120,7 @@ class TagAlias < ActiveRecord::Base
|
||||
def absence_of_transitive_relation
|
||||
# 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 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"
|
||||
false
|
||||
end
|
||||
|
||||
@@ -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)
|
||||
end
|
||||
|
||||
def active
|
||||
where("status IN (?)", ["active", "processing"])
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = where("true")
|
||||
return q if params.blank?
|
||||
@@ -118,6 +122,9 @@ class TagImplication < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def process!
|
||||
unless valid?
|
||||
raise errors.full_messages.join("; ")
|
||||
end
|
||||
update_column(:status, "processing")
|
||||
update_posts
|
||||
update_column(:status, "active")
|
||||
@@ -128,7 +135,7 @@ class TagImplication < ActiveRecord::Base
|
||||
|
||||
def absence_of_circular_relation
|
||||
# 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"
|
||||
false
|
||||
end
|
||||
@@ -136,7 +143,7 @@ class TagImplication < ActiveRecord::Base
|
||||
|
||||
def antecedent_is_not_aliased
|
||||
# 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"
|
||||
false
|
||||
end
|
||||
@@ -144,7 +151,7 @@ class TagImplication < ActiveRecord::Base
|
||||
|
||||
def consequent_is_not_aliased
|
||||
# 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"
|
||||
false
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user