mirror of
https://github.com/bitwarden/browser
synced 2025-12-28 22:23:28 +00:00
[Soft Delete] jslib updates for new API updates
New API methods and cipher Deleted Date property, plus search expansion to toggle on deleted flag.
This commit is contained in:
@@ -434,6 +434,30 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
return this.send('POST', '/ciphers/import-organization?organizationId=' + organizationId, request, true, false);
|
||||
}
|
||||
|
||||
putDeleteCipher(id: string): Promise<any> {
|
||||
return this.send('PUT', '/ciphers/' + id + '/delete', null, true, false);
|
||||
}
|
||||
|
||||
putDeleteCipherAdmin(id: string): Promise<any> {
|
||||
return this.send('PUT', '/ciphers/' + id + '/delete-admin', null, true, false);
|
||||
}
|
||||
|
||||
putDeleteManyCiphers(request: CipherBulkDeleteRequest): Promise<any> {
|
||||
return this.send('PUT', '/ciphers/delete', request, true, false);
|
||||
}
|
||||
|
||||
putRestoreCipher(id: string): Promise<any> {
|
||||
return this.send('PUT', '/ciphers/' + id + '/restore', null, true, false);
|
||||
}
|
||||
|
||||
putRestoreCipherAdmin(id: string): Promise<any> {
|
||||
return this.send('PUT', '/ciphers/' + id + '/restore-admin', null, true, false);
|
||||
}
|
||||
|
||||
putRestoreManyCiphers(request: CipherBulkDeleteRequest): Promise<any> {
|
||||
return this.send('PUT', '/ciphers/restore', request, true, false);
|
||||
}
|
||||
|
||||
// Attachments APIs
|
||||
|
||||
async postCipherAttachment(id: string, data: FormData): Promise<CipherResponse> {
|
||||
|
||||
@@ -19,6 +19,7 @@ import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey';
|
||||
|
||||
import { CipherBulkDeleteRequest } from '../models/request/cipherBulkDeleteRequest';
|
||||
import { CipherBulkMoveRequest } from '../models/request/cipherBulkMoveRequest';
|
||||
import { CipherBulkRestoreRequest } from '../models/request/cipherBulkRestoreRequest';
|
||||
import { CipherBulkShareRequest } from '../models/request/cipherBulkShareRequest';
|
||||
import { CipherCollectionsRequest } from '../models/request/cipherCollectionsRequest';
|
||||
import { CipherCreateRequest } from '../models/request/cipherCreateRequest';
|
||||
@@ -790,6 +791,76 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
};
|
||||
}
|
||||
|
||||
async softDelete(id: string | string[]): Promise<any> {
|
||||
const userId = await this.userService.getUserId();
|
||||
const ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
|
||||
Keys.ciphersPrefix + userId);
|
||||
if (ciphers == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const setDeletedDate = (cipherId: string) => {
|
||||
if (ciphers[cipherId] == null) {
|
||||
return;
|
||||
}
|
||||
ciphers[cipherId].deletedDate = new Date().toISOString();
|
||||
};
|
||||
|
||||
if (typeof id === 'string') {
|
||||
setDeletedDate(id);
|
||||
} else {
|
||||
(id as string[]).forEach(setDeletedDate);
|
||||
}
|
||||
|
||||
await this.storageService.save(Keys.ciphersPrefix + userId, ciphers);
|
||||
this.decryptedCipherCache = null;
|
||||
}
|
||||
|
||||
async softDeleteWithServer(id: string): Promise<any> {
|
||||
await this.apiService.putDeleteCipher(id);
|
||||
await this.softDelete(id);
|
||||
}
|
||||
|
||||
async softDeleteManyWithServer(ids: string[]): Promise<any> {
|
||||
await this.apiService.putDeleteManyCiphers(new CipherBulkDeleteRequest(ids));
|
||||
await this.softDelete(ids);
|
||||
}
|
||||
|
||||
async restore(id: string | string[]): Promise<any> {
|
||||
const userId = await this.userService.getUserId();
|
||||
const ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
|
||||
Keys.ciphersPrefix + userId);
|
||||
if (ciphers == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const clearDeletedDate = (cipherId: string) => {
|
||||
if (ciphers[cipherId] == null) {
|
||||
return;
|
||||
}
|
||||
ciphers[cipherId].deletedDate = null;
|
||||
};
|
||||
|
||||
if (typeof id === 'string') {
|
||||
clearDeletedDate(id);
|
||||
} else {
|
||||
(id as string[]).forEach(clearDeletedDate);
|
||||
}
|
||||
|
||||
await this.storageService.save(Keys.ciphersPrefix + userId, ciphers);
|
||||
this.decryptedCipherCache = null;
|
||||
}
|
||||
|
||||
async restoreWithServer(id: string): Promise<any> {
|
||||
await this.apiService.putRestoreCipher(id);
|
||||
await this.restore(id);
|
||||
}
|
||||
|
||||
async restoreManyWithServer(ids: string[]): Promise<any> {
|
||||
await this.apiService.putRestoreManyCiphers(new CipherBulkRestoreRequest(ids));
|
||||
await this.restore(ids);
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
private async shareAttachmentWithServer(attachmentView: AttachmentView, cipherId: string,
|
||||
|
||||
@@ -71,7 +71,8 @@ export class SearchService implements SearchServiceAbstraction {
|
||||
console.timeEnd('search indexing');
|
||||
}
|
||||
|
||||
async searchCiphers(query: string, filter: (cipher: CipherView) => boolean = null, ciphers: CipherView[] = null):
|
||||
async searchCiphers(query: string, filter: (cipher: CipherView) => boolean = null, ciphers: CipherView[] = null,
|
||||
deleted: boolean = false):
|
||||
Promise<CipherView[]> {
|
||||
const results: CipherView[] = [];
|
||||
if (query != null) {
|
||||
@@ -84,9 +85,16 @@ export class SearchService implements SearchServiceAbstraction {
|
||||
if (ciphers == null) {
|
||||
ciphers = await this.cipherService.getAllDecrypted();
|
||||
}
|
||||
if (filter != null) {
|
||||
ciphers = ciphers.filter(filter);
|
||||
}
|
||||
|
||||
ciphers = ciphers.filter((c) => {
|
||||
if (deleted !== c.isDeleted) {
|
||||
return false;
|
||||
}
|
||||
if (filter != null) {
|
||||
return filter(c);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!this.isSearchable(query)) {
|
||||
return ciphers;
|
||||
@@ -138,9 +146,12 @@ export class SearchService implements SearchServiceAbstraction {
|
||||
return results;
|
||||
}
|
||||
|
||||
searchCiphersBasic(ciphers: CipherView[], query: string) {
|
||||
searchCiphersBasic(ciphers: CipherView[], query: string, deleted: boolean = false) {
|
||||
query = query.trim().toLowerCase();
|
||||
return ciphers.filter((c) => {
|
||||
if (deleted !== c.isDeleted) {
|
||||
return false;
|
||||
}
|
||||
if (c.name != null && c.name.toLowerCase().indexOf(query) > -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user