This commit is contained in:
Jason Ng 2024-05-17 14:11:21 -07:00 committed by GitHub
commit 8defb89a7f
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 be null when a Owner/Admin makes a request removing the last Can Manage Access
// they have for an item. When this occurs we will call delete to remove that cipher from state
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);
}