mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00: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:
@@ -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"));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user