Orphan domain blocks when their severity is changed

This commit is contained in:
Claire
2026-09-03 17:20:50 +02:00
parent ed08c623d1
commit a2a8cf5706
5 changed files with 37 additions and 4 deletions

View File

@@ -57,6 +57,7 @@ module Admin
if existing_domain_block.present? && existing_domain_block.domain == TagManager.instance.normalize_domain(@domain_block.domain)
@domain_block = existing_domain_block
@domain_block.assign_attributes(resource_params)
@domain_block.moderation_subscription_id = nil if @domain_block.severity_changed?
end
# Require explicit confirmation when suspending
@@ -75,6 +76,7 @@ module Admin
authorize :domain_block, :update?
@domain_block.assign_attributes(update_params)
@domain_block.moderation_subscription_id = nil if @domain_block.severity_changed?
# Require explicit confirmation when suspending
return render :confirm_suspension if requires_confirmation?

View File

@@ -41,7 +41,9 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController
def update
authorize @domain_block, :update?
@domain_block.update!(domain_block_params)
@domain_block.assign_attributes(domain_block_params)
@domain_block.moderation_subscription_id = nil if @domain_block.severity_changed?
@domain_block.save!
DomainBlockWorker.perform_async(@domain_block.id, @domain_block.severity_previously_changed?)
log_action :update, @domain_block
render json: @domain_block, serializer: REST::Admin::DomainBlockSerializer

View File

@@ -1,6 +1,26 @@
# frozen_string_literal: true
module Admin::ActionLogsHelper
def action_log_title(log)
log.account_id == -99 ? automated_action_log_title(log) : generic_action_log_title(log)
end
def automated_action_log_title(log)
t("admin.action_logs.automated_actions.#{log.action}_#{log.target_type.underscore}_html",
target: content_tag(:span, log_target(log), class: 'target'))
end
def generic_action_log_title(log)
t("admin.action_logs.actions.#{log.action}_#{log.target_type.underscore}_html",
name: content_tag(:span, log.account.username, class: 'username'),
target: content_tag(:span, log_target(log), class: 'target'))
end
def action_log_subscription(log)
subscription = log.moderation_subscription.present? ? link_to(log.moderation_subscription.name, admin_moderation_subscription_path(log.moderation_subscription)) : t('admin.action_logs.deleted_suggestion')
t('admin.action_logs.suggested_by_html', subscription: content_tag(:span, subscription, class: 'target'))
end
def log_target(log)
case log.target_type
when 'Account'

View File

@@ -4,11 +4,13 @@
= image_tag action_log.account.avatar.url(:original), alt: '', width: 40, height: 40, class: 'avatar'
.log-entry__content
.log-entry__title
= t("admin.action_logs.actions.#{action_log.action}_#{action_log.target_type.underscore}_html",
name: content_tag(:span, action_log.account.username, class: 'username'),
target: content_tag(:span, log_target(action_log), class: 'target'))
= action_log_title(action_log)
- if action_log.recorded_changes.present?
= t(chain_multiple_translations(action_log))
- if action_log.moderation_subscription_id.present?
.log-entry__suggestion
= action_log_subscription(action_log)
.log-entry__timestamp
%time.formatted{ datetime: action_log.created_at.iso8601 }

View File

@@ -343,11 +343,18 @@ en:
update_user_role_html: "%{name} changed %{target} role"
update_username_block_html: "%{name} updated rule for usernames containing %{target}"
usable_tag_html: can be used;
automated_actions:
create_domain_allow_html: Automatically allowed federation with domain %{target}
create_domain_block_html: Automatically blocked domain %{target}
destroy_domain_allow_html: Automatically disallowed federation with domain %{target}
destroy_domain_block_html: Automatically unblocked domain %{target}
update_domain_block_html: Automatically updated domain block for %{target}
deleted_account: deleted account
deleted_suggestion: a deleted moderation subscription
empty: No logs found.
filter_by_action: Filter by action
filter_by_user: Filter by user
suggested_by_html: Action suggested by %{subscription}
title: Audit log
unavailable_instance: "(domain name unavailable)"
announcements: