mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
[EC-320] Add organization vault export to event logs (#3136)
* Added organizationId to EventData and EventRequest * Added EventType Organization_ClientExportedVault * Sending organizationId on Organization Export event * Checking that the user belongs to the organization * Added organizationExportResponse model * Added API method to get Organization vault export data * Updated getOrganizationDecryptedExport to use new API method
This commit is contained in:
@@ -139,6 +139,7 @@ import {
|
||||
OrganizationConnectionConfigApis,
|
||||
OrganizationConnectionResponse,
|
||||
} from "../models/response/organizationConnectionResponse";
|
||||
import { OrganizationExportResponse } from "../models/response/organizationExportResponse";
|
||||
import { OrganizationKeysResponse } from "../models/response/organizationKeysResponse";
|
||||
import { OrganizationResponse } from "../models/response/organizationResponse";
|
||||
import { OrganizationSponsorshipSyncStatusResponse } from "../models/response/organizationSponsorshipSyncStatusResponse";
|
||||
@@ -2323,6 +2324,17 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
}
|
||||
}
|
||||
|
||||
async getOrganizationExport(organizationId: string): Promise<OrganizationExportResponse> {
|
||||
const r = await this.send(
|
||||
"GET",
|
||||
"/organizations/" + organizationId + "/export",
|
||||
null,
|
||||
true,
|
||||
true
|
||||
);
|
||||
return new OrganizationExportResponse(r);
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
async getActiveBearerToken(): Promise<string> {
|
||||
|
||||
@@ -34,7 +34,8 @@ export class EventService implements EventServiceAbstraction {
|
||||
async collect(
|
||||
eventType: EventType,
|
||||
cipherId: string = null,
|
||||
uploadImmediately = false
|
||||
uploadImmediately = false,
|
||||
organizationId: string = null
|
||||
): Promise<any> {
|
||||
const authed = await this.stateService.getIsAuthenticated();
|
||||
if (!authed) {
|
||||
@@ -54,6 +55,11 @@ export class EventService implements EventServiceAbstraction {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (organizationId != null) {
|
||||
if (!orgIds.has(organizationId)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
let eventCollection = await this.stateService.getEventCollection();
|
||||
if (eventCollection == null) {
|
||||
eventCollection = [];
|
||||
@@ -62,6 +68,7 @@ export class EventService implements EventServiceAbstraction {
|
||||
event.type = eventType;
|
||||
event.cipherId = cipherId;
|
||||
event.date = new Date().toISOString();
|
||||
event.organizationId = organizationId;
|
||||
eventCollection.push(event);
|
||||
await this.stateService.setEventCollection(eventCollection);
|
||||
if (uploadImmediately) {
|
||||
@@ -83,6 +90,7 @@ export class EventService implements EventServiceAbstraction {
|
||||
req.type = e.type;
|
||||
req.cipherId = e.cipherId;
|
||||
req.date = e.date;
|
||||
req.organizationId = e.organizationId;
|
||||
return req;
|
||||
});
|
||||
try {
|
||||
|
||||
@@ -245,38 +245,41 @@ export class ExportService implements ExportServiceAbstraction {
|
||||
const promises = [];
|
||||
|
||||
promises.push(
|
||||
this.apiService.getCollections(organizationId).then((collections) => {
|
||||
const collectionPromises: any = [];
|
||||
if (collections != null && collections.data != null && collections.data.length > 0) {
|
||||
collections.data.forEach((c) => {
|
||||
const collection = new Collection(new CollectionData(c as CollectionDetailsResponse));
|
||||
collectionPromises.push(
|
||||
collection.decrypt().then((decCol) => {
|
||||
decCollections.push(decCol);
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
return Promise.all(collectionPromises);
|
||||
})
|
||||
);
|
||||
|
||||
promises.push(
|
||||
this.apiService.getCiphersOrganization(organizationId).then((ciphers) => {
|
||||
const cipherPromises: any = [];
|
||||
if (ciphers != null && ciphers.data != null && ciphers.data.length > 0) {
|
||||
ciphers.data
|
||||
.filter((c) => c.deletedDate === null)
|
||||
.forEach((c) => {
|
||||
const cipher = new Cipher(new CipherData(c));
|
||||
cipherPromises.push(
|
||||
cipher.decrypt().then((decCipher) => {
|
||||
decCiphers.push(decCipher);
|
||||
this.apiService.getOrganizationExport(organizationId).then((exportData) => {
|
||||
const exportPromises: any = [];
|
||||
if (exportData != null) {
|
||||
if (
|
||||
exportData.collections != null &&
|
||||
exportData.collections.data != null &&
|
||||
exportData.collections.data.length > 0
|
||||
) {
|
||||
exportData.collections.data.forEach((c) => {
|
||||
const collection = new Collection(new CollectionData(c as CollectionDetailsResponse));
|
||||
exportPromises.push(
|
||||
collection.decrypt().then((decCol) => {
|
||||
decCollections.push(decCol);
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
if (
|
||||
exportData.ciphers != null &&
|
||||
exportData.ciphers.data != null &&
|
||||
exportData.ciphers.data.length > 0
|
||||
) {
|
||||
exportData.ciphers.data
|
||||
.filter((c) => c.deletedDate === null)
|
||||
.forEach((c) => {
|
||||
const cipher = new Cipher(new CipherData(c));
|
||||
exportPromises.push(
|
||||
cipher.decrypt().then((decCipher) => {
|
||||
decCiphers.push(decCipher);
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
return Promise.all(cipherPromises);
|
||||
return Promise.all(exportPromises);
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user