diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index b42c7470c4..72bf63d381 100755 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -820,15 +820,47 @@ def index_page_title end def log_admin_activity - if logged_in_as_admin? - options = { action: params[:action] } + return unless logged_in_as_admin? - if params[:action] == 'update_tags' - summary = "Old tags: #{@work.tags.pluck(:name).join(', ')}" + if params[:action] == "update_tags" + unless params[:work][:language_id].empty? + old_language_id = @work.language_id + new_language_id = params[:work][:language_id].to_i + + if old_language_id != new_language_id + new_language_name = Language.find_by(id: new_language_id).name + edit_language_summary = "
Old language: #{@work.language.name}
New language: #{new_language_name}
" + + AdminActivity.log_action(current_admin, @work, action: "edit language", summary: edit_language_summary) + end + end + + # Don't log if nothing changed. + rating_changed = params[:work][:rating_string] != @work.rating_string + fandoms_changed = params[:work][:fandom_string] != @work.fandom_string + relationships_changed = params[:work][:relationship_string] != @work.relationship_string + characters_changed = params[:work][:character_string] != @work.character_string + freeforms_changed = params[:work][:freeform_string] != @work.freeform_string + # Saving without previewing uses "strings" category and warning parameters + # but previewing and saving uses "string" ones + if params[:work][:category_strings].nil? + categories_changed = params[:work][:category_string] != @work.category_string + warnings_changed = params[:work][:archive_warning_string] != @work.archive_warning_string + else + # The category_strings and archive_warning_strings params values + # both start with an empty element which has to be dropped here + categories_changed = params[:work][:category_strings].drop(1).sort != @work.category_strings.sort + warnings_changed = params[:work][:archive_warning_strings].drop(1).sort != @work.archive_warning_strings.sort end - AdminActivity.log_action(current_admin, @work, action: params[:action], summary: summary) + return unless rating_changed || fandoms_changed || relationships_changed || + characters_changed || freeforms_changed || + categories_changed || warnings_changed + + summary = "Old tags: #{@work.tags.pluck(:name).join(', ')}" end + + AdminActivity.log_action(current_admin, @work, action: params[:action], summary: summary) end private diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 1b085c2106..d2e94f101c 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -14,11 +14,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 2520553933..2f9f54e048 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,40 @@ 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 Tags and Language" + 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 Tags and Language" + 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 Tags and Language" + 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: can mark a work as spam Given the work "Spammity Spam" And I am logged in as a "policy_and_abuse" admin