Expire unused aliases and implications after 2 years of inactivity

This commit is contained in:
Albert Yi
2018-07-27 17:56:28 -07:00
parent cdb0a2cac7
commit ea4e7f1970
11 changed files with 167 additions and 170 deletions

View File

@@ -2,6 +2,7 @@ class TagAlias < TagRelationship
before_save :ensure_tags_exist
after_save :clear_all_cache
after_destroy :clear_all_cache
after_save :clear_all_cache, if: ->(rec) {rec.is_retired?}
after_save :create_mod_action
validates_uniqueness_of :antecedent_name
validate :absence_of_transitive_relation

View File

@@ -2,6 +2,7 @@ class TagImplication < TagRelationship
before_save :update_descendant_names
after_save :update_descendant_names_for_parents
after_destroy :update_descendant_names_for_parents
after_save :update_descendant_names_for_parents, if: ->(rec) { rec.is_retired? }
after_save :create_mod_action
validates_uniqueness_of :antecedent_name, :scope => :consequent_name
validate :absence_of_circular_relation

View File

@@ -13,13 +13,15 @@ class TagRelationship < ApplicationRecord
has_one :antecedent_tag, :class_name => "Tag", :foreign_key => "name", :primary_key => "antecedent_name"
has_one :consequent_tag, :class_name => "Tag", :foreign_key => "name", :primary_key => "consequent_name"
scope :active, ->{where(status: "active")}
scope :expired, ->{where("created_at < ?", EXPIRY.days.ago)}
scope :old, ->{where("created_at >= ? and created_at < ?", EXPIRY.days.ago, EXPIRY_WARNING.days.ago)}
scope :pending, ->{where(status: "pending")}
scope :retired, ->{where(status: "retired")}
before_validation :initialize_creator, :on => :create
before_validation :normalize_names
validates_format_of :status, :with => /\A(active|deleted|pending|processing|queued|error: .*)\Z/
validates_format_of :status, :with => /\A(active|deleted|pending|processing|queued|retired|error: .*)\Z/
validates_presence_of :creator_id, :antecedent_name, :consequent_name
validates :creator, presence: { message: "must exist" }, if: -> { creator_id.present? }
validates :approver, presence: { message: "must exist" }, if: -> { approver_id.present? }
@@ -35,6 +37,10 @@ class TagRelationship < ApplicationRecord
self.consequent_name = consequent_name.mb_chars.downcase.tr(" ", "_")
end
def is_retired?
status == "retired"
end
def is_pending?
status == "pending"
end
@@ -98,6 +104,8 @@ class TagRelationship < ApplicationRecord
if params[:status].present?
q = q.status_matches(params[:status])
else
q = q.active
end
if params[:category].present?
@@ -140,6 +148,10 @@ class TagRelationship < ApplicationRecord
"The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] #{forum_link} has been rejected by @#{rejector.name}."
end
def retirement_message
"The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] #{forum_link} has been retired."
end
def conflict_message
"The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] #{forum_link} has conflicting wiki pages. [[#{consequent_name}]] should be updated to include information from [[#{antecedent_name}]] if necessary."
end