Skip to content

Commit

Permalink
[PM-12273] use organization properties for access permissions (#12358)
Browse files Browse the repository at this point in the history
* use organization properties for access permissions

* clean up refactor

* simplify logic

* refactor canAccessIntegrationEditor to have all the permission checks
  • Loading branch information
BTreston authored Dec 15, 2024
1 parent 407a571 commit 31be6a7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<app-header> </app-header>

<bit-tab-group [(selectedIndex)]="tabIndex">
<bit-tab [label]="'singleSignOn' | i18n">
<bit-tab-group [(selectedIndex)]="tabIndex" *ngIf="organization$ | async as organization">
<bit-tab [label]="'singleSignOn' | i18n" *ngIf="organization.useSso">
<section class="tw-mb-9">
<h2 bitTypography="h2">{{ "singleSignOn" | i18n }}</h2>
<p bitTypography="body1">
Expand All @@ -15,8 +15,11 @@ <h2 bitTypography="h2">{{ "singleSignOn" | i18n }}</h2>
</section>
</bit-tab>

<bit-tab [label]="'userProvisioning' | i18n">
<section class="tw-mb-9">
<bit-tab
[label]="'userProvisioning' | i18n"
*ngIf="organization.useScim || organization.useDirectory"
>
<section class="tw-mb-9" *ngIf="organization.useScim">
<h2 bitTypography="h2">
{{ "scimIntegration" | i18n }}
</h2>
Expand All @@ -29,7 +32,7 @@ <h2 bitTypography="h2">
[integrations]="integrationsList | filterIntegrations: IntegrationType.SCIM"
></app-integration-grid>
</section>
<section class="tw-mb-9">
<section class="tw-mb-9" *ngIf="organization.useDirectory">
<h2 bitTypography="h2">
{{ "bwdc" | i18n }}
</h2>
Expand All @@ -40,7 +43,7 @@ <h2 bitTypography="h2">
</section>
</bit-tab>

<bit-tab [label]="'eventManagement' | i18n">
<bit-tab [label]="'eventManagement' | i18n" *ngIf="organization.useEvents">
<section class="tw-mb-9">
<h2 bitTypography="h2">
{{ "eventManagement" | i18n }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Component } from "@angular/core";
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { Observable, switchMap } 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 { IntegrationType } from "@bitwarden/common/enums";

import { HeaderModule } from "../../../layouts/header/header.module";
Expand All @@ -21,11 +25,21 @@ import { SharedOrganizationModule } from "../shared";
FilterIntegrationsPipe,
],
})
export class AdminConsoleIntegrationsComponent {
export class AdminConsoleIntegrationsComponent implements OnInit {
integrationsList: Integration[] = [];
tabIndex: number;
organization$: Observable<Organization>;

constructor() {
ngOnInit(): void {
this.organization$ = this.route.params.pipe(
switchMap((params) => this.organizationService.get$(params.organizationId)),
);
}

constructor(
private route: ActivatedRoute,
private organizationService: OrganizationService,
) {
this.integrationsList = [
{
name: "AD FS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import { PolicyService } from "@bitwarden/common/admin-console/abstractions/poli
import { ProviderService } from "@bitwarden/common/admin-console/abstractions/provider.service";
import { PolicyType, ProviderStatusType } from "@bitwarden/common/admin-console/enums";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { ProductTierType } from "@bitwarden/common/billing/enums";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { getById } from "@bitwarden/common/platform/misc";
import { BannerModule, IconModule } from "@bitwarden/components";
Expand Down Expand Up @@ -69,7 +67,6 @@ export class OrganizationLayoutComponent implements OnInit {
private configService: ConfigService,
private policyService: PolicyService,
private providerService: ProviderService,
private i18nService: I18nService,
) {}

async ngOnInit() {
Expand Down Expand Up @@ -113,12 +110,7 @@ export class OrganizationLayoutComponent implements OnInit {
this.integrationPageEnabled$ = combineLatest(
this.organization$,
this.configService.getFeatureFlag$(FeatureFlag.PM14505AdminConsoleIntegrationPage),
).pipe(
map(
([org, featureFlagEnabled]) =>
org.productTierType === ProductTierType.Enterprise && featureFlagEnabled,
),
);
).pipe(map(([org, featureFlagEnabled]) => featureFlagEnabled && org.canAccessIntegrations));

this.domainVerificationNavigationTextKey = (await this.configService.getFeatureFlag(
FeatureFlag.AccountDeprovisioning,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const routes: Routes = [
canActivate: [
canAccessFeature(FeatureFlag.PM14505AdminConsoleIntegrationPage),
isEnterpriseOrgGuard(false),
organizationPermissionsGuard(canAccessIntegrations),
],
component: AdminConsoleIntegrationsComponent,
data: {
Expand Down Expand Up @@ -109,6 +110,10 @@ function getOrganizationRoute(organization: Organization): string {
return undefined;
}

function canAccessIntegrations(organization: Organization) {
return organization.canAccessIntegrations;
}

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
Expand Down
11 changes: 11 additions & 0 deletions libs/common/src/admin-console/models/domain/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,15 @@ export class Organization {
familySponsorshipValidUntil: new Date(json.familySponsorshipValidUntil),
});
}

get canAccessIntegrations() {
return (
(this.productTierType === ProductTierType.Teams ||
this.productTierType === ProductTierType.Enterprise) &&
(this.isAdmin ||
this.permissions.manageUsers ||
this.permissions.manageGroups ||
this.permissions.accessEventLogs)
);
}
}

0 comments on commit 31be6a7

Please sign in to comment.