Skip to content

Commit

Permalink
Refactor AccountComponent to use OrganizationService to check for man…
Browse files Browse the repository at this point in the history
…aging organization
  • Loading branch information
r-tome committed Oct 8, 2024
1 parent 077d8c3 commit 3a02b67
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions apps/web/src/app/auth/settings/account/account.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit, ViewChild, ViewContainerRef } from "@angular/core";
import { lastValueFrom, map, Observable, of, switchMap } from "rxjs";

import { ModalService } from "@bitwarden/angular/services/modal.service";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
Expand All @@ -28,8 +28,8 @@ export class AccountComponent implements OnInit {
private modalService: ModalService,
private dialogService: DialogService,
private userVerificationService: UserVerificationService,
private accountService: AccountService,
private configService: ConfigService,
private organizationService: OrganizationService,

Check warning on line 32 in apps/web/src/app/auth/settings/account/account.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/auth/settings/account/account.component.ts#L32

Added line #L32 was not covered by tests
) {}

async ngOnInit() {
Expand All @@ -39,8 +39,8 @@ export class AccountComponent implements OnInit {
.pipe(
switchMap((isAccountDeprovisioningEnabled) =>
isAccountDeprovisioningEnabled
? this.accountService.activeAccount$.pipe(
map((account) => account?.managedByOrganizationId === null),
? this.organizationService.organizations$.pipe(
map((organizations) => !organizations.some((o) => o.managesActiveUser === true)),

Check warning on line 43 in apps/web/src/app/auth/settings/account/account.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/auth/settings/account/account.component.ts#L43

Added line #L43 was not covered by tests
)
: of(true),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class OrganizationData {
accessSecretsManager: boolean;
limitCollectionCreationDeletion: boolean;
allowAdminAccessToAllCollectionItems: boolean;
managesActiveUser?: boolean | null;

constructor(
response?: ProfileOrganizationResponse,
Expand Down Expand Up @@ -112,6 +113,7 @@ export class OrganizationData {
this.accessSecretsManager = response.accessSecretsManager;
this.limitCollectionCreationDeletion = response.limitCollectionCreationDeletion;
this.allowAdminAccessToAllCollectionItems = response.allowAdminAccessToAllCollectionItems;
this.managesActiveUser = response.managesActiveUser;

this.isMember = options.isMember;
this.isProviderUser = options.isProviderUser;
Expand Down
7 changes: 7 additions & 0 deletions libs/common/src/admin-console/models/domain/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ export class Organization {
* Refers to the ability for an owner/admin to access all collection items, regardless of assigned collections
*/
allowAdminAccessToAllCollectionItems: boolean;
/**
* Indicates if this organization manages the active user.
* A user is considered managed by an organization if their email domain
* matches one of the verified domains of that organization, and the user is a member of it.
*/
managesActiveUser?: boolean | null;

constructor(obj?: OrganizationData) {
if (obj == null) {
Expand Down Expand Up @@ -127,6 +133,7 @@ export class Organization {
this.accessSecretsManager = obj.accessSecretsManager;
this.limitCollectionCreationDeletion = obj.limitCollectionCreationDeletion;
this.allowAdminAccessToAllCollectionItems = obj.allowAdminAccessToAllCollectionItems;
this.managesActiveUser = obj.managesActiveUser;
}

get canAccess() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class ProfileOrganizationResponse extends BaseResponse {
accessSecretsManager: boolean;
limitCollectionCreationDeletion: boolean;
allowAdminAccessToAllCollectionItems: boolean;
managesActiveUser?: boolean | null;

constructor(response: any) {
super(response);
Expand Down Expand Up @@ -115,5 +116,6 @@ export class ProfileOrganizationResponse extends BaseResponse {
this.allowAdminAccessToAllCollectionItems = this.getResponseProperty(
"AllowAdminAccessToAllCollectionItems",
);
this.managesActiveUser = this.getResponseProperty("ManagesActiveUser") ?? null;
}
}

0 comments on commit 3a02b67

Please sign in to comment.