diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index 1e7ec3f70ab..5f7299784c3 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, :update, :update_multiple, :delete_multiple, :search, :mark_for_later, :mark_as_read, :drafts, :collected, :share] # admins should have the ability to edit works (tags, language, and more) as per our ToS before_action :check_ownership_or_admin, only: [:edit, :update] - before_action :log_admin_activity, only: [:update] + before_action :save_old_tags, only: [:update] + after_action :log_admin_activity, only: [:update] before_action :check_parent_visible, only: [:navigate] before_action :check_visibility, only: [:show, :navigate, :share, :mark_for_later, :mark_as_read] @@ -832,12 +833,31 @@ def index_page_title end end + def save_old_tags + @old_language = @work.language.name + @old_tags = @work.tags.pluck(:name) + end + def log_admin_activity - if logged_in_as_admin? - summary = "Old tags: #{@work.tags.pluck(:name).join(', ')}" if params[:action] == "update" + return unless logged_in_as_admin? - AdminActivity.log_action(current_admin, @work, action: params[:action], summary: summary) - end + log_admin_language_edit if @work.saved_change_to_language_id? + + new_tags = @work.tags.pluck(:name) + tags_changed = new_tags.sort != @old_tags.sort + + log_admin_tag_edit if tags_changed + end + + def log_admin_language_edit + new_language = @work.language.name + edit_summary = "

Old language: #{@old_language}

New language: #{new_language}

" + AdminActivity.log_action(current_admin, @work, action: "edit language", summary: edit_summary) + end + + def log_admin_tag_edit + edit_summary = "Old tags: #{@old_tags.join(', ')}" if @old_tags.present? + AdminActivity.log_action(current_admin, @work, action: "update_tags", summary: edit_summary) end private diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 6f17f78e0f5..67303f6716f 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -17,11 +17,11 @@ def admin_activity_target_link(activity) link_to(activity.target_name, url) end - # Summaries for profile and pseud edits, which contain links, need to be - # handled differently from summaries that use item.inspect (and thus contain - # angle brackets). + # Summaries for profile and pseud edits, which contain links, and summaries for + # language edits, which have multiple paragraphs, need to be handled differently + # from summaries that use item.inspect (and thus contain angle brackets). def admin_activity_summary(activity) - if activity.action == "edit pseud" || activity.action == "edit profile" + if activity.action == "edit pseud" || activity.action == "edit profile" || activity.action == "edit language" raw sanitize_field(activity, :summary) else activity.summary diff --git a/features/admins/admin_works.feature b/features/admins/admin_works.feature index 3ef1b9b03e0..4b97a160970 100644 --- a/features/admins/admin_works.feature +++ b/features/admins/admin_works.feature @@ -381,6 +381,11 @@ Feature: Admin Actions for Works, Comments, Series, Bookmarks And I press "Update" Then I should see "Deutsch" And I should not see "English" + When I follow "Activities" + Then I should see "edit language" + When I visit the last activities item + Then I should see "Old language: English" + And I should see "New language: Deutsch" Scenario: Admin can edit language on works when previewing first Given basic languages @@ -395,6 +400,62 @@ Feature: Admin Actions for Works, Comments, Series, Bookmarks Then I should see "Deutsch" And I should not see "English" + Scenario: When admin edits tags and language on works at the same time, both Activities entries are added + Given basic languages + And the work "Wrong Tags and Language" + When I am logged in as a "policy_and_abuse" admin + And I view the work "Wrong Tags and Language" + And I follow "Edit Work" + When I select "Mature" from "Rating" + And I select "Deutsch" from "Choose a language" + And I press "Update" + And I follow "Activities" + Then I should see "update_tags" + And I should see "edit language" + + Scenario: When admin does not edit tags or language and posts without previewing, no Activities entries are added + Given the work "Nothing Wrong" + When I am logged in as a "policy_and_abuse" admin + And I view the work "Nothing Wrong" + And I follow "Edit Work" + And I press "Update" + And I follow "Activities" + Then I should not see "update_tags" + And I should not see "edit language" + + Scenario: When admin does not edit tags or language, previews and then posts, no Activities entries are added + Given the work "Nothing Wrong" + When I am logged in as a "policy_and_abuse" admin + And I view the work "Nothing Wrong" + And I follow "Edit Work" + And I press "Preview" + And I press "Update" + And I follow "Activities" + Then I should not see "update_tags" + And I should not see "edit language" + + Scenario: When admin tries to make an invalid edit, no Activities entries are added + Given the work "Some Fic" + When I am logged in as a "policy_and_abuse" admin + And I view the work "Some Fic" + And I follow "Edit Work" + 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: When admin previews without saving, no Activities entries are added + Given basic languages + And the work "Some Fic" + When I am logged in as a "policy_and_abuse" admin + And I view the work "Some Fic" + And I follow "Edit Work" + And I select "Mature" from "Rating" + And I select "Deutsch" from "Choose a language" + When I press "Preview" + And I follow "Activities" + Then I should see 0 admin activity log entries + Scenario: can mark a work as spam Given the work "Spammity Spam" And I am logged in as a "policy_and_abuse" admin