Skip to content

Commit

Permalink
Allow updates to draft deleted assets
Browse files Browse the repository at this point in the history
In publishing apps, we have the following issue:

1. User replaces an attachment asset with a new one on a new edition of a published document.
2. User deletes the attachment.
3. User publishes the new edition of the document.
4. Replaced attachment asset remains live.

This happens because the deleted asset still has a value of "false" for the draft attribute,
so the replacement on the old asset is not active.

In order to address this, we are allowing the update of draft deleted assets.
Given that assets are still live on GOV.UK until they are both "deleted" and "live"
(i.e. have a draft value of "false"), we are more accurately fulfilling the intent
of the API by allowing updates to deleted draft assets.
  • Loading branch information
lauraghiorghisor-tw committed Jan 7, 2025
1 parent a4089e8 commit aab3b33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/assets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class AssetsController < BaseAssetsController
before_action :restrict_request_format

def update
@asset = find_asset
@asset = Asset.undeleted.or(Asset.where(draft: true)).find(params[:id])

if @asset.update(asset_params)
render json: AssetPresenter.new(@asset, view_context).as_json(status: :success)
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/assets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,22 @@

expect(body["draft"]).to be_truthy
end

it "changes draft state for draft deleted asset" do
asset.update!(deleted_at: 1.hour.ago, draft: true)

put :update, params: { id: asset.id, asset: attributes.merge(draft: false) }

expect(asset.reload).not_to be_draft
end

it "preserves draft state for live deleted asset" do
asset.update!(deleted_at: 1.hour.ago, draft: false)

put :update, params: { id: asset.id, asset: attributes.merge(draft: true) }

expect(asset.reload).not_to be_draft
end
end
end
end
Expand Down

0 comments on commit aab3b33

Please sign in to comment.