Tag change notices

This adds a small notice at the bottom of post searches if a single tag search is the target of any tag change request.
This commit is contained in:
Albert Yi
2019-01-14 18:14:27 -08:00
parent 60f0aeeb99
commit 1550538dc1
10 changed files with 143 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ class BulkUpdateRequest < ApplicationRecord
before_validation :initialize_attributes, :on => :create
before_validation :normalize_text
after_create :create_forum_topic
after_save :update_notice
scope :pending_first, -> { order(Arel.sql("(case status when 'pending' then 0 when 'approved' then 1 else 2 end)")) }
scope :pending, -> {where(status: "pending")}
@@ -241,4 +242,11 @@ class BulkUpdateRequest < ApplicationRecord
def estimate_update_count
AliasAndImplicationImporter.new(script, nil).estimate_update_count
end
def update_notice
TagChangeNoticeService.update_cache(
AliasAndImplicationImporter.new(script, nil).affected_tags,
forum_topic_id
)
end
end

View File

@@ -32,6 +32,7 @@ class TagRelationship < ApplicationRecord
validates :approver, presence: { message: "must exist" }, if: -> { approver_id.present? }
validates :forum_topic, presence: { message: "must exist" }, if: -> { forum_topic_id.present? }
validate :antecedent_and_consequent_are_different
after_save :update_notice
def initialize_creator
self.creator_id = CurrentUser.user.id
@@ -196,6 +197,13 @@ class TagRelationship < ApplicationRecord
Post.fast_count(antecedent_name, skip_cache: true)
end
def update_notice
TagChangeNoticeService.update_cache(
[antecedent_name, consequent_name],
forum_topic_id
)
end
extend SearchMethods
include MessageMethods
end