-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[PM-2682] Fix v0 attachments migration on share cipher with org #3051
[PM-2682] Fix v0 attachments migration on share cipher with org #3051
Conversation
No New Or Fixed Issues Found |
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.
This looks good from my perspective! nice work
Co-authored-by: Matt Gibson <[email protected]>
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.
Thanks for this, @fedemkr. LGTM!
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.
Nice job @fedemkr, LGTM
Objective
Fix v0 attachments migration when sharing cipher with an organization
Code changes
filename
andkey
to the_cipherService.CreateAttachmentShareAsync
method to take care of those values.TempMetadata
property to hold the new metadata values while we do the migration. This allows us to maintain the data safe while the migration is ongoing or any connectivity issues/error happens in between.AttachmentId
given that is JSON ignored and when deserializing we lose the id.CreateShareAttachmentAsync(...)
we pass thefilename
andkey
and instead of replacing those values into the current metadata of the cipher's attachment, we clone the attachment, set the new metadata there and save it into theTempMetadata
of the original one. So the original gets maintained until the end of the migration flow in case something bad happens in between. Furthermore, this approach was chosen so clients don't have to change anything and it's backwards compatible.ShareAsync(...)
, fixed a couple of issues regardingKey
being referenced in the attachments list as theKeyValuePair
instead of the actual attachment metadata. Also, now it handles switching the old metadata for the new metadata correctly by cloning the attachments and updating it so no weird issues happens there or in the possible rollback.ShareAsync(...)
process replacing the metadata and removing the collection id <-> cipher id relationship that happens inside_cipherRepository.ReplaceAsync(cipher, collectionIds)
. There is currently no stored procedure to delete many collection ids for a given cipher so given that this would be an edge case (rollback) of an edge case (v0 migration) I decided to use the_collectionCipherRepository.UpdateCollectionsAsync(...)
which I just give the current collections minus the ones we want to remove and that performs the update. LMK if I should change this and create the new Stored Procedure or some other way (btw there is an SP to delete a collection id of a cipher but I didn't want to use it because it was not done in bulk and I had to iterate for each collection id which IMO is worse from the current approach)Before you submit
dotnet format --verify-no-changes
) (required)