[PM-5757] Update local collection data when a collection is updated (#7940)
* [PM-5757] Update local data when a collection is updated * [PM-5757] Use defer() for collections re-evaluate the promise on refresh$
This commit is contained in:
parent
f0ae318f57
commit
2a9d396a01
|
@ -4,6 +4,8 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
import { SelectionReadOnlyRequest } from "@bitwarden/common/admin-console/models/request/selection-read-only.request";
|
import { SelectionReadOnlyRequest } from "@bitwarden/common/admin-console/models/request/selection-read-only.request";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
||||||
|
import { CollectionService } from "@bitwarden/common/vault/abstractions/collection.service";
|
||||||
|
import { CollectionData } from "@bitwarden/common/vault/models/data/collection.data";
|
||||||
import { CollectionRequest } from "@bitwarden/common/vault/models/request/collection.request";
|
import { CollectionRequest } from "@bitwarden/common/vault/models/request/collection.request";
|
||||||
import {
|
import {
|
||||||
CollectionAccessDetailsResponse,
|
CollectionAccessDetailsResponse,
|
||||||
|
@ -21,6 +23,7 @@ export class CollectionAdminService {
|
||||||
constructor(
|
constructor(
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
private collectionService: CollectionService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async getAll(organizationId: string): Promise<CollectionAdminView[]> {
|
async getAll(organizationId: string): Promise<CollectionAdminView[]> {
|
||||||
|
@ -67,6 +70,12 @@ export class CollectionAdminService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response.assigned) {
|
||||||
|
await this.collectionService.upsert(new CollectionData(response));
|
||||||
|
} else {
|
||||||
|
await this.collectionService.delete(collection.id);
|
||||||
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { ActivatedRoute, Params, Router } from "@angular/router";
|
||||||
import {
|
import {
|
||||||
BehaviorSubject,
|
BehaviorSubject,
|
||||||
combineLatest,
|
combineLatest,
|
||||||
|
defer,
|
||||||
firstValueFrom,
|
firstValueFrom,
|
||||||
lastValueFrom,
|
lastValueFrom,
|
||||||
Observable,
|
Observable,
|
||||||
|
@ -250,7 +251,7 @@ export class VaultComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
const allCollectionsWithoutUnassigned$ = combineLatest([
|
const allCollectionsWithoutUnassigned$ = combineLatest([
|
||||||
organizationId$.pipe(switchMap((orgId) => this.collectionAdminService.getAll(orgId))),
|
organizationId$.pipe(switchMap((orgId) => this.collectionAdminService.getAll(orgId))),
|
||||||
this.collectionService.getAllDecrypted(),
|
defer(() => this.collectionService.getAllDecrypted()),
|
||||||
]).pipe(
|
]).pipe(
|
||||||
map(([adminCollections, syncCollections]) => {
|
map(([adminCollections, syncCollections]) => {
|
||||||
const syncCollectionDict = Object.fromEntries(syncCollections.map((c) => [c.id, c]));
|
const syncCollectionDict = Object.fromEntries(syncCollections.map((c) => [c.id, c]));
|
||||||
|
|
|
@ -20,12 +20,17 @@ export class CollectionDetailsResponse extends CollectionResponse {
|
||||||
readOnly: boolean;
|
readOnly: boolean;
|
||||||
manage: boolean;
|
manage: boolean;
|
||||||
hidePasswords: boolean;
|
hidePasswords: boolean;
|
||||||
|
assigned: boolean;
|
||||||
|
|
||||||
constructor(response: any) {
|
constructor(response: any) {
|
||||||
super(response);
|
super(response);
|
||||||
this.readOnly = this.getResponseProperty("ReadOnly") || false;
|
this.readOnly = this.getResponseProperty("ReadOnly") || false;
|
||||||
this.manage = this.getResponseProperty("Manage") || false;
|
this.manage = this.getResponseProperty("Manage") || false;
|
||||||
this.hidePasswords = this.getResponseProperty("HidePasswords") || false;
|
this.hidePasswords = this.getResponseProperty("HidePasswords") || false;
|
||||||
|
|
||||||
|
// Temporary until the API is updated to return this property in AC-2084
|
||||||
|
// For now, we can assume that if the object is 'collectionDetails' then the user is assigned
|
||||||
|
this.assigned = this.getResponseProperty("object") == "collectionDetails";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue