Skip to content

Commit

Permalink
Remove also assets which are in draft but not deleted, replaced, or r…
Browse files Browse the repository at this point in the history
…edirected

These are relatively harmless to the public, as the links will redirect to SignOn and require a login to preview. However it would still be available to other users with a SignOn account. For assets that are superseded, it's probably best we also remove them so users are certain that as long as assets are not linked to their live or preview editions, it should not be accessible anywhere.
  • Loading branch information
minhngocd committed Dec 6, 2024
1 parent 392c045 commit 560213a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace :assets do
next
end

if original_asset.draft? || original_asset.deleted? || replacement_asset || original_asset.redirect_url
if original_asset.deleted? || replacement_asset || original_asset.redirect_url
puts "Asset ID: #{original_asset_id} - SKIPPED. Asset is draft (#{original_asset.draft?}), deleted (#{original_asset.deleted?}), replaced (#{!replacement_asset.nil?}), or redirected (#{!original_asset.redirect_url.nil?})."
next
end
Expand Down
19 changes: 10 additions & 9 deletions spec/lib/tasks/assets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,6 @@
expect { task.invoke(filepath) }.to output(expected_output).to_stdout
end

it "skips the asset if asset is itself in draft (and not replaced by draft or itself a replacement)" do
FactoryBot.create(:asset, id: asset_id, draft: true)

expected_output = <<~OUTPUT
Asset ID: #{asset_id} - SKIPPED. Asset is draft (true), deleted (false), replaced (false), or redirected (false).
OUTPUT
expect { task.invoke(filepath) }.to output(expected_output).to_stdout
end

it "skips the asset, if the asset is already deleted (and is not itself a replacement)" do
FactoryBot.create(:asset, id: asset_id, deleted_at: Time.zone.now)

Expand Down Expand Up @@ -382,6 +373,16 @@
expect { task.invoke(filepath) }.to output(expected_output).to_stdout
end

it "deletes but not update draft status of the asset if asset is itself in draft, not deleted, not redirected, not replaced" do
asset =FactoryBot.create(:asset, id: asset_id, draft: true)

Check failure on line 377 in spec/lib/tasks/assets_spec.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/SpaceAroundOperators: Surrounding space missing for operator `=`. (https://rubystyle.guide#spaces-operators)

expected_output = <<~OUTPUT
Asset ID: #{asset_id} - OK. Asset has been deleted.

Check failure on line 380 in spec/lib/tasks/assets_spec.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc. (https://rubystyle.guide#squiggly-heredocs)
OUTPUT

Check failure on line 381 in spec/lib/tasks/assets_spec.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/ClosingHeredocIndentation: `OUTPUT` is not aligned with `expected_output = <<~OUTPUT`.
expect { task.invoke(filepath) }.to output(expected_output).to_stdout
expect(asset.reload.draft).to be true
end

it "marks a line as 'done' in the CSV if line is processed" do
FactoryBot.create(:asset, id: asset_id, draft: true, deleted_at: nil)
task.invoke(filepath)
Expand Down

0 comments on commit 560213a

Please sign in to comment.