mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 06:13:38 +00:00
[PM-12047] Remove usage of ActiveUserState from cipher.service (#12814)
* Cipher service web changes * Updated browser client to pass user id to cipher service observable changes * Cli changes * desktop changes * Fixed test * Libs changes * Fixed merge conflicts * Fixed merge conflicts * removed duplicate reference fixed conflict * Fixed test * Fixed test * Fixed test * Fixed desturcturing issue on failed to decrypt ciphers cipher service * Updated abstraction to use method syntax * Fixed conflicts * Fixed test on add edit v2 Passed active userId to delete function * Used getUserId utility function * made vault changes * made suggestion changes * made suggestion changes * made suggestion changes * Replace getUserId function calls with pipe operator syntax for better consistency * fixed merge conflicts * revert mistake made of usinf account activity during merge conflict fix * fixed conflicts * fixed tests
This commit is contained in:
@@ -179,7 +179,6 @@ export class AssignCollectionsComponent implements OnInit, OnDestroy, AfterViewI
|
||||
private get selectedOrgId(): OrganizationId {
|
||||
return this.formGroup.getRawValue().selectedOrg || this.params.organizationId;
|
||||
}
|
||||
private activeUserId: UserId;
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
constructor(
|
||||
@@ -193,10 +192,6 @@ export class AssignCollectionsComponent implements OnInit, OnDestroy, AfterViewI
|
||||
) {}
|
||||
|
||||
async ngOnInit() {
|
||||
this.activeUserId = await firstValueFrom(
|
||||
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
|
||||
);
|
||||
|
||||
const onlyPersonalItems = this.params.ciphers.every((c) => c.organizationId == null);
|
||||
|
||||
if (this.selectedOrgId === MY_VAULT_ID || onlyPersonalItems) {
|
||||
@@ -253,12 +248,15 @@ export class AssignCollectionsComponent implements OnInit, OnDestroy, AfterViewI
|
||||
.filter((i) => i.organizationId)
|
||||
.map((i) => i.id as CipherId);
|
||||
|
||||
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
|
||||
|
||||
// Move personal items to the organization
|
||||
if (this.personalItemsCount > 0) {
|
||||
await this.moveToOrganization(
|
||||
this.selectedOrgId,
|
||||
this.params.ciphers.filter((c) => c.organizationId == null),
|
||||
this.formGroup.controls.collections.value.map((i) => i.id as CollectionId),
|
||||
activeUserId,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -267,8 +265,8 @@ export class AssignCollectionsComponent implements OnInit, OnDestroy, AfterViewI
|
||||
|
||||
// Update assigned collections for single org cipher or bulk update collections for multiple org ciphers
|
||||
await (isSingleOrgCipher
|
||||
? this.updateAssignedCollections(this.editableItems[0])
|
||||
: this.bulkUpdateCollections(cipherIds));
|
||||
? this.updateAssignedCollections(this.editableItems[0], activeUserId)
|
||||
: this.bulkUpdateCollections(cipherIds, activeUserId));
|
||||
|
||||
this.toastService.showToast({
|
||||
variant: "success",
|
||||
@@ -447,12 +445,13 @@ export class AssignCollectionsComponent implements OnInit, OnDestroy, AfterViewI
|
||||
organizationId: OrganizationId,
|
||||
shareableCiphers: CipherView[],
|
||||
selectedCollectionIds: CollectionId[],
|
||||
userId: UserId,
|
||||
) {
|
||||
await this.cipherService.shareManyWithServer(
|
||||
shareableCiphers,
|
||||
organizationId,
|
||||
selectedCollectionIds,
|
||||
this.activeUserId,
|
||||
userId,
|
||||
);
|
||||
|
||||
this.toastService.showToast({
|
||||
@@ -465,10 +464,11 @@ export class AssignCollectionsComponent implements OnInit, OnDestroy, AfterViewI
|
||||
});
|
||||
}
|
||||
|
||||
private async bulkUpdateCollections(cipherIds: CipherId[]) {
|
||||
private async bulkUpdateCollections(cipherIds: CipherId[], userId: UserId) {
|
||||
if (this.formGroup.controls.collections.value.length > 0) {
|
||||
await this.cipherService.bulkUpdateCollectionsWithServer(
|
||||
this.selectedOrgId,
|
||||
userId,
|
||||
cipherIds,
|
||||
this.formGroup.controls.collections.value.map((i) => i.id as CollectionId),
|
||||
false,
|
||||
@@ -483,6 +483,7 @@ export class AssignCollectionsComponent implements OnInit, OnDestroy, AfterViewI
|
||||
) {
|
||||
await this.cipherService.bulkUpdateCollectionsWithServer(
|
||||
this.selectedOrgId,
|
||||
userId,
|
||||
cipherIds,
|
||||
[this.params.activeCollection.id as CollectionId],
|
||||
true,
|
||||
@@ -490,14 +491,14 @@ export class AssignCollectionsComponent implements OnInit, OnDestroy, AfterViewI
|
||||
}
|
||||
}
|
||||
|
||||
private async updateAssignedCollections(cipherView: CipherView) {
|
||||
private async updateAssignedCollections(cipherView: CipherView, userId: UserId) {
|
||||
const { collections } = this.formGroup.getRawValue();
|
||||
cipherView.collectionIds = collections.map((i) => i.id as CollectionId);
|
||||
const cipher = await this.cipherService.encrypt(cipherView, this.activeUserId);
|
||||
const cipher = await this.cipherService.encrypt(cipherView, userId);
|
||||
if (this.params.isSingleCipherAdmin) {
|
||||
await this.cipherService.saveCollectionsWithServerAdmin(cipher);
|
||||
} else {
|
||||
await this.cipherService.saveCollectionsWithServer(cipher);
|
||||
await this.cipherService.saveCollectionsWithServer(cipher, userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user