2021-12-17 15:57:11 +01:00
|
|
|
import { Component, EventEmitter, Input, Output } from "@angular/core";
|
2018-06-12 23:11:24 +02:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { Organization } from "@bitwarden/common/models/domain/organization";
|
|
|
|
import { CipherBulkDeleteRequest } from "@bitwarden/common/models/request/cipherBulkDeleteRequest";
|
2020-08-11 17:30:30 +02:00
|
|
|
|
2018-06-12 23:11:24 +02:00
|
|
|
@Component({
|
2021-12-17 15:57:11 +01:00
|
|
|
selector: "app-vault-bulk-delete",
|
|
|
|
templateUrl: "bulk-delete.component.html",
|
2018-06-12 23:11:24 +02:00
|
|
|
})
|
|
|
|
export class BulkDeleteComponent {
|
2021-12-17 15:57:11 +01:00
|
|
|
@Input() cipherIds: string[] = [];
|
2022-02-24 12:10:07 +01:00
|
|
|
@Input() permanent = false;
|
2021-12-17 15:57:11 +01:00
|
|
|
@Input() organization: Organization;
|
|
|
|
@Output() onDeleted = new EventEmitter();
|
|
|
|
|
|
|
|
formPromise: Promise<any>;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private cipherService: CipherService,
|
|
|
|
private platformUtilsService: PlatformUtilsService,
|
|
|
|
private i18nService: I18nService,
|
|
|
|
private apiService: ApiService
|
|
|
|
) {}
|
|
|
|
|
|
|
|
async submit() {
|
|
|
|
if (!this.organization || !this.organization.canEditAnyCollection) {
|
|
|
|
await this.deleteCiphers();
|
|
|
|
} else {
|
|
|
|
await this.deleteCiphersAdmin();
|
2018-06-12 23:11:24 +02:00
|
|
|
}
|
2020-08-11 17:30:30 +02:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
await this.formPromise;
|
|
|
|
|
|
|
|
this.onDeleted.emit();
|
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"success",
|
|
|
|
null,
|
|
|
|
this.i18nService.t(this.permanent ? "permanentlyDeletedItems" : "deletedItems")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async deleteCiphers() {
|
|
|
|
if (this.permanent) {
|
|
|
|
this.formPromise = await this.cipherService.deleteManyWithServer(this.cipherIds);
|
|
|
|
} else {
|
|
|
|
this.formPromise = await this.cipherService.softDeleteManyWithServer(this.cipherIds);
|
2020-08-11 17:30:30 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private async deleteCiphersAdmin() {
|
|
|
|
const deleteRequest = new CipherBulkDeleteRequest(this.cipherIds, this.organization.id);
|
|
|
|
if (this.permanent) {
|
|
|
|
this.formPromise = await this.apiService.deleteManyCiphersAdmin(deleteRequest);
|
|
|
|
} else {
|
|
|
|
this.formPromise = await this.apiService.putDeleteManyCiphersAdmin(deleteRequest);
|
2020-08-11 17:30:30 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-12 23:11:24 +02:00
|
|
|
}
|