Skip to content

Commit

Permalink
clean up refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
BTreston committed Dec 12, 2024
1 parent 93e0d23 commit 39a7592
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ 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 { OrganizationApiService } from "@bitwarden/common/admin-console/services/organization/organization-api.service";
import { PlanType, ProductTierType } from "@bitwarden/common/billing/enums";
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 { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
Expand Down Expand Up @@ -69,7 +68,6 @@ export class OrganizationLayoutComponent implements OnInit {
private configService: ConfigService,
private policyService: PolicyService,
private providerService: ProviderService,
private organizationApiService: OrganizationApiService,
) {}

async ngOnInit() {
Expand Down Expand Up @@ -110,15 +108,6 @@ export class OrganizationLayoutComponent implements OnInit {
),
);

const excludedPlans = [
PlanType.Free,
PlanType.Custom,
PlanType.TeamsStarter,
PlanType.TeamsStarter2023,
PlanType.FamiliesAnnually,
PlanType.FamiliesAnnually2019,
];

this.integrationPageEnabled$ = combineLatest(
this.organization$,
this.configService.getFeatureFlag$(FeatureFlag.PM14505AdminConsoleIntegrationPage),
Expand All @@ -128,16 +117,7 @@ export class OrganizationLayoutComponent implements OnInit {
(org.productTierType === ProductTierType.Enterprise ||
org.productTierType === ProductTierType.Teams) &&
featureFlagEnabled,
).pipe(
filter(
(enabled) =>
enabled &&
org.isAdmin &&
(org.useSso || org.useDirectory || org.useScim || org.useEvents),
),
switchMap(() => this.organizationApiService.getPlanType(org.id)),
map((planType) => !excludedPlans.includes(planType)),
),
).pipe(filter((enabled) => enabled && org.isAdmin && org.canAccessIntegrations)),
),
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { PlanType } from "@bitwarden/common/billing/enums";
import { BillingHistoryResponse } from "@bitwarden/common/billing/models/response/billing-history.response";

import { OrganizationApiKeyRequest } from "../../../admin-console/models/request/organization-api-key.request";
Expand Down Expand Up @@ -43,7 +42,6 @@ export class OrganizationApiServiceAbstraction {
getSubscription: (id: string) => Promise<OrganizationSubscriptionResponse>;
getLicense: (id: string, installationId: string) => Promise<unknown>;
getAutoEnrollStatus: (identifier: string) => Promise<OrganizationAutoEnrollStatusResponse>;
getPlanType: (id: string) => Promise<PlanType>;
create: (request: OrganizationCreateRequest) => Promise<OrganizationResponse>;
createWithoutPayment: (
request: OrganizationNoPaymentMethodCreateRequest,
Expand Down
7 changes: 6 additions & 1 deletion libs/common/src/admin-console/models/domain/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ export class Organization {
}

get canAccessIntegrations() {
return this.isAdmin || this.userIsManagedByOrganization || this.canAccessEventLogs;
return (

Check warning on line 365 in libs/common/src/admin-console/models/domain/organization.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/admin-console/models/domain/organization.ts#L365

Added line #L365 was not covered by tests
this.isAdmin ||
this.permissions.manageUsers ||
this.permissions.manageGroups ||
this.permissions.accessEventLogs
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { PlanType } from "@bitwarden/common/billing/enums";
import { BillingHistoryResponse } from "@bitwarden/common/billing/models/response/billing-history.response";

import { ApiService } from "../../../abstractions/api.service";
Expand Down Expand Up @@ -93,10 +92,6 @@ export class OrganizationApiService implements OrganizationApiServiceAbstraction
);
}

async getPlanType(id: string): Promise<PlanType> {
return this.apiService.send("GET", "/organizations/" + id + "/plan-type", null, true, true);
}

async getAutoEnrollStatus(identifier: string): Promise<OrganizationAutoEnrollStatusResponse> {
const r = await this.apiService.send(
"GET",
Expand Down

0 comments on commit 39a7592

Please sign in to comment.