mirror of
https://github.com/bitwarden/server
synced 2025-12-27 13:43:18 +00:00
[PM-25947] Add folders and favorites when sharing a cipher (#6402)
* add folders and favorites when sharing a cipher * refactor folders and favorites assignment to consider existing folders/favorite assignments on a cipher * remove unneeded string manipulation * remove comment * add unit test for folder/favorite sharing * add migration for sharing a cipher to org and collect reprompt, favorite and folders * update date timestamp of migration
This commit is contained in:
@@ -225,4 +225,58 @@ public class CipherRepositoryTests
|
||||
Assert.True(savedCipher == null);
|
||||
}
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfOrganizationCipherCustomize, BitAutoData]
|
||||
public async Task ReplaceAsync_WithCollections_UpdatesFoldersFavoritesRepromptAndArchivedDateAsync(
|
||||
Cipher cipher,
|
||||
User user,
|
||||
Organization org,
|
||||
Collection collection,
|
||||
List<EfVaultRepo.CipherRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
List<EfRepo.CollectionRepository> efCollectionRepos)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var postEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
efOrgRepos[i].ClearChangeTracking();
|
||||
var postEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
efUserRepos[i].ClearChangeTracking();
|
||||
|
||||
collection.OrganizationId = postEfOrg.Id;
|
||||
var postEfCollection = await efCollectionRepos[i].CreateAsync(collection);
|
||||
efCollectionRepos[i].ClearChangeTracking();
|
||||
|
||||
cipher.UserId = postEfUser.Id;
|
||||
cipher.OrganizationId = null;
|
||||
cipher.Folders = $"{{\"{postEfUser.Id}\":\"some-folder-id\"}}";
|
||||
cipher.Favorites = $"{{\"{postEfUser.Id}\":true}}";
|
||||
cipher.Reprompt = Core.Vault.Enums.CipherRepromptType.Password;
|
||||
|
||||
var createdCipher = await sut.CreateAsync(cipher);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var updatedCipher = await sut.GetByIdAsync(createdCipher.Id);
|
||||
updatedCipher.UserId = postEfUser.Id;
|
||||
updatedCipher.OrganizationId = postEfOrg.Id;
|
||||
updatedCipher.Folders = $"{{\"{postEfUser.Id}\":\"new-folder-id\"}}";
|
||||
updatedCipher.Favorites = $"{{\"{postEfUser.Id}\":true}}";
|
||||
updatedCipher.Reprompt = Core.Vault.Enums.CipherRepromptType.Password;
|
||||
|
||||
await sut.ReplaceAsync(updatedCipher, new List<Guid> { postEfCollection.Id });
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
|
||||
var savedCipher = await sut.GetByIdAsync(createdCipher.Id);
|
||||
Assert.NotNull(savedCipher);
|
||||
Assert.Null(savedCipher.UserId);
|
||||
Assert.Equal(postEfOrg.Id, savedCipher.OrganizationId);
|
||||
Assert.Equal($"{{\"{postEfUser.Id}\":\"new-folder-id\"}}", savedCipher.Folders);
|
||||
Assert.Equal($"{{\"{postEfUser.Id}\":true}}", savedCipher.Favorites);
|
||||
Assert.Equal(Core.Vault.Enums.CipherRepromptType.Password, savedCipher.Reprompt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user