1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-21 11:35:34 +01:00

[AC-2447] Allow the UI to save and close dialog when user removes final Can Manage Collection of an item (#9136)

* update saveCollectionsWithServer to accept a new value if user can no longer manage cipher after requested update
This commit is contained in:
Jason Ng 2024-05-21 12:32:27 -04:00 committed by GitHub
parent b7463d551c
commit 5075d0865e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 6 deletions

View File

@ -123,6 +123,7 @@ import {
CollectionDetailsResponse,
CollectionResponse,
} from "../vault/models/response/collection.response";
import { OptionalCipherResponse } from "../vault/models/response/optional-cipher.response";
import { SyncResponse } from "../vault/models/response/sync.response";
/**
@ -218,7 +219,10 @@ export abstract class ApiService {
putMoveCiphers: (request: CipherBulkMoveRequest) => Promise<any>;
putShareCipher: (id: string, request: CipherShareRequest) => Promise<CipherResponse>;
putShareCiphers: (request: CipherBulkShareRequest) => Promise<any>;
putCipherCollections: (id: string, request: CipherCollectionsRequest) => Promise<CipherResponse>;
putCipherCollections: (
id: string,
request: CipherCollectionsRequest,
) => Promise<OptionalCipherResponse>;
putCipherCollectionsAdmin: (id: string, request: CipherCollectionsRequest) => Promise<any>;
postPurgeCiphers: (request: SecretVerificationRequest, organizationId?: string) => Promise<any>;
putDeleteCipher: (id: string) => Promise<any>;

View File

@ -138,6 +138,7 @@ import {
CollectionDetailsResponse,
CollectionResponse,
} from "../vault/models/response/collection.response";
import { OptionalCipherResponse } from "../vault/models/response/optional-cipher.response";
import { SyncResponse } from "../vault/models/response/sync.response";
/**
@ -566,9 +567,15 @@ export class ApiService implements ApiServiceAbstraction {
async putCipherCollections(
id: string,
request: CipherCollectionsRequest,
): Promise<CipherResponse> {
const response = await this.send("PUT", "/ciphers/" + id + "/collections", request, true, true);
return new CipherResponse(response);
): Promise<OptionalCipherResponse> {
const response = await this.send(
"PUT",
"/ciphers/" + id + "/collections_v2",
request,
true,
true,
);
return new OptionalCipherResponse(response);
}
putCipherCollectionsAdmin(id: string, request: CipherCollectionsRequest): Promise<any> {

View File

@ -0,0 +1,14 @@
import { BaseResponse } from "../../../models/response/base.response";
import { CipherResponse } from "./cipher.response";
export class OptionalCipherResponse extends BaseResponse {
unavailable: boolean;
cipher?: CipherResponse;
constructor(response: any) {
super(response);
this.unavailable = this.getResponseProperty("Unavailable");
this.cipher = new CipherResponse(this.getResponseProperty("Cipher"));
}
}

View File

@ -776,9 +776,14 @@ export class CipherService implements CipherServiceAbstraction {
async saveCollectionsWithServer(cipher: Cipher): Promise<Cipher> {
const request = new CipherCollectionsRequest(cipher.collectionIds);
const response = await this.apiService.putCipherCollections(cipher.id, request);
const data = new CipherData(response);
// The response will now check for an unavailable value. This value determines whether
// the user still has Can Manage access to the item after updating.
if (response.unavailable) {
await this.delete(cipher.id);
return;
}
const data = new CipherData(response.cipher);
const updated = await this.upsert(data);
// Collection updates don't change local data
return new Cipher(updated[cipher.id as CipherId], cipher.localData);
}