From 89c8c48cd4097fd8f4758f7c0a2286b574ed571f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rui=20Tom=C3=A9?= <108268980+r-tome@users.noreply.github.com> Date: Fri, 21 Apr 2023 12:22:34 +0100 Subject: [PATCH] [AC-1340] Fixed cipher restore for provider users by using the restore-admin endpoints (#5255) --- apps/web/src/app/vault/org-vault/vault.component.ts | 3 ++- libs/angular/src/vault/components/add-edit.component.ts | 3 ++- libs/common/src/vault/abstractions/cipher.service.ts | 2 +- libs/common/src/vault/services/cipher.service.ts | 6 ++++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/web/src/app/vault/org-vault/vault.component.ts b/apps/web/src/app/vault/org-vault/vault.component.ts index 0f842c621e..fce2097a58 100644 --- a/apps/web/src/app/vault/org-vault/vault.component.ts +++ b/apps/web/src/app/vault/org-vault/vault.component.ts @@ -674,7 +674,8 @@ export class VaultComponent implements OnInit, OnDestroy { } try { - await this.cipherService.restoreWithServer(c.id); + const asAdmin = this.organization?.canEditAnyCollection; + await this.cipherService.restoreWithServer(c.id, asAdmin); this.platformUtilsService.showToast("success", null, this.i18nService.t("restoredItem")); this.refresh(); } catch (e) { diff --git a/libs/angular/src/vault/components/add-edit.component.ts b/libs/angular/src/vault/components/add-edit.component.ts index ae6e95f12a..54dccfd2e9 100644 --- a/libs/angular/src/vault/components/add-edit.component.ts +++ b/libs/angular/src/vault/components/add-edit.component.ts @@ -610,7 +610,8 @@ export class AddEditComponent implements OnInit, OnDestroy { } protected restoreCipher() { - return this.cipherService.restoreWithServer(this.cipher.id); + const asAdmin = this.organization?.canEditAnyCollection; + return this.cipherService.restoreWithServer(this.cipher.id, asAdmin); } get defaultOwnerId(): string | null { diff --git a/libs/common/src/vault/abstractions/cipher.service.ts b/libs/common/src/vault/abstractions/cipher.service.ts index 60c0366f61..ffb2c43adc 100644 --- a/libs/common/src/vault/abstractions/cipher.service.ts +++ b/libs/common/src/vault/abstractions/cipher.service.ts @@ -75,6 +75,6 @@ export abstract class CipherService { restore: ( cipher: { id: string; revisionDate: string } | { id: string; revisionDate: string }[] ) => Promise; - restoreWithServer: (id: string) => Promise; + restoreWithServer: (id: string, asAdmin?: boolean) => Promise; restoreManyWithServer: (ids: string[]) => Promise; } diff --git a/libs/common/src/vault/services/cipher.service.ts b/libs/common/src/vault/services/cipher.service.ts index 3a3a9aa634..c59319285a 100644 --- a/libs/common/src/vault/services/cipher.service.ts +++ b/libs/common/src/vault/services/cipher.service.ts @@ -914,8 +914,10 @@ export class CipherService implements CipherServiceAbstraction { await this.stateService.setEncryptedCiphers(ciphers); } - async restoreWithServer(id: string): Promise { - const response = await this.apiService.putRestoreCipher(id); + async restoreWithServer(id: string, asAdmin = false): Promise { + const response = asAdmin + ? await this.apiService.putRestoreCipherAdmin(id) + : await this.apiService.putRestoreCipher(id); await this.restore({ id: id, revisionDate: response.revisionDate }); }