1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

Update revision date upon cipher restore (#243)

* Update revision date upon cipher restore

* Receive and use returned datetimes from restore
This commit is contained in:
Matt Gibson 2021-01-08 08:53:41 -06:00 committed by GitHub
parent afa01f67f4
commit cea09a22e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 21 deletions

View File

@ -206,9 +206,9 @@ export abstract class ApiService {
putDeleteCipherAdmin: (id: string) => Promise<any>;
putDeleteManyCiphers: (request: CipherBulkDeleteRequest) => Promise<any>;
putDeleteManyCiphersAdmin: (request: CipherBulkDeleteRequest) => Promise<any>;
putRestoreCipher: (id: string) => Promise<any>;
putRestoreCipherAdmin: (id: string) => Promise<any>;
putRestoreManyCiphers: (request: CipherBulkRestoreRequest) => Promise<any>;
putRestoreCipher: (id: string) => Promise<CipherResponse>;
putRestoreCipherAdmin: (id: string) => Promise<CipherResponse>;
putRestoreManyCiphers: (request: CipherBulkRestoreRequest) => Promise<ListResponse<CipherResponse>>;
postCipherAttachment: (id: string, data: FormData) => Promise<CipherResponse>;
postCipherAttachmentAdmin: (id: string, data: FormData) => Promise<CipherResponse>;

View File

@ -53,7 +53,7 @@ export abstract class CipherService {
softDelete: (id: string | string[]) => Promise<any>;
softDeleteWithServer: (id: string) => Promise<any>;
softDeleteManyWithServer: (ids: string[]) => Promise<any>;
restore: (id: string | string[]) => Promise<any>;
restore: (cipher: { id: string, revisionDate: string; } | { id: string, revisionDate: string; }[]) => Promise<any>;
restoreWithServer: (id: string) => Promise<any>;
restoreManyWithServer: (ids: string[]) => Promise<any>;
}

View File

@ -556,16 +556,19 @@ export class ApiService implements ApiServiceAbstraction {
return this.send('PUT', '/ciphers/delete-admin', request, true, false);
}
putRestoreCipher(id: string): Promise<any> {
return this.send('PUT', '/ciphers/' + id + '/restore', null, true, false);
async putRestoreCipher(id: string): Promise<CipherResponse> {
const r = await this.send('PUT', '/ciphers/' + id + '/restore', null, true, true);
return new CipherResponse(r);
}
putRestoreCipherAdmin(id: string): Promise<any> {
return this.send('PUT', '/ciphers/' + id + '/restore-admin', null, true, false);
async putRestoreCipherAdmin(id: string): Promise<CipherResponse> {
const r = await this.send('PUT', '/ciphers/' + id + '/restore-admin', null, true, true);
return new CipherResponse(r);
}
putRestoreManyCiphers(request: CipherBulkDeleteRequest): Promise<any> {
return this.send('PUT', '/ciphers/restore', request, true, false);
async putRestoreManyCiphers(request: CipherBulkDeleteRequest): Promise<ListResponse<CipherResponse>> {
const r = await this.send('PUT', '/ciphers/restore', request, true, true);
return new ListResponse<CipherResponse>(r, CipherResponse);
}
// Attachments APIs

View File

@ -876,7 +876,7 @@ export class CipherService implements CipherServiceAbstraction {
await this.softDelete(ids);
}
async restore(id: string | string[]): Promise<any> {
async restore(cipher: { id: string, revisionDate: string; } | { id: string, revisionDate: string; }[]) {
const userId = await this.userService.getUserId();
const ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
Keys.ciphersPrefix + userId);
@ -884,17 +884,19 @@ export class CipherService implements CipherServiceAbstraction {
return;
}
const clearDeletedDate = (cipherId: string) => {
if (ciphers[cipherId] == null) {
const clearDeletedDate = (c: { id: string, revisionDate: string; }) => {
if (ciphers[c.id] == null) {
return;
}
ciphers[cipherId].deletedDate = null;
ciphers[c.id].deletedDate = null;
ciphers[c.id].revisionDate = c.revisionDate;
};
if (typeof id === 'string') {
clearDeletedDate(id);
if (cipher.constructor.name === 'Array') {
(cipher as { id: string, revisionDate: string; }[]).forEach(clearDeletedDate);
} else {
(id as string[]).forEach(clearDeletedDate);
clearDeletedDate(cipher as { id: string, revisionDate: string; });
}
await this.storageService.save(Keys.ciphersPrefix + userId, ciphers);
@ -902,13 +904,17 @@ export class CipherService implements CipherServiceAbstraction {
}
async restoreWithServer(id: string): Promise<any> {
await this.apiService.putRestoreCipher(id);
await this.restore(id);
const response = await this.apiService.putRestoreCipher(id);
await this.restore({ id: id, revisionDate: response.revisionDate });
}
async restoreManyWithServer(ids: string[]): Promise<any> {
await this.apiService.putRestoreManyCiphers(new CipherBulkRestoreRequest(ids));
await this.restore(ids);
const response = await this.apiService.putRestoreManyCiphers(new CipherBulkRestoreRequest(ids));
const restores: { id: string, revisionDate: string; }[] = [];
for (const cipher of response.data) {
restores.push({ id: cipher.id, revisionDate: cipher.revisionDate });
}
await this.restore(restores);
}
// Helpers