diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index 6baf30a5e..a677ec049 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -15,7 +15,7 @@ class TagAliasesController < ApplicationController def destroy @tag_alias = authorize TagAlias.find(params[:id]) - @tag_alias.reject! + @tag_alias.reject!(CurrentUser.user) respond_with(@tag_alias, location: tag_aliases_path, notice: "Tag alias was deleted") end diff --git a/app/controllers/tag_implications_controller.rb b/app/controllers/tag_implications_controller.rb index 02264b92a..306cfff46 100644 --- a/app/controllers/tag_implications_controller.rb +++ b/app/controllers/tag_implications_controller.rb @@ -15,7 +15,7 @@ class TagImplicationsController < ApplicationController def destroy @tag_implication = authorize TagImplication.find(params[:id]) - @tag_implication.reject! + @tag_implication.reject!(CurrentUser.user) respond_with(@tag_implication, location: tag_implications_path, notice: "Tag implication was deleted") end diff --git a/app/logical/bulk_update_request_processor.rb b/app/logical/bulk_update_request_processor.rb index 40d558919..65895d06c 100644 --- a/app/logical/bulk_update_request_processor.rb +++ b/app/logical/bulk_update_request_processor.rb @@ -144,11 +144,11 @@ class BulkUpdateRequestProcessor when :remove_alias tag_alias = TagAlias.active.find_by!(antecedent_name: args[0], consequent_name: args[1]) - tag_alias.reject! + tag_alias.reject!(User.system) when :remove_implication tag_implication = TagImplication.active.find_by!(antecedent_name: args[0], consequent_name: args[1]) - tag_implication.reject! + tag_implication.reject!(User.system) when :mass_update TagBatchChangeJob.perform_later(args[0], args[1]) @@ -157,7 +157,7 @@ class BulkUpdateRequestProcessor # Reject existing implications from any other tag to the one we're nuking # otherwise the tag won't be removed from posts that have those other tags if PostQueryBuilder.new(args[0]).is_simple_tag? - TagImplication.active.where(consequent_name: args[0]).each(&:reject!) + TagImplication.active.where(consequent_name: args[0]).each { |ti| ti.reject!(User.system) } end TagBatchChangeJob.perform_later(args[0], "-#{args[0]}") diff --git a/app/models/mod_action.rb b/app/models/mod_action.rb index 1796b0c97..393a75b2b 100644 --- a/app/models/mod_action.rb +++ b/app/models/mod_action.rb @@ -46,8 +46,10 @@ class ModAction < ApplicationRecord forum_post_delete: 102, tag_alias_create: 120, tag_alias_update: 121, # XXX unused + tag_alias_delete: 122, tag_implication_create: 140, tag_implication_update: 141, # XXX unused + tag_implication_delete: 142, ip_ban_create: 160, ip_ban_delete: 162, ip_ban_undelete: 163, diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index bc0dde4f5..1afdb43ac 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -43,6 +43,6 @@ class TagAlias < TagRelationship tag_relationships << TagAlias.active.find_by(antecedent_name: consequent_name, consequent_name: antecedent_name) tag_relationships << TagImplication.active.find_by(antecedent_name: antecedent_name, consequent_name: consequent_name) tag_relationships << TagImplication.active.find_by(antecedent_name: consequent_name, consequent_name: antecedent_name) - tag_relationships.each { |rel| rel.reject! if rel.present? } + tag_relationships.each { |rel| rel.reject!(User.system) if rel.present? } end end diff --git a/app/models/tag_relationship.rb b/app/models/tag_relationship.rb index 316ad3ac8..60010a5a7 100644 --- a/app/models/tag_relationship.rb +++ b/app/models/tag_relationship.rb @@ -43,8 +43,16 @@ class TagRelationship < ApplicationRecord status == "active" end - def reject! + # Mark an alias or implication as deleted, and log a mod action if the + # deletion was manually performed by an admin, as opposed to automatically by + # DanbooruBot as part of a BUR. + def reject!(rejector = CurrentUser.user) update!(status: "deleted") + + if rejector != User.system + category = relationship == "tag alias" ? :tag_alias_delete : :tag_implication_delete + ModAction.log("deleted #{relationship} #{antecedent_name} -> #{consequent_name}", category, rejector) + end end module SearchMethods diff --git a/test/functional/tag_aliases_controller_test.rb b/test/functional/tag_aliases_controller_test.rb index 2db17a743..b0a38b08a 100644 --- a/test/functional/tag_aliases_controller_test.rb +++ b/test/functional/tag_aliases_controller_test.rb @@ -55,10 +55,12 @@ class TagAliasesControllerTest < ActionDispatch::IntegrationTest context "destroy action" do should "allow admins to delete aliases" do - delete_auth tag_alias_path(@tag_alias), create(:admin_user) + user = create(:admin_user) + delete_auth tag_alias_path(@tag_alias), user assert_response :redirect assert_equal("deleted", @tag_alias.reload.status) + assert_equal(user, ModAction.tag_alias_delete.last.creator) end should "not allow members to delete aliases" do diff --git a/test/functional/tag_implications_controller_test.rb b/test/functional/tag_implications_controller_test.rb index e7355b422..50948340b 100644 --- a/test/functional/tag_implications_controller_test.rb +++ b/test/functional/tag_implications_controller_test.rb @@ -65,10 +65,12 @@ class TagImplicationsControllerTest < ActionDispatch::IntegrationTest context "destroy action" do should "allow admins to delete implications" do - delete_auth tag_implication_path(@tag_implication), create(:admin_user) + user = create(:admin_user) + delete_auth tag_implication_path(@tag_implication), user assert_response :redirect assert_equal("deleted", @tag_implication.reload.status) + assert_equal(user, ModAction.tag_implication_delete.last.creator) end should "not allow members to delete aliases" do