From 52294864aae5e74eb3325e01def8bbd53a4731fe Mon Sep 17 00:00:00 2001 From: Nick Krantz Date: Tue, 30 Sep 2025 15:58:46 -0500 Subject: [PATCH] add folders and favorites when sharing a cipher --- src/Api/Vault/Controllers/CiphersController.cs | 2 +- src/Api/Vault/Models/Request/CipherRequestModel.cs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Api/Vault/Controllers/CiphersController.cs b/src/Api/Vault/Controllers/CiphersController.cs index 06c88ad9bb..7872ab5ea4 100644 --- a/src/Api/Vault/Controllers/CiphersController.cs +++ b/src/Api/Vault/Controllers/CiphersController.cs @@ -757,7 +757,7 @@ public class CiphersController : Controller ValidateClientVersionForFido2CredentialSupport(cipher); var original = cipher.Clone(); - await _cipherService.ShareAsync(original, model.Cipher.ToCipher(cipher), new Guid(model.Cipher.OrganizationId), + await _cipherService.ShareAsync(original, model.Cipher.ToCipher(cipher, user.Id), new Guid(model.Cipher.OrganizationId), model.CollectionIds.Select(c => new Guid(c)), user.Id, model.Cipher.LastKnownRevisionDate); var sharedCipher = await GetByIdAsync(id, user.Id); diff --git a/src/Api/Vault/Models/Request/CipherRequestModel.cs b/src/Api/Vault/Models/Request/CipherRequestModel.cs index b0589a62f9..cfe0a7c99d 100644 --- a/src/Api/Vault/Models/Request/CipherRequestModel.cs +++ b/src/Api/Vault/Models/Request/CipherRequestModel.cs @@ -84,7 +84,7 @@ public class CipherRequestModel return existingCipher; } - public Cipher ToCipher(Cipher existingCipher) + public Cipher ToCipher(Cipher existingCipher, Guid? userId = null) { // If Data field is provided, use it directly if (!string.IsNullOrWhiteSpace(Data)) @@ -124,9 +124,16 @@ public class CipherRequestModel } } + var userIdKey = userId.HasValue ? $"\"{userId.ToString().ToUpperInvariant()}\"" : null; existingCipher.Reprompt = Reprompt; existingCipher.Key = Key; existingCipher.ArchivedDate = ArchivedDate; + existingCipher.Folders = userIdKey != null && FolderId != null ? + $"{{{userIdKey}:\"{FolderId.ToUpperInvariant()}\"}}" : + null; + existingCipher.Favorites = userIdKey != null && Favorite ? + $"{{{userIdKey}:true}}" : + null; var hasAttachments2 = (Attachments2?.Count ?? 0) > 0; var hasAttachments = (Attachments?.Count ?? 0) > 0;