mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
* Refactor components to remove limitItemDeletion feature flag usage This commit simplifies the logic in various components by removing the limitItemDeletion feature flag. The conditions for displaying restore and delete actions are now based solely on the cipher's permissions, enhancing code clarity and maintainability. * Refactor cipher deletion logic to remove the feature flag and collection ID dependency This commit updates the cipher deletion logic across multiple components and services by removing the unnecessary dependency on collection IDs. The `canDeleteCipher$` method now solely relies on the cipher's permissions, simplifying the code and improving maintainability. * Remove LimitItemDeletion feature flag from feature-flag enum and default values * Remove configService from ServiceContainer and MainBackground constructor parameters * Remove configService from RestoreCommand instantiation in OssServeConfigurator and VaultProgram classes
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import { firstValueFrom } from "rxjs";
|
|
|
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
|
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
|
import { CipherAuthorizationService } from "@bitwarden/common/vault/services/cipher-authorization.service";
|
|
|
|
import { Response } from "../models/response";
|
|
|
|
export class RestoreCommand {
|
|
constructor(
|
|
private cipherService: CipherService,
|
|
private accountService: AccountService,
|
|
private cipherAuthorizationService: CipherAuthorizationService,
|
|
) {}
|
|
|
|
async run(object: string, id: string): Promise<Response> {
|
|
if (id != null) {
|
|
id = id.toLowerCase();
|
|
}
|
|
|
|
switch (object.toLowerCase()) {
|
|
case "item":
|
|
return await this.restoreCipher(id);
|
|
default:
|
|
return Response.badRequest("Unknown object.");
|
|
}
|
|
}
|
|
|
|
private async restoreCipher(id: string) {
|
|
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
|
|
const cipher = await this.cipherService.get(id, activeUserId);
|
|
|
|
if (cipher == null) {
|
|
return Response.notFound();
|
|
}
|
|
if (cipher.deletedDate == null) {
|
|
return Response.badRequest("Cipher is not in trash.");
|
|
}
|
|
|
|
const canRestore = await firstValueFrom(
|
|
this.cipherAuthorizationService.canRestoreCipher$(cipher),
|
|
);
|
|
|
|
if (!canRestore) {
|
|
return Response.error("You do not have permission to restore this item");
|
|
}
|
|
|
|
try {
|
|
await this.cipherService.restoreWithServer(id, activeUserId);
|
|
return Response.success();
|
|
} catch (e) {
|
|
return Response.error(e);
|
|
}
|
|
}
|
|
}
|