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:
@@ -15,7 +15,7 @@ class TagAliasesController < ApplicationController
|
|||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@tag_alias = authorize TagAlias.find(params[:id])
|
@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")
|
respond_with(@tag_alias, location: tag_aliases_path, notice: "Tag alias was deleted")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class TagImplicationsController < ApplicationController
|
|||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@tag_implication = authorize TagImplication.find(params[:id])
|
@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")
|
respond_with(@tag_implication, location: tag_implications_path, notice: "Tag implication was deleted")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -144,11 +144,11 @@ class BulkUpdateRequestProcessor
|
|||||||
|
|
||||||
when :remove_alias
|
when :remove_alias
|
||||||
tag_alias = TagAlias.active.find_by!(antecedent_name: args[0], consequent_name: args[1])
|
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
|
when :remove_implication
|
||||||
tag_implication = TagImplication.active.find_by!(antecedent_name: args[0], consequent_name: args[1])
|
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
|
when :mass_update
|
||||||
TagBatchChangeJob.perform_later(args[0], args[1])
|
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
|
# 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
|
# otherwise the tag won't be removed from posts that have those other tags
|
||||||
if PostQueryBuilder.new(args[0]).is_simple_tag?
|
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
|
end
|
||||||
|
|
||||||
TagBatchChangeJob.perform_later(args[0], "-#{args[0]}")
|
TagBatchChangeJob.perform_later(args[0], "-#{args[0]}")
|
||||||
|
|||||||
@@ -46,8 +46,10 @@ class ModAction < ApplicationRecord
|
|||||||
forum_post_delete: 102,
|
forum_post_delete: 102,
|
||||||
tag_alias_create: 120,
|
tag_alias_create: 120,
|
||||||
tag_alias_update: 121, # XXX unused
|
tag_alias_update: 121, # XXX unused
|
||||||
|
tag_alias_delete: 122,
|
||||||
tag_implication_create: 140,
|
tag_implication_create: 140,
|
||||||
tag_implication_update: 141, # XXX unused
|
tag_implication_update: 141, # XXX unused
|
||||||
|
tag_implication_delete: 142,
|
||||||
ip_ban_create: 160,
|
ip_ban_create: 160,
|
||||||
ip_ban_delete: 162,
|
ip_ban_delete: 162,
|
||||||
ip_ban_undelete: 163,
|
ip_ban_undelete: 163,
|
||||||
|
|||||||
@@ -43,6 +43,6 @@ class TagAlias < TagRelationship
|
|||||||
tag_relationships << TagAlias.active.find_by(antecedent_name: consequent_name, consequent_name: antecedent_name)
|
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: antecedent_name, consequent_name: consequent_name)
|
||||||
tag_relationships << TagImplication.active.find_by(antecedent_name: consequent_name, consequent_name: antecedent_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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -43,8 +43,16 @@ class TagRelationship < ApplicationRecord
|
|||||||
status == "active"
|
status == "active"
|
||||||
end
|
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")
|
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
|
end
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
|
|||||||
@@ -55,10 +55,12 @@ class TagAliasesControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
context "destroy action" do
|
context "destroy action" do
|
||||||
should "allow admins to delete aliases" 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_response :redirect
|
||||||
assert_equal("deleted", @tag_alias.reload.status)
|
assert_equal("deleted", @tag_alias.reload.status)
|
||||||
|
assert_equal(user, ModAction.tag_alias_delete.last.creator)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not allow members to delete aliases" do
|
should "not allow members to delete aliases" do
|
||||||
|
|||||||
@@ -65,10 +65,12 @@ class TagImplicationsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
context "destroy action" do
|
context "destroy action" do
|
||||||
should "allow admins to delete implications" 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_response :redirect
|
||||||
assert_equal("deleted", @tag_implication.reload.status)
|
assert_equal("deleted", @tag_implication.reload.status)
|
||||||
|
assert_equal(user, ModAction.tag_implication_delete.last.creator)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not allow members to delete aliases" do
|
should "not allow members to delete aliases" do
|
||||||
|
|||||||
Reference in New Issue
Block a user