mirror of
https://github.com/bitwarden/browser
synced 2026-02-18 02:19:18 +00:00
Use new vault-export-api.service instead of the ApiService to retrieve organizational export data
This commit is contained in:
@@ -179,6 +179,7 @@ import { SerializedMemoryStorageService } from "@bitwarden/storage-core";
|
||||
import {
|
||||
IndividualVaultExportService,
|
||||
IndividualVaultExportServiceAbstraction,
|
||||
VaultExportApiService,
|
||||
OrganizationVaultExportService,
|
||||
OrganizationVaultExportServiceAbstraction,
|
||||
VaultExportService,
|
||||
@@ -241,6 +242,7 @@ export class ServiceContainer {
|
||||
importService: ImportServiceAbstraction;
|
||||
importApiService: ImportApiServiceAbstraction;
|
||||
exportService: VaultExportServiceAbstraction;
|
||||
vaultExportApiService: VaultExportApiService;
|
||||
individualExportService: IndividualVaultExportServiceAbstraction;
|
||||
organizationExportService: OrganizationVaultExportServiceAbstraction;
|
||||
searchService: SearchService;
|
||||
@@ -844,9 +846,11 @@ export class ServiceContainer {
|
||||
this.restrictedItemTypesService,
|
||||
);
|
||||
|
||||
this.vaultExportApiService = new VaultExportApiService(this.apiService);
|
||||
|
||||
this.organizationExportService = new OrganizationVaultExportService(
|
||||
this.cipherService,
|
||||
this.apiService,
|
||||
this.vaultExportApiService,
|
||||
this.pinService,
|
||||
this.keyService,
|
||||
this.encryptService,
|
||||
|
||||
@@ -342,6 +342,8 @@ import { PasswordRepromptService } from "@bitwarden/vault";
|
||||
import {
|
||||
IndividualVaultExportService,
|
||||
IndividualVaultExportServiceAbstraction,
|
||||
VaultExportApiService,
|
||||
VaultExportApiServiceAbstraction,
|
||||
OrganizationVaultExportService,
|
||||
OrganizationVaultExportServiceAbstraction,
|
||||
VaultExportService,
|
||||
@@ -886,12 +888,17 @@ const safeProviders: SafeProvider[] = [
|
||||
RestrictedItemTypesService,
|
||||
],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: VaultExportApiServiceAbstraction,
|
||||
useClass: VaultExportApiService,
|
||||
deps: [ApiServiceAbstraction],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: OrganizationVaultExportServiceAbstraction,
|
||||
useClass: OrganizationVaultExportService,
|
||||
deps: [
|
||||
CipherServiceAbstraction,
|
||||
ApiServiceAbstraction,
|
||||
VaultExportApiServiceAbstraction,
|
||||
PinServiceAbstraction,
|
||||
KeyService,
|
||||
EncryptService,
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
CollectionDetailsResponse,
|
||||
CollectionView,
|
||||
} from "@bitwarden/admin-console/common";
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
||||
import { CryptoFunctionService } from "@bitwarden/common/key-management/crypto/abstractions/crypto-function.service";
|
||||
@@ -34,6 +33,7 @@ import {
|
||||
ExportedVaultAsString,
|
||||
} from "../types";
|
||||
|
||||
import { VaultExportApiServiceAbstraction } from "./api/vault-export-api.service.abstraction";
|
||||
import { BaseVaultExportService } from "./base-vault-export.service";
|
||||
import { ExportHelper } from "./export-helper";
|
||||
import { OrganizationVaultExportServiceAbstraction } from "./org-vault-export.service.abstraction";
|
||||
@@ -45,7 +45,7 @@ export class OrganizationVaultExportService
|
||||
{
|
||||
constructor(
|
||||
private cipherService: CipherService,
|
||||
private apiService: ApiService,
|
||||
private vaultExportApiService: VaultExportApiServiceAbstraction,
|
||||
pinService: PinServiceAbstraction,
|
||||
private keyService: KeyService,
|
||||
encryptService: EncryptService,
|
||||
@@ -138,7 +138,7 @@ export class OrganizationVaultExportService
|
||||
const restrictions = await firstValueFrom(this.restrictedItemTypesService.restricted$);
|
||||
|
||||
promises.push(
|
||||
this.apiService.getOrganizationExport(organizationId).then((exportData) => {
|
||||
this.vaultExportApiService.getOrganizationExport(organizationId as OrganizationId).then((exportData) => {
|
||||
const exportPromises: any = [];
|
||||
if (exportData != null) {
|
||||
if (exportData.collections != null && exportData.collections.length > 0) {
|
||||
@@ -188,39 +188,35 @@ export class OrganizationVaultExportService
|
||||
|
||||
private async getOrganizationEncryptedExport(organizationId: string): Promise<string> {
|
||||
const collections: Collection[] = [];
|
||||
let ciphers: Cipher[] = [];
|
||||
const promises = [];
|
||||
|
||||
promises.push(
|
||||
this.apiService.getCollections(organizationId).then((c) => {
|
||||
if (c != null && c.data != null && c.data.length > 0) {
|
||||
c.data.forEach((r) => {
|
||||
const collection = Collection.fromCollectionData(
|
||||
new CollectionData(r as CollectionDetailsResponse),
|
||||
);
|
||||
collections.push(collection);
|
||||
});
|
||||
}
|
||||
}),
|
||||
);
|
||||
const ciphers: Cipher[] = [];
|
||||
|
||||
const restrictions = await firstValueFrom(this.restrictedItemTypesService.restricted$);
|
||||
|
||||
promises.push(
|
||||
this.apiService.getCiphersOrganization(organizationId).then((c) => {
|
||||
if (c != null && c.data != null && c.data.length > 0) {
|
||||
ciphers = c.data
|
||||
.filter((item) => item.deletedDate === null)
|
||||
.map((item) => new Cipher(new CipherData(item)))
|
||||
.filter(
|
||||
(cipher) => !this.restrictedItemTypesService.isCipherRestricted(cipher, restrictions),
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
const exportData = await this.vaultExportApiService.getOrganizationExport(organizationId as OrganizationId);
|
||||
|
||||
await Promise.all(promises);
|
||||
if (exportData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (exportData.collections != null && exportData.collections.length > 0) {
|
||||
exportData.collections.forEach((c) => {
|
||||
const collection = Collection.fromCollectionData(
|
||||
new CollectionData(c as CollectionDetailsResponse),
|
||||
);
|
||||
collections.push(collection);
|
||||
});
|
||||
}
|
||||
|
||||
if (exportData.ciphers != null && exportData.ciphers.length > 0) {
|
||||
exportData.ciphers
|
||||
.filter((c) => c.deletedDate === null)
|
||||
.forEach((c) => {
|
||||
const cipher = new Cipher(new CipherData(c));
|
||||
if (!this.restrictedItemTypesService.isCipherRestricted(cipher, restrictions)) {
|
||||
ciphers.push(cipher);
|
||||
}
|
||||
});
|
||||
}
|
||||
return this.BuildEncryptedExport(organizationId, collections, ciphers);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user