BURs: don't add [APPROVED] / [REJECTED] tags to titles.
This commit is contained in:
@@ -1,18 +1,16 @@
|
|||||||
class ForumUpdater
|
class ForumUpdater
|
||||||
attr_reader :forum_topic, :forum_post, :expected_title
|
attr_reader :forum_topic, :forum_post
|
||||||
|
|
||||||
def initialize(forum_topic, options = {})
|
def initialize(forum_topic, options = {})
|
||||||
@forum_topic = forum_topic
|
@forum_topic = forum_topic
|
||||||
@forum_post = options[:forum_post]
|
@forum_post = options[:forum_post]
|
||||||
@expected_title = options[:expected_title]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update(message, title_tag = nil)
|
def update(message)
|
||||||
return if forum_topic.nil?
|
return if forum_topic.nil?
|
||||||
|
|
||||||
CurrentUser.scoped(User.system) do
|
CurrentUser.scoped(User.system) do
|
||||||
create_response(message)
|
create_response(message)
|
||||||
update_title(title_tag) if title_tag
|
|
||||||
|
|
||||||
if forum_post
|
if forum_post
|
||||||
update_post(message)
|
update_post(message)
|
||||||
@@ -24,12 +22,6 @@ class ForumUpdater
|
|||||||
forum_topic.posts.create(body: body, skip_mention_notifications: true, creator: User.system)
|
forum_topic.posts.create(body: body, skip_mention_notifications: true, creator: User.system)
|
||||||
end
|
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)
|
def update_post(body)
|
||||||
forum_post.update(body: "#{forum_post.body}\n\nEDIT: #{body}", skip_mention_notifications: true)
|
forum_post.update(body: "#{forum_post.body}\n\nEDIT: #{body}", skip_mention_notifications: true)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -64,11 +64,7 @@ class BulkUpdateRequest < ApplicationRecord
|
|||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
ForumUpdater.new(
|
ForumUpdater.new(forum_topic, forum_post: post)
|
||||||
forum_topic,
|
|
||||||
forum_post: post,
|
|
||||||
expected_title: title
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -77,13 +73,13 @@ class BulkUpdateRequest < ApplicationRecord
|
|||||||
CurrentUser.scoped(approver) do
|
CurrentUser.scoped(approver) do
|
||||||
AliasAndImplicationImporter.new(script, forum_topic_id, "1", true).process!
|
AliasAndImplicationImporter.new(script, forum_topic_id, "1", true).process!
|
||||||
update!(status: "approved", approver: approver, skip_secondary_validations: true)
|
update!(status: "approved", approver: approver, skip_secondary_validations: true)
|
||||||
forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has been approved by @#{approver.name}.", "APPROVED")
|
forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has been approved by @#{approver.name}.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue AliasAndImplicationImporter::Error => x
|
rescue AliasAndImplicationImporter::Error => x
|
||||||
self.approver = approver
|
self.approver = approver
|
||||||
CurrentUser.scoped(approver) do
|
CurrentUser.scoped(approver) do
|
||||||
forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has failed: #{x}", "FAILED")
|
forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has failed: #{x}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -98,7 +94,7 @@ class BulkUpdateRequest < ApplicationRecord
|
|||||||
def reject!(rejector = User.system)
|
def reject!(rejector = User.system)
|
||||||
transaction do
|
transaction do
|
||||||
update(status: "rejected")
|
update(status: "rejected")
|
||||||
forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has been rejected by @#{rejector.name}.", "REJECTED")
|
forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has been rejected by @#{rejector.name}.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,6 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
assert_equal("pending", @req.reload.status)
|
assert_equal("pending", @req.reload.status)
|
||||||
assert_match(/\[FAILED\]/, @topic.reload.title)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "leave the BUR pending if there is an unexpected error during approval" do
|
should "leave the BUR pending if there is an unexpected error during approval" do
|
||||||
@@ -188,9 +187,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
|||||||
@req.approve!(@admin)
|
@req.approve!(@admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
@topic.reload
|
assert_match(/approved/, @post.reload.body)
|
||||||
@post.reload
|
|
||||||
assert_match(/\[APPROVED\]/, @topic.title)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "update the topic when rejected" do
|
should "update the topic when rejected" do
|
||||||
@@ -200,9 +197,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
|||||||
@req.reject!(@admin)
|
@req.reject!(@admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
@topic.reload
|
assert_match(/rejected/, @post.reload.body)
|
||||||
@post.reload
|
|
||||||
assert_match(/\[REJECTED\]/, @topic.title)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "reference the rejector in the automated message" do
|
should "reference the rejector in the automated message" do
|
||||||
|
|||||||
Reference in New Issue
Block a user