-
Notifications
You must be signed in to change notification settings - Fork 9
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
Deleting a parent Whitehall document should delete underlying assets in Asset Manager #469
Comments
This is intended to work in a similar way to the notifier in EditionServiceCoordinator, except that it's used to publish events concerning the Attachment class. My plan is to subscribe an instance of ServiceListeners::AttachmentDraftStatusUpdater to this notifier in order to keep the draft status of attachments associated with policy groups up-to-date in Asset Manager. Note that the visibility of attachments on a policy group is determined simply by the existence of the policy group. This logic is already encapsulated in the AttachmentVisibility class which is used in the ServiceListeners::AttachmentDraftStatusUpdater. I did consider introducing a service for creating attachments, but there doesn't seem to be any precedent for using services in that way and in any case it felt a bit like overkill. I also considered wiring an instance of ServiceListeners::AttachmentDraftStatusUpdater directly into the Admin::AttachmentsController, but that felt at odds with the approach taken elsewhere and would've introduced unnecessary coupling and made testing of the controller harder. Note that there's no need to publish 'update' events as well as 'create' events, because updating an attachment should not have any effect on the draft status of its corresponding asset. We might need to introduce a 'destroy' event at some point, but we're planning to tackle that separately in this issue [1]. [1]: alphagov/asset-manager#469
Further investigation:
I've also verified the above behaviour by deleting an attachment in integration. Since I'm less confident that point 2 applies to non-edition entities. TODO: Investigate this. I think all of this implies that when an attachment is deleted in Whitehall, we should "delete" the asset (and any versions) from Asset Manager. |
There doesn't seem to be any way to un-delete a Whitehall attachment, so I don't think we need to worry about that for now. Especially as Asset Manager already supports restoring of deleted assets if we ever need it. |
So I think we should add an |
When I wrote the above, I had forgotten about the However, I also noticed some inconsistent behaviour when a draft edition is discarded. In this case all its attachments are marked as deleted, but because I've spiked on a fix to remove this inconsistency in this commit. All the commits mentioned in this comment are on this branch. |
Thinking about this a bit more, I think we do need to fix the above inconsistency if we want the behaviour to remain the same when we switch over to serve attachments from Asset Manager. This is because requests for attachments will no longer go via |
Note that I've belatedly realised that this issue is specifically about what happens when you delete an attachments parent document; not what happens when you delete the attachment itself. However, as noted in some of the above comments, we have work to do on this front and hence I've captured this in a new issue: #509. |
I've captured the possible issue about deleting a policy group not deleting its associated attachments in this issue. |
Closing. |
I think this should focus on reproducing existing Whitehall behaviour, rather than adding missing behaviour or fixing bugs. The only exception to this might be to support potential behaviour provided by models which is not currently available via the UI.
Here are some notes about the current situation:
Editions
Admin::EditionsController
has a#destroy
action, although it's not obvious that this is accessible via the UI.EditionDeleter
which has a#fire_transition!
method which, in turn, callsAttachable#delete_all_attachments
which seems to mark the attachments asdeleted
.deleted
flag is actually used to decide whether an attachment should be visible, but surprisingly there doesn't appear to be a default scope onAttachment
.AttachmentData
instance which is what would cause the underlying CarrierWave file to be deleted.PolicyGroups
Admin::PolicyGroupsController
has a#destroy
action, although I haven't checked whether this is accessible via the UI.PolicyGroup
model has no custom attachment-related behaviour other than that added byAttachable
.Attachable
doesn't appear to have any callbacks which would remove attachments or their corresponding attachment datas.(Consultation) Responses
Admin::ResponsesController
has no#destroy
action.Response
nor its subclasses have any significant custom attachment-specific behaviour other than that added byAttachable
.The text was updated successfully, but these errors were encountered: