From 54ca843f8a888c0282f02c515a26972ae5f5f634 Mon Sep 17 00:00:00 2001 From: caitlinkwan Date: Wed, 25 Mar 2026 01:52:52 -0400 Subject: [PATCH] AO3-7250 Remove cancelled and invalid tag edits from Activities log --- app/controllers/works_controller.rb | 13 +++++++++++-- features/admins/admin_works.feature | 30 +++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index 61e6ad43a02..1b9645f7907 100755 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -14,7 +14,8 @@ class WorksController < ApplicationController before_action :check_ownership, except: [:index, :show, :navigate, :new, :create, :import, :show_multiple, :edit_multiple, :edit_tags, :update_tags, :update_multiple, :delete_multiple, :search, :mark_for_later, :mark_as_read, :drafts, :collected, :share] # admins should have the ability to edit tags (:edit_tags, :update_tags) as per our ToS before_action :check_ownership_or_admin, only: [:edit_tags, :update_tags] - before_action :log_admin_activity, only: [:update_tags] + before_action :save_old_tags, only: [:update_tags] + after_action :log_admin_activity, only: [:update_tags], if: [:tried_to_save?], unless: [:work_cannot_be_saved?] before_action :check_parent_visible, only: [:navigate] before_action :check_visibility, only: [:show, :navigate, :share, :mark_for_later, :mark_as_read] @@ -780,6 +781,10 @@ def work_cannot_be_saved? !(@work.errors.empty? && @work.valid?) end + def tried_to_save? + params[:update_button].present? + end + def set_work_form_fields @work.reset_published_at(@chapter) @series = current_user.series.distinct @@ -825,12 +830,16 @@ def index_page_title end end + def save_old_tags + @old_tags = @work.tags.pluck(:name) + end + def log_admin_activity if logged_in_as_admin? options = { action: params[:action] } if params[:action] == 'update_tags' - summary = "Old tags: #{@work.tags.pluck(:name).join(', ')}" + summary = "Old tags: #{@old_tags.join(', ')}" end AdminActivity.log_action(current_admin, @work, action: params[:action], summary: summary) diff --git a/features/admins/admin_works.feature b/features/admins/admin_works.feature index 4e0936b0e5e..b5e7e79a65b 100644 --- a/features/admins/admin_works.feature +++ b/features/admins/admin_works.feature @@ -202,14 +202,36 @@ Feature: Admin Actions for Works, Comments, Series, Bookmarks And I should see "Mature" And I should see "Admin-Added Relationship" And I should see "Admin-Added Character" - When I follow "Activities" - Then I should see "Admin Activities" - When I visit the last activities item - Then I should see "No Archive Warnings Apply" + When I follow "Activities" + Then I should see "Admin Activities" + When I visit the last activities item + Then I should see "No Archive Warnings Apply" And I should see "Old tags" And I should see "User-Added Fandom" And I should not see "Admin-Added Fandom" + Scenario: No activity log when tag edits are invalid + Given I am logged in as "regular_user" + And I post the work "Changes" with fandom "User-Added Fandom" + When I am logged in as a "policy_and_abuse" admin + And I view the work "Changes" + And I follow "Edit Tags and Language" + And I uncheck "No Archive Warnings Apply" + When I press "Update" + And I follow "Activities" + Then I should see 0 admin activity log entries + + Scenario: No activity log when previewing without saving + Given I am logged in as "regular_user" + And I post the work "Changes" with fandom "User-Added Fandom" + When I am logged in as a "policy_and_abuse" admin + And I view the work "Changes" + And I follow "Edit Tags and Language" + And I fill in "Fandoms" with "Admin-Added Fandom" + When I press "Preview" + And I follow "Activities" + Then I should see 0 admin activity log entries + Scenario: Can edit external works Given basic languages And I am logged in as "regular_user"