From f2351766c677cc5fd12af4129cadc9f1ca7776f5 Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 15 Nov 2017 12:50:15 -0600 Subject: [PATCH] Fix #3374: List approver in BUR approval messages. --- .../bulk_update_requests_controller.rb | 2 +- app/logical/forum_updater.rb | 2 +- app/models/bulk_update_request.rb | 12 ++++++++---- app/models/tag_alias.rb | 8 ++------ app/models/tag_implication.rb | 4 ++-- app/models/tag_relationship.rb | 18 +++++++++++++----- test/unit/bulk_update_request_test.rb | 2 +- 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/app/controllers/bulk_update_requests_controller.rb b/app/controllers/bulk_update_requests_controller.rb index 49b6be349..14e133574 100644 --- a/app/controllers/bulk_update_requests_controller.rb +++ b/app/controllers/bulk_update_requests_controller.rb @@ -38,7 +38,7 @@ class BulkUpdateRequestsController < ApplicationController def destroy if @bulk_update_request.editable?(CurrentUser.user) - @bulk_update_request.reject! + @bulk_update_request.reject!(CurrentUser.user) flash[:notice] = "Bulk update request rejected" respond_with(@bulk_update_request, :location => bulk_update_requests_path) else diff --git a/app/logical/forum_updater.rb b/app/logical/forum_updater.rb index 0951eec38..84db03410 100644 --- a/app/logical/forum_updater.rb +++ b/app/logical/forum_updater.rb @@ -33,6 +33,6 @@ class ForumUpdater end def update_post(body) - forum_post.update(:body => "#{forum_post.body}\n\n#{body}") + forum_post.update(:body => "#{forum_post.body}\n\nEDIT: #{body}") end end diff --git a/app/models/bulk_update_request.rb b/app/models/bulk_update_request.rb index 3f32659a8..a771fb420 100644 --- a/app/models/bulk_update_request.rb +++ b/app/models/bulk_update_request.rb @@ -95,13 +95,13 @@ class BulkUpdateRequest < ApplicationRecord CurrentUser.scoped(approver) do AliasAndImplicationImporter.new(script, forum_topic_id, "1", true).process! update({ :status => "approved", :approver_id => CurrentUser.id, :skip_secondary_validations => true }, :as => CurrentUser.role) - forum_updater.update("The \"bulk update request ##{id}\":/bulk_update_requests?search%5Bid%5D=#{id} has been approved.", "APPROVED") + forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has been approved by @#{approver.name}.", "APPROVED") end rescue Exception => x self.approver = approver CurrentUser.scoped(approver) do - forum_updater.update("The \"Bulk update request ##{id}\":/bulk_update_requests?search%5Bid%5D=#{id} has failed: #{x.to_s}", "FAILED") + forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has failed: #{x.to_s}", "FAILED") end end @@ -119,10 +119,14 @@ class BulkUpdateRequest < ApplicationRecord end end - def reject! - forum_updater.update("The \"bulk update request ##{id}\":/bulk_update_requests?search%5Bid%5D=#{id} has been rejected.", "REJECTED") + def reject!(rejector) + forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has been rejected by @#{rejector.name}.", "REJECTED") update_attribute(:status, "rejected") end + + def bulk_update_request_link + %{"bulk update request ##{id}":/bulk_update_requests?search%5Bid%5D=#{id}} + end end module ValidationMethods diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 52e789b4b..b98a0eb55 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -42,10 +42,6 @@ class TagAlias < TagRelationship delay(:queue => "default").process!(update_topic: update_topic) end end - - def conflict_message - "The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] (alias ##{id}) has conflicting wiki pages. [[#{consequent_name}]] should be updated to include information from [[#{antecedent_name}]] if necessary." - end end module ForumMethods @@ -90,7 +86,7 @@ class TagAlias < TagRelationship clear_all_cache ensure_category_consistency update_posts - forum_updater.update(approval_message, "APPROVED") if update_topic + forum_updater.update(approval_message(approver), "APPROVED") if update_topic rename_wiki_and_artist update({ :status => "active", :post_count => consequent_tag.post_count }, :as => CurrentUser.role) end @@ -227,7 +223,7 @@ class TagAlias < TagRelationship def reject! update({ :status => "deleted" }, :as => CurrentUser.role) clear_all_cache - forum_updater.update(reject_message, "REJECTED") + forum_updater.update(reject_message(CurrentUser.user), "REJECTED") destroy end diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index 3cb3a1ff7..9e1b75cde 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -148,7 +148,7 @@ class TagImplication < TagRelationship update_posts update({ :status => "active" }, :as => CurrentUser.role) update_descendant_names_for_parents - forum_updater.update(approval_message, "APPROVED") if update_topic + forum_updater.update(approval_message(approver), "APPROVED") if update_topic end rescue Exception => e if tries < 5 @@ -186,7 +186,7 @@ class TagImplication < TagRelationship def reject! update({ :status => "deleted", }, :as => CurrentUser.role) - forum_updater.update(reject_message, "REJECTED") + forum_updater.update(reject_message(CurrentUser.user), "REJECTED") destroy end diff --git a/app/models/tag_relationship.rb b/app/models/tag_relationship.rb index 637befd0a..8a9be2780 100644 --- a/app/models/tag_relationship.rb +++ b/app/models/tag_relationship.rb @@ -123,21 +123,29 @@ class TagRelationship < ApplicationRecord self.class.name.underscore.tr("_", " ") end - def approval_message - "The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] has been approved." + def approval_message(approver) + "The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] #{forum_link} has been approved by @#{approver.name}." end def failure_message(e = nil) - "The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] failed during processing. Reason: #{e}" + "The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] #{forum_link} failed during processing. Reason: #{e}" end - def reject_message - "The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] has been rejected." + def reject_message(rejector) + "The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] #{forum_link} has been rejected by @#{rejector.name}." + 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 def date_timestamp Time.now.strftime("%Y-%m-%d") end + + def forum_link + "(forum ##{forum_post.id})" if forum_post.present? + end end extend SearchMethods diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb index 654c91ab4..6f21c1a8a 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -127,7 +127,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase @req.approver_id = @admin.id assert_difference("ForumPost.count") do - @req.reject! + @req.reject!(@admin) end @topic.reload