Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete assets in Asset Manager when attachments are deleted #3853

Merged

Conversation

floehopper
Copy link
Contributor

This wires up an instance of ServiceListeners::AttachmentDeleter so that the Asset Manager assets corresponding to an AttachmentData are deleted via a Sidekiq worker.

This will mark the relevant assets as deleted in Asset Manager. While there is functionality in the Asset Manager API to restore a deleted asset, there doesn't appear to be any such functionality in Whitehall.

Note that the Asset Manager assets will only be deleted if no other non-deleted Attachment instances are still referencing the AttachmentData, i.e. where AttachmentData#deleted? is true.

Also note that it looks as if when a (consultation) Response or a PolicyGroup is destroyed, the associated attachments are not destroyed. While it's not obvious that it's possible to delete a Response via the user interface, it does appear to be possible to delete a PolicyGroup.

While it doesn't feel appropriate to address this here, I'd recommend that for consistency and completeness, both of these problems should be fixed by calling Attachable#delete_all_attachments from a before/after destroy callback on Response and PolicyGroup. This would mean a 'destroy' event would be published to the attachment notifier for each attachment and the relevant assets would be deleted in Asset Manager.

I want to delete the Asset Manager assets corresponding to Whitehall
attachments when they are deleted. This is a first step towards making
this possible.

I chose to use the attachment notifier rather than the attachment data
notifier, because the deleted state that is definitely changing is on
the Attachment - the deleted state of the AttachmentData may or may not
be changing, depending on the state of other Attachments which reference
it.
I'm planning to wire this up to delete assets in Asset Manager for
Whitehall attachments which are deleted.

Given the ID of an AttachmentData which is considered as deleted, this
worker will look up the AttachmentData and mark the corresponding Asset
Manager asset as deleted, as well as the asset corresponding to the
attachment's thumbnail image if appropriate.
I'm planning to wire this up to delete assets in Asset Manager for
Whitehall attachments which are deleted.

We've discussed inlining all the attachment-related service listener
classes, but I'm going to leave that for now to keep the code more
consistent.
This wires up an instance of ServiceListeners::AttachmentDeleter so that
the Asset Manager assets corresponding to an AttachmentData are deleted
via a Sidekiq worker.

This will mark the relevant assets as deleted in Asset Manager. While
there is functionality in the Asset Manager API to restore a deleted
asset, there doesn't appear to be any such functionality in Whitehall.

Note that the Asset Manager assets will only be deleted if no other
non-deleted Attachment instances are still referencing the
AttachmentData, i.e. where AttachmentData#deleted? is `true`.

Also note that it looks as if when a (consultation) Response or a
PolicyGroup is destroyed, the associated attachments are not deleted.
While it's not obvious that it's possible to delete a Response via the
user interface, it does appear to be possible to delete a PolicyGroup.

While it doesn't feel appropriate to address this here, I'd recommend
that for consistency and completeness, both of these problems should be
fixed by calling Attachable#delete_all_attachments from a before/after
destroy callback on Response and PolicyGroup. This would mean a
'destroy' event would be published to the attachment notifier for each
attachment and the relevant assets would be deleted in Asset Manager.
@floehopper floehopper requested review from chrisroos and chrislo March 13, 2018 13:54
@floehopper floehopper changed the title Delete assets in asset manager when attachments are deleted Delete assets in Asset Manager when attachments are deleted Mar 13, 2018
@chrislo chrislo self-assigned this Mar 13, 2018
Copy link
Contributor

@chrislo chrislo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me - good work!

Also note that it looks as if when a (consultation) Response or a PolicyGroup is destroyed, the associated attachments are not deleted. While it's not obvious that it's possible to delete a Response via the user interface, it does appear to be possible to delete a PolicyGroup.

Perhaps we should add an issue against Whitehall for this?

@floehopper
Copy link
Contributor Author

@chrislo:

Thanks for reviewing.

Perhaps we should add an issue against Whitehall for this?

I think it would be good to capture it somewhere, but I'm not sure the repo issues are monitored by the GOV.UK team. I'll investigate and try to capture the issue somewhere, but in the meantime I'm going to merge this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants