-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9828 from alphagov/ensure-deleted-assets-are-mark…
…ed-as-live Ensure deleted assets are marked as live
- Loading branch information
Showing
24 changed files
with
469 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
app/services/service_listeners/attachment_asset_deleter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module ServiceListeners | ||
class AttachmentAssetDeleter | ||
def self.call(attachable) | ||
Attachment.includes(:attachment_data).where(attachable: attachable.attachables).find_each do |attachment| | ||
attachment_data = attachment.attachment_data | ||
|
||
next unless attachment_data&.deleted? | ||
|
||
DeleteAttachmentAssetJob.perform_async(attachment_data.id) | ||
end | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
app/services/service_listeners/attachment_asset_publisher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module ServiceListeners | ||
class AttachmentAssetPublisher | ||
def self.call(attachable) | ||
Attachment.includes(:attachment_data).where(attachable: attachable.attachables).find_each do |attachment| | ||
next unless attachment.attachment_data | ||
|
||
PublishAttachmentAssetJob.perform_async(attachment.attachment_data.id) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class DeleteAttachmentAssetJob < WorkerBase | ||
sidekiq_options queue: "asset_manager" | ||
|
||
def perform(attachment_data_id) | ||
attachment_data = AttachmentData.find(attachment_data_id) | ||
|
||
attachment_data.assets.each do |asset| | ||
AssetManager::AssetDeleter.call(asset.asset_manager_id) | ||
rescue AssetManager::ServiceHelper::AssetNotFound | ||
logger.info("Asset #{asset.asset_manager_id} has already been deleted from Asset Manager") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class PublishAttachmentAssetJob < WorkerBase | ||
sidekiq_options queue: "asset_manager" | ||
|
||
def perform(attachment_data_id) | ||
attachment_data = AttachmentData.find(attachment_data_id) | ||
|
||
asset_attributes = { | ||
"draft" => false, | ||
} | ||
|
||
if attachment_data.last_attachable.respond_to?(:public_url) | ||
asset_attributes.merge!({ "parent_document_url" => attachment_data.last_attachable.public_url }) | ||
end | ||
|
||
# We need to delete the asset first, because if we delete it after updating the draft value to false, and the delete request fails, | ||
# the asset will remain live. | ||
attachment_data.assets.each do |asset| | ||
AssetManager::AssetDeleter.call(asset.asset_manager_id) if attachment_data.deleted? | ||
AssetManager::AssetUpdater.call(asset.asset_manager_id, asset_attributes) if attachment_data.needs_publishing? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.