Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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], 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]

Expand Down Expand Up @@ -825,16 +826,33 @@ 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?
options = { action: params[:action] }
return unless logged_in_as_admin?

if params[:action] == 'update_tags'
summary = "Old tags: #{@work.tags.pluck(:name).join(', ')}"
end
action = params[:action]

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(action) if tags_changed
end

def log_admin_language_edit
new_language = @work.language.name
edit_summary = "<p>Old language: #{@old_language}</p><p>New language: #{new_language}</p>"
AdminActivity.log_action(current_admin, @work, action: "edit language", summary: edit_summary)
end

def log_admin_tag_edit(action)
edit_summary = "Old tags: #{@old_tags.join(', ')}"
AdminActivity.log_action(current_admin, @work, action: action, summary: edit_summary)
end

private
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions features/admins/admin_works.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 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: 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 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: 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 Tags and Language"
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
Expand Down
Loading