From fed2725139b4cfa9b6d2ad24abd17234d5dd8634 Mon Sep 17 00:00:00 2001 From: Toks Date: Tue, 15 Jul 2014 11:38:53 -0400 Subject: [PATCH] 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. --- app/models/tag_alias.rb | 5 ++++- app/models/tag_implication.rb | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 1295cbe1f..fe6a17039 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -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 diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index bb1a0518c..951a0e26b 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -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