1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-30 13:03:53 +01:00

Export Organization events (#375)

* Export Organization events

* Lint fixes
This commit is contained in:
Matt Gibson 2021-05-13 13:43:54 -05:00 committed by GitHub
parent 306aef73d4
commit 92dbf24ab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 0 deletions

View File

@ -1,5 +1,8 @@
import { EventView } from '../models/view/eventView';
export abstract class ExportService { export abstract class ExportService {
getExport: (format?: 'csv' | 'json' | 'encrypted_json') => Promise<string>; getExport: (format?: 'csv' | 'json' | 'encrypted_json') => Promise<string>;
getOrganizationExport: (organizationId: string, format?: 'csv' | 'json' | 'encrypted_json') => Promise<string>; getOrganizationExport: (organizationId: string, format?: 'csv' | 'json' | 'encrypted_json') => Promise<string>;
getEventExport: (events: EventView[]) => Promise<string>;
getFileName: (prefix?: string, extension?: string) => string; getFileName: (prefix?: string, extension?: string) => string;
} }

View File

@ -0,0 +1,26 @@
import { EventType } from '../../enums/eventType';
import { EventView } from '../view/eventView';
export class Event {
message: string;
appIcon: string;
appName: string;
userId: string;
userName: string;
userEmail: string;
date: string;
ip: string;
type: string;
constructor(event: EventView) {
this.message = event.humanReadableMessage;
this.appIcon = event.appIcon;
this.appName = event.appName;
this.userId = event.userId;
this.userName = event.userName;
this.userEmail = event.userEmail;
this.date = event.date;
this.ip = event.ip;
this.type = EventType[event.type];
}
}

View File

@ -0,0 +1,27 @@
import { EventType } from '../../enums/eventType';
export class EventView {
message: string;
humanReadableMessage: string;
appIcon: string;
appName: string;
userId: string;
userName: string;
userEmail: string;
date: string;
ip: string;
type: EventType;
constructor(data: Required<EventView>) {
this.message = data.message;
this.humanReadableMessage = data.humanReadableMessage;
this.appIcon = data.appIcon;
this.appName = data.appName;
this.userId = data.userId;
this.userName = data.userName;
this.userEmail = data.userEmail;
this.date = data.date;
this.ip = data.ip;
this.type = data.type;
}
}

View File

@ -22,7 +22,9 @@ import { CollectionDetailsResponse } from '../models/response/collectionResponse
import { CipherWithIds as CipherExport } from '../models/export/cipherWithIds'; import { CipherWithIds as CipherExport } from '../models/export/cipherWithIds';
import { CollectionWithId as CollectionExport } from '../models/export/collectionWithId'; import { CollectionWithId as CollectionExport } from '../models/export/collectionWithId';
import { Event } from '../models/export/event';
import { FolderWithId as FolderExport } from '../models/export/folderWithId'; import { FolderWithId as FolderExport } from '../models/export/folderWithId';
import { EventView } from '../models/view/eventView';
import { Utils } from '../misc/utils'; import { Utils } from '../misc/utils';
@ -47,6 +49,10 @@ export class ExportService implements ExportServiceAbstraction {
} }
} }
async getEventExport(events: EventView[]): Promise<string> {
return papa.unparse(events.map(e => new Event(e)));
}
getFileName(prefix: string = null, extension: string = 'csv'): string { getFileName(prefix: string = null, extension: string = 'csv'): string {
const now = new Date(); const now = new Date();
const dateString = const dateString =