Skip to content

Commit bdf91e2

Browse files
authored
[PM-13177] Fix Unassigned cipher collection assignment in AC (#11419)
* [PM-13177] Add saveCollectionsWithServerAdmin to CipherService * [PM-13177] Introduce isSingleCipherAdmin flag to AssignCollections component
1 parent 87cb45c commit bdf91e2

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

apps/web/src/app/vault/org-vault/vault.component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,8 @@ export class VaultComponent implements OnInit, OnDestroy {
12491249
organizationId: this.organization?.id as OrganizationId,
12501250
availableCollections,
12511251
activeCollection: this.activeFilter?.selectedCollectionNode?.node,
1252+
isSingleCipherAdmin:
1253+
items.length === 1 && (this.organization?.canEditAllCiphers || items[0].isUnassigned),
12521254
},
12531255
});
12541256

libs/common/src/vault/abstractions/cipher.service.ts

+7
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ export abstract class CipherService implements UserKeyRotationDataProvider<Ciphe
113113
* @returns A promise that resolves when the collections have been saved
114114
*/
115115
saveCollectionsWithServer: (cipher: Cipher) => Promise<Cipher>;
116+
117+
/**
118+
* Save the collections for a cipher with the server as an admin.
119+
* Used for Unassigned ciphers or when the user only has admin access to the cipher (not assigned normally).
120+
* @param cipher
121+
*/
122+
saveCollectionsWithServerAdmin: (cipher: Cipher) => Promise<void>;
116123
/**
117124
* Bulk update collections for many ciphers with the server
118125
* @param orgId

libs/common/src/vault/services/cipher.service.ts

+5
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,11 @@ export class CipherService implements CipherServiceAbstraction {
858858
return new Cipher(updated[cipher.id as CipherId], cipher.localData);
859859
}
860860

861+
async saveCollectionsWithServerAdmin(cipher: Cipher): Promise<void> {
862+
const request = new CipherCollectionsRequest(cipher.collectionIds);
863+
await this.apiService.putCipherCollectionsAdmin(cipher.id, request);
864+
}
865+
861866
/**
862867
* Bulk update collections for many ciphers with the server
863868
* @param orgId

libs/vault/src/components/assign-collections.component.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ export interface CollectionAssignmentParams {
6464
* removed from the ciphers upon submission.
6565
*/
6666
activeCollection?: CollectionView;
67+
68+
/**
69+
* Flag indicating if the user is performing the action as an admin on a SINGLE cipher. When true,
70+
* the `/admin` endpoint will be used to update the cipher's collections. Required when updating
71+
* ciphers an Admin does not normally have access to or for Unassigned ciphers.
72+
*
73+
* The bulk method already handles admin actions internally.
74+
*/
75+
isSingleCipherAdmin?: boolean;
6776
}
6877

6978
export enum CollectionAssignmentResult {
@@ -463,6 +472,10 @@ export class AssignCollectionsComponent implements OnInit, OnDestroy, AfterViewI
463472
const { collections } = this.formGroup.getRawValue();
464473
cipherView.collectionIds = collections.map((i) => i.id as CollectionId);
465474
const cipher = await this.cipherService.encrypt(cipherView, this.activeUserId);
466-
await this.cipherService.saveCollectionsWithServer(cipher);
475+
if (this.params.isSingleCipherAdmin) {
476+
await this.cipherService.saveCollectionsWithServerAdmin(cipher);
477+
} else {
478+
await this.cipherService.saveCollectionsWithServer(cipher);
479+
}
467480
}
468481
}

0 commit comments

Comments
 (0)