diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index f2c28328f86..449422c202f 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -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 diff --git a/app/helpers/admin/action_logs_helper.rb b/app/helpers/admin/action_logs_helper.rb index 76edb965a6a..22450be4f2f 100644 --- a/app/helpers/admin/action_logs_helper.rb +++ b/app/helpers/admin/action_logs_helper.rb @@ -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 diff --git a/app/models/admin/action_log_filter.rb b/app/models/admin/action_log_filter.rb index b912865cc85..02980d06477 100644 --- a/app/models/admin/action_log_filter.rb +++ b/app/models/admin/action_log_filter.rb @@ -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 diff --git a/app/models/tag.rb b/app/models/tag.rb index a5fbf2f6837..6ac34832f8f 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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) diff --git a/app/views/admin/tags/show.html.haml b/app/views/admin/tags/show.html.haml index 0c8b2eaec0b..ea40801e95e 100644 --- a/app/views/admin/tags/show.html.haml +++ b/app/views/admin/tags/show.html.haml @@ -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' diff --git a/config/locales/en-GB.yml b/config/locales/en-GB.yml index 9d535e3af02..847d4a55a71 100644 --- a/config/locales/en-GB.yml +++ b/config/locales/en-GB.yml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 95631bd86b9..e3c7b284082 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1101,6 +1101,8 @@ en: action: Check here for more information message_html: "Your object storage is misconfigured. The privacy of your users is at risk." tags: + audit_log: + title: Recent Audit Logs moderation: not_trendable: Not trendable not_usable: Not usable diff --git a/spec/requests/admin/tags_spec.rb b/spec/requests/admin/tags_spec.rb index 653c5bd9356..543102e1ebe 100644 --- a/spec/requests/admin/tags_spec.rb +++ b/spec/requests/admin/tags_spec.rb @@ -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