mirror of
https://github.com/bitwarden/server
synced 2025-12-10 05:13:48 +00:00
PM-27248 [Defect] An unhandled error is returned when a MSP tries to import data (#6563)
* Revert previous commits and implement logic to avoid null references: • reverted previous commits and force pushed to remove inconsistent formatting • implemented logic to avoid null reference access (with comments) * fix typo in comment * fix logical error and add test coverage * extracted logic common to all code paths per review comment
This commit is contained in:
@@ -150,17 +150,34 @@ public class ImportCiphersCommand : IImportCiphersCommand
|
||||
|
||||
foreach (var collection in collections)
|
||||
{
|
||||
if (!organizationCollectionsIds.Contains(collection.Id))
|
||||
// If the collection already exists, skip it
|
||||
if (organizationCollectionsIds.Contains(collection.Id))
|
||||
{
|
||||
collection.SetNewId();
|
||||
newCollections.Add(collection);
|
||||
newCollectionUsers.Add(new CollectionUser
|
||||
{
|
||||
CollectionId = collection.Id,
|
||||
OrganizationUserId = importingOrgUser.Id,
|
||||
Manage = true
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create new collections if not already present
|
||||
collection.SetNewId();
|
||||
newCollections.Add(collection);
|
||||
|
||||
/*
|
||||
* If the organization was created by a Provider, the organization may have zero members (users)
|
||||
* In this situation importingOrgUser will be null, and accessing importingOrgUser.Id will
|
||||
* result in a null reference exception.
|
||||
*
|
||||
* Avoid user assignment, but proceed with adding the collection.
|
||||
*/
|
||||
if (importingOrgUser == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
newCollectionUsers.Add(new CollectionUser
|
||||
{
|
||||
CollectionId = collection.Id,
|
||||
OrganizationUserId = importingOrgUser.Id,
|
||||
Manage = true
|
||||
});
|
||||
}
|
||||
|
||||
// Create associations based on the newly assigned ids
|
||||
|
||||
Reference in New Issue
Block a user