-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[PM-33500] - delete attachments from deleted ciphers #7208
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
base: main
Are you sure you want to change the base?
Changes from all commits
fe0f808
3048893
834a1b9
5dcb0f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -460,6 +460,12 @@ public async Task DeleteManyAsync(IEnumerable<Guid> cipherIds, Guid deletingUser | |
| await _cipherRepository.DeleteAsync(deletingCiphers.Select(c => c.Id), deletingUserId); | ||
| } | ||
|
|
||
| // Clean up attachment files from storage | ||
| foreach (var cipher in deletingCiphers) | ||
| { | ||
| await _attachmentStorageService.DeleteAttachmentsForCipherAsync(cipher.Id); | ||
| } | ||
|
|
||
| var events = deletingCiphers.Select(c => | ||
| new Tuple<Cipher, EventType, DateTime?>(c, EventType.Cipher_Deleted, null)); | ||
| foreach (var eventsBatch in events.Chunk(100)) | ||
|
|
@@ -494,10 +500,26 @@ public async Task PurgeAsync(Guid organizationId) | |
| { | ||
| throw new NotFoundException(); | ||
| } | ||
|
|
||
|
|
||
| await DeleteAttachmentsForOrganizationAsync(organizationId); | ||
|
|
||
| await _cipherRepository.DeleteByOrganizationIdAsync(organizationId); | ||
|
|
||
| await _eventService.LogOrganizationEventAsync(org, EventType.Organization_PurgedVault); | ||
| } | ||
|
|
||
| public async Task DeleteAttachmentsForOrganizationAsync(Guid organizationId) | ||
| { | ||
| var ciphersWithAttachments = (await _cipherRepository.GetManyByOrganizationIdAsync(organizationId)) | ||
| .Where(c => c.GetAttachments()?.Count > 0); | ||
|
Comment on lines
+514
to
+515
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. β @jaasen-livefront, is there a reason we will need the whole cipher object? since we just need the cipher Ids, we can add a |
||
|
|
||
| foreach (var cipher in ciphersWithAttachments) | ||
| { | ||
| await _attachmentStorageService.DeleteAttachmentsForCipherAsync(cipher.Id); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By having 1 spot where we only supply the organization ID to pass, we can get rid of all these for loops! π |
||
| } | ||
| } | ||
|
|
||
| public async Task MoveManyAsync(IEnumerable<Guid> cipherIds, Guid? destinationFolderId, Guid movingUserId) | ||
| { | ||
| if (destinationFolderId.HasValue) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By doing what I suggested above, we can probably also get rid of another for loop here as well