mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 17:53:39 +00:00
[PM-15506] Implement vNextOrganizationService (#12839)
* [PM-15506] Wire up vNextOrganizationService for libs/common and libs/angular (#12683) * Wire up vNextOrganizationService in PolicyService * Wire vNextOrganizationService in SyncService * wire vNextOrganizationService for EventCollectionService * wire vNextOrganizationService for KeyConnectorService * wire up vNextOrganizationService for CipherAuthorizationService * Wire up vNextOrganizationService in PolicyService * Wire vNextOrganizationService in SyncService * wire vNextOrganizationService for EventCollectionService * wire vNextOrganizationService for KeyConnectorService * wire up vNextOrganizationService for CipherAuthorizationService * wire vNextOrganizationService for share.component * wire vNextOrganizationService for collections.component * wire vNextOrganizationServcie for add-account-credit-dialog * wire vNextOrganizationService for vault-filter.service * fix browser errors for vNextOrganizationService implementation in libs * fix desktop errors for vNextOrganizationService implementation for libs * fix linter errors * fix CLI errors on vNextOrganizationServcie implementations for libs * [PM-15506] Wire up vNextOrganizationService for web client (#12810) PR to a feature branch, no need to review until this goes to main. * implement vNextOrganization service for browser client (#12844) PR to feature branch, no need for review yet. * wire vNextOrganizationService for licence and some web router guards * wire vNextOrganizationService in tests * remove vNext notation for OrganizationService and related * Merge branch 'main' into ac/pm-15506-vNextOrganizationService * fix tsstrict error * fix test, fix ts strict error
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { firstValueFrom, map, from, zip, Observable } from "rxjs";
|
||||
import { firstValueFrom, map, from, zip } from "rxjs";
|
||||
|
||||
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
||||
|
||||
import { EventCollectionService as EventCollectionServiceAbstraction } from "../../abstractions/event/event-collection.service";
|
||||
import { EventUploadService } from "../../abstractions/event/event-upload.service";
|
||||
import { OrganizationService } from "../../admin-console/abstractions/organization/organization.service.abstraction";
|
||||
import { AccountService } from "../../auth/abstractions/account.service";
|
||||
import { AuthService } from "../../auth/abstractions/auth.service";
|
||||
import { AuthenticationStatus } from "../../auth/enums/authentication-status";
|
||||
import { EventType } from "../../enums";
|
||||
@@ -17,8 +20,6 @@ import { CipherView } from "../../vault/models/view/cipher.view";
|
||||
import { EVENT_COLLECTION } from "./key-definitions";
|
||||
|
||||
export class EventCollectionService implements EventCollectionServiceAbstraction {
|
||||
private orgIds$: Observable<string[]>;
|
||||
|
||||
constructor(
|
||||
private cipherService: CipherService,
|
||||
private stateProvider: StateProvider,
|
||||
@@ -26,11 +27,11 @@ export class EventCollectionService implements EventCollectionServiceAbstraction
|
||||
private eventUploadService: EventUploadService,
|
||||
private authService: AuthService,
|
||||
private accountService: AccountService,
|
||||
) {
|
||||
this.orgIds$ = this.organizationService.organizations$.pipe(
|
||||
map((orgs) => orgs?.filter((o) => o.useEvents)?.map((x) => x.id) ?? []),
|
||||
);
|
||||
}
|
||||
) {}
|
||||
|
||||
private getOrgIds = (orgs: Organization[]): string[] => {
|
||||
return orgs?.filter((o) => o.useEvents)?.map((x) => x.id) ?? [];
|
||||
};
|
||||
|
||||
/** Adds an event to the active user's event collection
|
||||
* @param eventType the event type to be added
|
||||
@@ -42,14 +43,15 @@ export class EventCollectionService implements EventCollectionServiceAbstraction
|
||||
ciphers: CipherView[],
|
||||
uploadImmediately = false,
|
||||
): Promise<any> {
|
||||
const userId = await firstValueFrom(this.accountService.activeAccount$.pipe(map((a) => a?.id)));
|
||||
const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$));
|
||||
const eventStore = this.stateProvider.getUser(userId, EVENT_COLLECTION);
|
||||
|
||||
if (!(await this.shouldUpdate(null, eventType, ciphers))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const events$ = this.orgIds$.pipe(
|
||||
const events$ = this.organizationService.organizations$(userId).pipe(
|
||||
map((orgs) => this.getOrgIds(orgs)),
|
||||
map((orgs) =>
|
||||
ciphers
|
||||
.filter((c) => orgs.includes(c.organizationId))
|
||||
@@ -86,7 +88,7 @@ export class EventCollectionService implements EventCollectionServiceAbstraction
|
||||
uploadImmediately = false,
|
||||
organizationId: string = null,
|
||||
): Promise<any> {
|
||||
const userId = await firstValueFrom(this.accountService.activeAccount$.pipe(map((a) => a?.id)));
|
||||
const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$));
|
||||
const eventStore = this.stateProvider.getUser(userId, EVENT_COLLECTION);
|
||||
|
||||
if (!(await this.shouldUpdate(organizationId, eventType, undefined, cipherId))) {
|
||||
@@ -122,8 +124,14 @@ export class EventCollectionService implements EventCollectionServiceAbstraction
|
||||
): Promise<boolean> {
|
||||
const cipher$ = from(this.cipherService.get(cipherId));
|
||||
|
||||
const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$));
|
||||
|
||||
const orgIds$ = this.organizationService
|
||||
.organizations$(userId)
|
||||
.pipe(map((orgs) => this.getOrgIds(orgs)));
|
||||
|
||||
const [authStatus, orgIds, cipher] = await firstValueFrom(
|
||||
zip(this.authService.activeAccountStatus$, this.orgIds$, cipher$),
|
||||
zip(this.authService.activeAccountStatus$, orgIds$, cipher$),
|
||||
);
|
||||
|
||||
// The user must be authorized
|
||||
|
||||
Reference in New Issue
Block a user