This commit is contained in:
Pia B.
2026-06-09 13:57:22 +00:00
committed by GitHub
8 changed files with 39 additions and 0 deletions

View File

@@ -17,12 +17,14 @@ module Admin
authorize @tag, :show?
@time_period = report_range
@action_logs = Admin::ActionLogFilter.new(target_tag: @tag.formatted_name).results.limit(5)
end
def update
authorize @tag, :update?
if @tag.update(tag_params.merge(reviewed_at: Time.now.utc))
log_action :update, @tag
redirect_to admin_tag_path(@tag.id), notice: I18n.t('admin.tags.updated_msg')
else
@time_period = report_range

View File

@@ -37,6 +37,8 @@ module Admin::ActionLogsHelper
end
when 'Relay'
link_to log.human_identifier, admin_relays_path
when 'Tag'
link_to log.human_identifier, admin_tags_path
end
end

View File

@@ -76,6 +76,7 @@ class Admin::ActionLogFilter
update_status: { target_type: 'Status', action: 'update' }.freeze,
update_user_role: { target_type: 'UserRole', action: 'update' }.freeze,
update_ip_block: { target_type: 'IpBlock', action: 'update' }.freeze,
update_tag: { target_type: 'Tag', action: 'update' }.freeze,
unblock_email_account: { target_type: 'Account', action: 'unblock_email' }.freeze,
create_username_block: { target_type: 'UsernameBlock', action: 'create' }.freeze,
update_username_block: { target_type: 'UsernameBlock', action: 'update' }.freeze,
@@ -116,6 +117,8 @@ class Admin::ActionLogFilter
when 'target_domain'
normalized_domain = TagManager.instance.normalize_domain(value)
latest_action_logs.where(human_identifier: normalized_domain, target_type: INSTANCE_TARGET_TYPES)
when 'target_tag'
latest_action_logs.where(human_identifier: value)
else
raise Mastodon::InvalidParameterError, "Unknown filter: #{key}"
end

View File

@@ -110,6 +110,10 @@ class Tag < ApplicationRecord
@history ||= Trends::History.new('tags', id)
end
def to_log_human_identifier
formatted_name
end
class << self
def find_or_create_by_names(name_or_names)
names = Array(name_or_names).map { |str| [normalize_value_for(:name, str), str] }.uniq(&:first)

View File

@@ -90,3 +90,14 @@
.actions
= f.button :button, t('generic.save_changes'), type: :submit
- if @tag.persisted?
%hr.spacer/
%h3= t('admin.tags.audit_log.title')
- if @action_logs.nil?
%p= t('accounts.nothing_here')
- else
.report-notes
= render partial: 'admin/action_logs/action_log', collection: @action_logs
= link_to t('admin.instances.audit_log.view_all'), admin_action_logs_path(action_type: 'update_tag'), class: 'button'

View File

@@ -243,6 +243,7 @@ en-GB:
update_ip_block: Update IP rule
update_report: Update Report
update_status: Update Post
update_tag: Update Hashtag
update_user_role: Update Role
update_username_block: Update Username Rule
actions:
@@ -313,6 +314,7 @@ en-GB:
update_ip_block_html: "%{name} changed rule for IP %{target}"
update_report_html: "%{name} updated report %{target}"
update_status_html: "%{name} updated post by %{target}"
update_tag_html: "%{name} changed rule for %{target}"
update_user_role_html: "%{name} changed %{target} role"
update_username_block_html: "%{name} updated rule for usernames containing %{target}"
deleted_account: deleted account

View File

@@ -1101,6 +1101,8 @@ en:
action: Check here for more information
message_html: "<strong>Your object storage is misconfigured. The privacy of your users is at risk.</strong>"
tags:
audit_log:
title: Recent Audit Logs
moderation:
not_trendable: Not trendable
not_usable: Not usable

View File

@@ -15,4 +15,17 @@ RSpec.describe 'Admin Tags' do
.to have_http_status(400)
end
end
describe 'update tag' do
before { sign_in Fabricate(:admin_user) }
let(:tag) { Fabricate :tag, name: '#supertag' }
it 'redirects to tag page and saves log action for tag' do
put admin_tag_path(tag.id, params: { tag: { trendable: true } })
expect(response).to have_http_status(302)
expect(Admin::ActionLog.last.human_identifier).to eq(tag.formatted_name)
end
end
end