Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/Api/Tools/Controllers/OrganizationExportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,22 @@ public async Task<IActionResult> Export(Guid organizationId)
{
var canExportAll = await _authorizationService.AuthorizeAsync(User, new OrganizationScope(organizationId),
VaultExportOperations.ExportWholeVault);
var canExportManaged = await _authorizationService.AuthorizeAsync(User, new OrganizationScope(organizationId),
VaultExportOperations.ExportManagedCollections);

if (canExportAll.Succeeded)
{
var allOrganizationCiphers =
await _organizationCiphersQuery.GetAllOrganizationCiphersExcludingDefaultUserCollections(
organizationId);

var allCollections = await _collectionRepository
.GetManySharedCollectionsByOrganizationIdAsync(
organizationId);

var ciphersTask = _organizationCiphersQuery
.GetAllOrganizationCiphersExcludingDefaultUserCollections(organizationId);
var collectionsTask = _collectionRepository
.GetManySharedCollectionsByOrganizationIdAsync(organizationId);
await Task.WhenAll(ciphersTask, collectionsTask);

return Ok(new OrganizationExportResponseModel(allOrganizationCiphers, allCollections,
return Ok(new OrganizationExportResponseModel(ciphersTask.Result, collectionsTask.Result,
_globalSettings));
}

var canExportManaged = await _authorizationService.AuthorizeAsync(User, new OrganizationScope(organizationId),
VaultExportOperations.ExportManagedCollections);

if (canExportManaged.Succeeded)
{
var userId = _userService.GetProperUserId(User)!.Value;
Expand Down
4 changes: 3 additions & 1 deletion src/Core/Tools/ImportFeatures/ImportCiphersCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ public async Task ImportIntoOrganizationalVaultAsync(
}
}

var organizationCollectionsIds = (await _collectionRepository.GetManyByOrganizationIdAsync(org.Id)).Select(c => c.Id).ToList();
var organizationCollectionsIds = (await _collectionRepository.GetManyByOrganizationIdAsync(org.Id))
.Select(c => c.Id)
.ToHashSet();

//Assign id to the ones that don't exist in DB
//Need to keep the list order to create the relationships
Expand Down
9 changes: 5 additions & 4 deletions src/Core/Vault/Queries/OrganizationCiphersQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ public async Task<IEnumerable<CipherDetailsWithCollections>> GetOrganizationCiph
/// <param name="organizationId"></param>
public async Task<IEnumerable<CipherOrganizationDetailsWithCollections>> GetAllOrganizationCiphers(Guid organizationId)
{
var orgCiphers = await _cipherRepository.GetManyOrganizationDetailsByOrganizationIdAsync(organizationId);
var collectionCiphers = await _collectionCipherRepository.GetManyByOrganizationIdAsync(organizationId);
var collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);
var orgCiphersTask = _cipherRepository.GetManyOrganizationDetailsByOrganizationIdAsync(organizationId);
var collectionCiphersTask = _collectionCipherRepository.GetManyByOrganizationIdAsync(organizationId);
await Task.WhenAll(orgCiphersTask, collectionCiphersTask);

return orgCiphers.Select(c => new CipherOrganizationDetailsWithCollections(c, collectionCiphersGroupDict));
var collectionCiphersGroupDict = collectionCiphersTask.Result.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);
return orgCiphersTask.Result.Select(c => new CipherOrganizationDetailsWithCollections(c, collectionCiphersGroupDict));
}

/// <summary>
Expand Down
Loading