Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 11 additions & 2 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], 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]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 26 additions & 4 deletions features/admins/admin_works.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading