refactor forum notifications for tag changes
This commit is contained in:
@@ -87,14 +87,14 @@ private
|
||||
raise "Error: #{tag_alias.errors.full_messages.join("; ")} (create alias #{tag_alias.antecedent_name} -> #{tag_alias.consequent_name})"
|
||||
end
|
||||
tag_alias.rename_wiki_and_artist if rename_aliased_pages?
|
||||
tag_alias.approve!(approver, update_topic: false)
|
||||
tag_alias.approve!(approver: approver, update_topic: false)
|
||||
|
||||
when :create_implication
|
||||
tag_implication = TagImplication.create(:forum_topic_id => forum_id, :status => "pending", :antecedent_name => token[1], :consequent_name => token[2], :skip_secondary_validations => skip_secondary_validations)
|
||||
unless tag_implication.valid?
|
||||
raise "Error: #{tag_implication.errors.full_messages.join("; ")} (create implication #{tag_implication.antecedent_name} -> #{tag_implication.consequent_name})"
|
||||
end
|
||||
tag_implication.approve!(approver, update_topic: false)
|
||||
tag_implication.approve!(approver: approver, update_topic: false)
|
||||
|
||||
when :remove_alias
|
||||
tag_alias = TagAlias.where("antecedent_name = ?", token[1]).first
|
||||
|
||||
38
app/logical/forum_updater.rb
Normal file
38
app/logical/forum_updater.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
class ForumUpdater
|
||||
attr_reader :forum_topic, :forum_post, :expected_title
|
||||
|
||||
def initialize(forum_topic, options = {})
|
||||
@forum_topic = forum_topic
|
||||
@forum_post = options[:forum_post]
|
||||
@expected_title = options[:expected_title]
|
||||
end
|
||||
|
||||
def update(message, title_tag = nil)
|
||||
return if forum_topic.nil?
|
||||
|
||||
CurrentUser.scoped(User.system) do
|
||||
create_response(message)
|
||||
update_title(title_tag) if title_tag
|
||||
|
||||
if forum_post
|
||||
update_post(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create_response(body)
|
||||
forum_topic.posts.create(
|
||||
:body => body
|
||||
)
|
||||
end
|
||||
|
||||
def update_title(title_tag)
|
||||
if forum_topic.title == expected_title
|
||||
forum_topic.update(:title => "[#{title_tag}] #{forum_topic.title}")
|
||||
end
|
||||
end
|
||||
|
||||
def update_post(body)
|
||||
forum_post.update(:body => "#{forum_post.body}\n\n#{body}")
|
||||
end
|
||||
end
|
||||
@@ -6,6 +6,14 @@ class TagAliasRequest
|
||||
validate :validate_tag_alias
|
||||
validate :validate_forum_topic
|
||||
|
||||
def self.topic_title(antecedent_name, consequent_name)
|
||||
"Tag alias: #{antecedent_name} -> #{consequent_name}"
|
||||
end
|
||||
|
||||
def self.command_string(antecedent_name, consequent_name)
|
||||
"create alias [[#{antecedent_name}]] -> [[#{consequent_name}]]"
|
||||
end
|
||||
|
||||
def initialize(attributes)
|
||||
@antecedent_name = attributes[:antecedent_name].strip.tr(" ", "_")
|
||||
@consequent_name = attributes[:consequent_name].strip.tr(" ", "_")
|
||||
@@ -23,7 +31,7 @@ class TagAliasRequest
|
||||
@forum_topic = build_forum_topic(@tag_alias.id)
|
||||
@forum_topic.save
|
||||
|
||||
@tag_alias.update_attribute(:forum_topic_id, @forum_topic.id)
|
||||
@tag_alias.update_attributes(forum_topic_id: @forum_topic.id, forum_post_id: @forum_topic.posts.first.id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,9 +47,9 @@ class TagAliasRequest
|
||||
|
||||
def build_forum_topic(tag_alias_id)
|
||||
ForumTopic.new(
|
||||
:title => "Tag alias: #{antecedent_name} -> #{consequent_name}",
|
||||
:title => TagAliasRequest.topic_title(antecedent_name, consequent_name),
|
||||
:original_post_attributes => {
|
||||
:body => "create alias [[#{antecedent_name}]] -> [[#{consequent_name}]]\n\n\"Link to alias\":/tag_aliases?search[id]=#{tag_alias_id}\n\n#{reason}"
|
||||
:body => TagAliasRequest.command_string(antecedent_name, consequent_name) + "\n\n\"Link to alias\":/tag_aliases?search[id]=#{tag_alias_id}\n\n#{reason}"
|
||||
},
|
||||
:category_id => 1
|
||||
)
|
||||
|
||||
@@ -6,6 +6,14 @@ class TagImplicationRequest
|
||||
validate :validate_tag_implication
|
||||
validate :validate_forum_topic
|
||||
|
||||
def self.topic_title(antecedent_name, consequent_name)
|
||||
"Tag implication: #{antecedent_name} -> #{consequent_name}"
|
||||
end
|
||||
|
||||
def self.command_string(antecedent_name, consequent_name)
|
||||
"create implication [[#{antecedent_name}]] -> [[#{consequent_name}]]"
|
||||
end
|
||||
|
||||
def initialize(attributes)
|
||||
@antecedent_name = attributes[:antecedent_name].strip.tr(" ", "_")
|
||||
@consequent_name = attributes[:consequent_name].strip.tr(" ", "_")
|
||||
@@ -23,7 +31,7 @@ class TagImplicationRequest
|
||||
@forum_topic = build_forum_topic(@tag_implication.id)
|
||||
@forum_topic.save
|
||||
|
||||
@tag_implication.update_attribute(:forum_topic_id, @forum_topic.id)
|
||||
@tag_implication.update_attributes(:forum_topic_id => @forum_topic.id, :forum_post_id => @forum_topic.posts.first.id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,9 +47,9 @@ class TagImplicationRequest
|
||||
|
||||
def build_forum_topic(tag_implication_id)
|
||||
ForumTopic.new(
|
||||
:title => "Tag implication: #{antecedent_name} -> #{consequent_name}",
|
||||
:title => TagImplicationRequest.topic_title(antecedent_name, consequent_name),
|
||||
:original_post_attributes => {
|
||||
:body => "create implication [[#{antecedent_name}]] -> [[#{consequent_name}]]\n\n\"Link to implication\":/tag_implications?search[id]=#{tag_implication_id}\n\n#{reason}"
|
||||
:body => TagImplicationRequest.command_string(antecedent_name, consequent_name) + "\n\n\"Link to implication\":/tag_implications?search[id]=#{tag_implication_id}\n\n#{reason}"
|
||||
},
|
||||
:category_id => 1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user