fixes #3824: render tag requests dynamically in the forum post

refactoring
This commit is contained in:
Albert Yi
2019-01-02 17:27:01 -08:00
parent 5c54c61d65
commit 8b0af19f7f
18 changed files with 171 additions and 25 deletions

View File

@@ -90,7 +90,8 @@ class BulkUpdateRequest < ApplicationRecord
ForumUpdater.new(
forum_topic,
forum_post: post,
expected_title: title
expected_title: title,
skip_update: !TagRelationship::SUPPORT_HARD_CODED
)
end
end
@@ -168,12 +169,20 @@ class BulkUpdateRequest < ApplicationRecord
include ApprovalMethods
include ValidationMethods
concerning :EmbeddedText do
class_methods do
def embedded_pattern
/\[bur:(?<id>\d+)\]/m
end
end
end
def editable?(user)
user_id == user.id || user.is_builder?
end
def reason_with_link
"#{script_with_links}\n\n\"Link to request\":/bulk_update_requests?search[id]=#{id}\n\n#{reason}"
"[bur:#{id}]\n\nReason: #{reason}"
end
def script_with_links

View File

@@ -36,14 +36,15 @@ class TagAlias < TagRelationship
def forum_updater
@forum_updater ||= begin
post = if forum_topic
forum_post || forum_topic.posts.where("body like ?", TagAliasRequest.command_string(antecedent_name, consequent_name) + "%").last
forum_post || forum_topic.posts.where("body like ?", TagAliasRequest.command_string(antecedent_name, consequent_name, id) + "%").last
else
nil
end
ForumUpdater.new(
forum_topic,
forum_post: post,
expected_title: TagAliasRequest.topic_title(antecedent_name, consequent_name)
expected_title: TagAliasRequest.topic_title(antecedent_name, consequent_name),
skip_update: !TagRelationship::SUPPORT_HARD_CODED
)
end
end
@@ -53,6 +54,14 @@ class TagAlias < TagRelationship
include ApprovalMethods
include ForumMethods
concerning :EmbeddedText do
class_methods do
def embedded_pattern
/\[ta:(?<id>\d+)\]/m
end
end
end
def self.to_aliased(names)
Cache.get_multi(Array(names), "ta") do |tag|
ActiveRecord::Base.select_value_sql("select consequent_name from tag_aliases where status in ('active', 'processing') and antecedent_name = ?", tag) || tag.to_s

View File

@@ -196,14 +196,15 @@ class TagImplication < TagRelationship
def forum_updater
post = if forum_topic
forum_post || forum_topic.posts.where("body like ?", TagImplicationRequest.command_string(antecedent_name, consequent_name) + "%").last
forum_post || forum_topic.posts.where("body like ?", TagImplicationRequest.command_string(antecedent_name, consequent_name, id) + "%").last
else
nil
end
ForumUpdater.new(
forum_topic,
forum_post: post,
expected_title: TagImplicationRequest.topic_title(antecedent_name, consequent_name)
expected_title: TagImplicationRequest.topic_title(antecedent_name, consequent_name),
skip_update: !TagRelationship::SUPPORT_HARD_CODED
)
end
memoize :forum_updater
@@ -214,6 +215,14 @@ class TagImplication < TagRelationship
include ValidationMethods
include ApprovalMethods
concerning :EmbeddedText do
class_methods do
def embedded_pattern
/\[ti:(?<id>\d+)\]/m
end
end
end
def reload(options = {})
flush_cache
super

View File

@@ -1,6 +1,7 @@
class TagRelationship < ApplicationRecord
self.abstract_class = true
SUPPORT_HARD_CODED = true
EXPIRY = 60
EXPIRY_WARNING = 55
@@ -54,6 +55,10 @@ class TagRelationship < ApplicationRecord
status == "active"
end
def is_errored?
status =~ /\Aerror:/
end
def deletable_by?(user)
return true if user.is_admin?
return true if is_pending? && user.is_builder?
@@ -173,6 +178,14 @@ class TagRelationship < ApplicationRecord
end
end
concerning :EmbeddedText do
class_methods do
def embedded_pattern
raise NotImplementedError
end
end
end
def antecedent_and_consequent_are_different
if antecedent_name == consequent_name
errors[:base] << "Cannot alias or implicate a tag to itself"