mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-02 08:40:08 +01:00
[Soft Delete] - cipher search rem deleted flag, filter array conditional
This commit is contained in:
parent
549fcc18ff
commit
3a10c1ff30
@ -4,7 +4,8 @@ export abstract class SearchService {
|
||||
clearIndex: () => void;
|
||||
isSearchable: (query: string) => boolean;
|
||||
indexCiphers: () => Promise<void>;
|
||||
searchCiphers: (query: string, filter?: (cipher: CipherView) => boolean,
|
||||
ciphers?: CipherView[], deleted?: boolean) => Promise<CipherView[]>;
|
||||
searchCiphers: (query: string,
|
||||
filter?: ((cipher: CipherView) => boolean) | (Array<(cipher: CipherView) => boolean>),
|
||||
ciphers?: CipherView[]) => Promise<CipherView[]>;
|
||||
searchCiphersBasic: (ciphers: CipherView[], query: string, deleted?: boolean) => CipherView[];
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ export class AddEditComponent implements OnInit {
|
||||
@Input() organizationId: string = null;
|
||||
@Output() onSavedCipher = new EventEmitter<CipherView>();
|
||||
@Output() onDeletedCipher = new EventEmitter<CipherView>();
|
||||
@Output() onRestoredCipher = new EventEmitter<CipherView>();
|
||||
@Output() onCancelled = new EventEmitter<CipherView>();
|
||||
@Output() onEditAttachments = new EventEmitter<CipherView>();
|
||||
@Output() onShareCipher = new EventEmitter<CipherView>();
|
||||
@ -63,6 +64,7 @@ export class AddEditComponent implements OnInit {
|
||||
title: string;
|
||||
formPromise: Promise<any>;
|
||||
deletePromise: Promise<any>;
|
||||
restorePromise: Promise<any>;
|
||||
checkPasswordPromise: Promise<number>;
|
||||
showPassword: boolean = false;
|
||||
showCardCode: boolean = false;
|
||||
@ -221,6 +223,10 @@ export class AddEditComponent implements OnInit {
|
||||
}
|
||||
|
||||
async submit(): Promise<boolean> {
|
||||
if (this.cipher.isDeleted) {
|
||||
return this.restore();
|
||||
}
|
||||
|
||||
if (this.cipher.name == null || this.cipher.name === '') {
|
||||
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
||||
this.i18nService.t('nameRequired'));
|
||||
@ -331,10 +337,35 @@ export class AddEditComponent implements OnInit {
|
||||
try {
|
||||
this.deletePromise = this.deleteCipher();
|
||||
await this.deletePromise;
|
||||
this.platformUtilsService.eventTrack('Deleted Cipher');
|
||||
this.platformUtilsService.showToast('success', null, this.i18nService.t('deletedItem'));
|
||||
this.platformUtilsService.eventTrack((this.cipher.isDeleted ? 'Permanently ' : '') + 'Deleted Cipher');
|
||||
this.platformUtilsService.showToast('success', null,
|
||||
this.i18nService.t(this.cipher.isDeleted ? 'permanentlyDeletedItem' : 'deletedItem'));
|
||||
this.onDeletedCipher.emit(this.cipher);
|
||||
this.messagingService.send('deletedCipher');
|
||||
this.messagingService.send(this.cipher.isDeleted ? 'permanentlyDeletedCipher' : 'deletedCipher');
|
||||
} catch { }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async restore(): Promise<boolean> {
|
||||
if (!this.cipher.isDeleted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const confirmed = await this.platformUtilsService.showDialog(
|
||||
this.i18nService.t('restoreItemConfirmation'), this.i18nService.t('restoreItem'),
|
||||
this.i18nService.t('yes'), this.i18nService.t('no'), 'warning');
|
||||
if (!confirmed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
this.restorePromise = this.restoreCipher();
|
||||
await this.restorePromise;
|
||||
this.platformUtilsService.eventTrack('Restored Cipher');
|
||||
this.platformUtilsService.showToast('success', null, this.i18nService.t('restoredItem'));
|
||||
this.onRestoredCipher.emit(this.cipher);
|
||||
this.messagingService.send('restoredCipher');
|
||||
} catch { }
|
||||
|
||||
return true;
|
||||
@ -449,6 +480,11 @@ export class AddEditComponent implements OnInit {
|
||||
}
|
||||
|
||||
protected deleteCipher() {
|
||||
return this.cipherService.deleteWithServer(this.cipher.id);
|
||||
return this.cipher.isDeleted ? this.cipherService.deleteWithServer(this.cipher.id)
|
||||
: this.cipherService.softDeleteWithServer(this.cipher.id);
|
||||
}
|
||||
|
||||
protected restoreCipher() {
|
||||
return this.cipherService.restoreWithServer(this.cipher.id);
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ export class CiphersComponent {
|
||||
async refresh() {
|
||||
try {
|
||||
this.refreshing = true;
|
||||
await this.reload(this.filter);
|
||||
await this.reload(this.filter, this.deleted);
|
||||
} finally {
|
||||
this.refreshing = false;
|
||||
}
|
||||
@ -80,14 +80,15 @@ export class CiphersComponent {
|
||||
if (this.searchTimeout != null) {
|
||||
clearTimeout(this.searchTimeout);
|
||||
}
|
||||
const deletedFilter: (cipher: CipherView) => boolean = (c) => c.isDeleted === this.deleted;
|
||||
if (timeout == null) {
|
||||
this.ciphers = await this.searchService.searchCiphers(this.searchText, this.filter, null, this.deleted);
|
||||
this.ciphers = await this.searchService.searchCiphers(this.searchText, [this.filter, deletedFilter], null);
|
||||
await this.resetPaging();
|
||||
return;
|
||||
}
|
||||
this.searchPending = true;
|
||||
this.searchTimeout = setTimeout(async () => {
|
||||
this.ciphers = await this.searchService.searchCiphers(this.searchText, this.filter, null, this.deleted);
|
||||
this.ciphers = await this.searchService.searchCiphers(this.searchText, [this.filter, deletedFilter], null);
|
||||
await this.resetPaging();
|
||||
this.searchPending = false;
|
||||
}, timeout);
|
||||
|
@ -34,6 +34,7 @@ export class ViewComponent implements OnDestroy, OnInit {
|
||||
@Input() cipherId: string;
|
||||
@Output() onEditCipher = new EventEmitter<CipherView>();
|
||||
@Output() onCloneCipher = new EventEmitter<CipherView>();
|
||||
@Output() onRestoreCipher = new EventEmitter<CipherView>();
|
||||
|
||||
cipher: CipherView;
|
||||
showPassword: boolean;
|
||||
@ -110,6 +111,13 @@ export class ViewComponent implements OnDestroy, OnInit {
|
||||
this.onCloneCipher.emit(this.cipher);
|
||||
}
|
||||
|
||||
restore() {
|
||||
if (!this.cipher.isDeleted) {
|
||||
return;
|
||||
}
|
||||
this.onRestoreCipher.emit(this.cipher);
|
||||
}
|
||||
|
||||
togglePassword() {
|
||||
this.platformUtilsService.eventTrack('Toggled Password');
|
||||
this.showPassword = !this.showPassword;
|
||||
|
@ -71,8 +71,9 @@ export class SearchService implements SearchServiceAbstraction {
|
||||
console.timeEnd('search indexing');
|
||||
}
|
||||
|
||||
async searchCiphers(query: string, filter: (cipher: CipherView) => boolean = null, ciphers: CipherView[] = null,
|
||||
deleted: boolean = false):
|
||||
async searchCiphers(query: string,
|
||||
filter: (((cipher: CipherView) => boolean) | (Array<(cipher: CipherView) => boolean>)) = null,
|
||||
ciphers: CipherView[] = null):
|
||||
Promise<CipherView[]> {
|
||||
const results: CipherView[] = [];
|
||||
if (query != null) {
|
||||
@ -86,15 +87,11 @@ export class SearchService implements SearchServiceAbstraction {
|
||||
ciphers = await this.cipherService.getAllDecrypted();
|
||||
}
|
||||
|
||||
ciphers = ciphers.filter((c) => {
|
||||
if (deleted !== c.isDeleted) {
|
||||
return false;
|
||||
}
|
||||
if (filter != null) {
|
||||
return filter(c);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (filter != null && Array.isArray(filter) && filter.length > 0) {
|
||||
ciphers = ciphers.filter((c) => filter.every((f) => f == null || f(c)));
|
||||
} else if (filter != null) {
|
||||
ciphers = ciphers.filter(filter as (cipher: CipherView) => boolean);
|
||||
}
|
||||
|
||||
if (!this.isSearchable(query)) {
|
||||
return ciphers;
|
||||
|
Loading…
Reference in New Issue
Block a user