aliases/implications: log manual deletions by admins.

Log when an admin manually deletes an alias or implication outside of a
BUR. This is usually only necessary when a BUR is bugged.
This commit is contained in:
evazion
2021-09-06 00:21:00 -05:00
parent 28edd5a22a
commit 4dcfd1d141
8 changed files with 23 additions and 9 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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]}")

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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