mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 09:32:48 -05:00
[PS-2390] Updating and adding items into folder and collection on import (#2717)
* PS-2390 Adding Id to the Collection/Folder RequestModel replacing folder/collection when they already exist instead of creating a new one Adding items to existing collections if the id matches * PS-2390 Improved Folder/Collection RequestModel code design * PS-2390 Removed whitespaces from FolderRequestModel * PS-2390 Verifying if folder/collection belongs to user/organization when updating or creating a new one * PS-2390 - Removed unnecessary null validation for Id on Folder/CollectionRequestModel * PS-2390 - Added bulk methods to get and update folders at import * PS-2390 - Added bulk methods to get and update collections at import org * PS-2390 - Corrected sqlproj path to Folder_ReadByIdsAndUserId * PS-2390 - Improved code readibility * PS-2390 - Added newlines to EOF * PS-2390 Remove logic to update folders/collections at import * PS-2390 - removed unnecessary methods and imports * PS-2390 - Removed unnecessary formatting change * PS-2390 - Removed unused variable
This commit is contained in:
@ -648,10 +648,18 @@ public class CipherService : ICipherService
|
||||
}
|
||||
}
|
||||
|
||||
// Init. ids for folders
|
||||
var userfoldersIds = (await _folderRepository.GetManyByUserIdAsync(userId ?? Guid.Empty)).Select(f => f.Id).ToList();
|
||||
|
||||
//Assign id to the ones that don't exist in DB
|
||||
//Need to keep the list order to create the relationships
|
||||
List<Folder> newFolders = new List<Folder>();
|
||||
foreach (var folder in folders)
|
||||
{
|
||||
folder.SetNewId();
|
||||
if (!userfoldersIds.Contains(folder.Id))
|
||||
{
|
||||
folder.SetNewId();
|
||||
newFolders.Add(folder);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the folder associations based on the newly created folder ids
|
||||
@ -670,7 +678,7 @@ public class CipherService : ICipherService
|
||||
}
|
||||
|
||||
// Create it all
|
||||
await _cipherRepository.CreateAsync(ciphers, folders);
|
||||
await _cipherRepository.CreateAsync(ciphers, newFolders);
|
||||
|
||||
// push
|
||||
if (userId.HasValue)
|
||||
@ -705,10 +713,19 @@ public class CipherService : ICipherService
|
||||
cipher.SetNewId();
|
||||
}
|
||||
|
||||
// Init. ids for collections
|
||||
var userCollectionsIds = (await _collectionRepository.GetManyByOrganizationIdAsync(org.Id)).Select(c => c.Id).ToList();
|
||||
|
||||
//Assign id to the ones that don't exist in DB
|
||||
//Need to keep the list order to create the relationships
|
||||
List<Collection> newCollections = new List<Collection>();
|
||||
|
||||
foreach (var collection in collections)
|
||||
{
|
||||
collection.SetNewId();
|
||||
if (!userCollectionsIds.Contains(collection.Id))
|
||||
{
|
||||
collection.SetNewId();
|
||||
newCollections.Add(collection);
|
||||
}
|
||||
}
|
||||
|
||||
// Create associations based on the newly assigned ids
|
||||
@ -731,7 +748,7 @@ public class CipherService : ICipherService
|
||||
}
|
||||
|
||||
// Create it all
|
||||
await _cipherRepository.CreateAsync(ciphers, collections, collectionCiphers);
|
||||
await _cipherRepository.CreateAsync(ciphers, newCollections, collectionCiphers);
|
||||
|
||||
// push
|
||||
await _pushService.PushSyncVaultAsync(importingUserId);
|
||||
|
Reference in New Issue
Block a user