1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-28 12:45:45 +01:00

Conditionally disable client-side policy validation (#11550)

This commit is contained in:
Thomas Rittson 2024-10-16 08:46:03 +10:00 committed by GitHub
parent 70d83feb38
commit 178a418850
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 4 deletions

View File

@ -3,6 +3,8 @@ import { Component } from "@angular/core";
import { PolicyType } from "@bitwarden/common/admin-console/enums"; import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { PolicyRequest } from "@bitwarden/common/admin-console/models/request/policy.request"; import { PolicyRequest } from "@bitwarden/common/admin-console/models/request/policy.request";
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 { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { BasePolicy, BasePolicyComponent } from "./base-policy.component"; import { BasePolicy, BasePolicyComponent } from "./base-policy.component";
@ -23,11 +25,19 @@ export class RequireSsoPolicy extends BasePolicy {
templateUrl: "require-sso.component.html", templateUrl: "require-sso.component.html",
}) })
export class RequireSsoPolicyComponent extends BasePolicyComponent { export class RequireSsoPolicyComponent extends BasePolicyComponent {
constructor(private i18nService: I18nService) { constructor(
private i18nService: I18nService,
private configService: ConfigService,
) {
super(); super();
} }
buildRequest(policiesEnabledMap: Map<PolicyType, boolean>): Promise<PolicyRequest> { async buildRequest(policiesEnabledMap: Map<PolicyType, boolean>): Promise<PolicyRequest> {
if (await this.configService.getFeatureFlag(FeatureFlag.Pm13322AddPolicyDefinitions)) {
// We are now relying on server-side validation only
return super.buildRequest(policiesEnabledMap);
}
const singleOrgEnabled = policiesEnabledMap.get(PolicyType.SingleOrg) ?? false; const singleOrgEnabled = policiesEnabledMap.get(PolicyType.SingleOrg) ?? false;
if (this.enabled.value && !singleOrgEnabled) { if (this.enabled.value && !singleOrgEnabled) {
throw new Error(this.i18nService.t("requireSsoPolicyReqError")); throw new Error(this.i18nService.t("requireSsoPolicyReqError"));

View File

@ -2,6 +2,8 @@ import { Component } from "@angular/core";
import { PolicyType } from "@bitwarden/common/admin-console/enums"; import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { PolicyRequest } from "@bitwarden/common/admin-console/models/request/policy.request"; import { PolicyRequest } from "@bitwarden/common/admin-console/models/request/policy.request";
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 { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { BasePolicy, BasePolicyComponent } from "./base-policy.component"; import { BasePolicy, BasePolicyComponent } from "./base-policy.component";
@ -18,11 +20,19 @@ export class SingleOrgPolicy extends BasePolicy {
templateUrl: "single-org.component.html", templateUrl: "single-org.component.html",
}) })
export class SingleOrgPolicyComponent extends BasePolicyComponent { export class SingleOrgPolicyComponent extends BasePolicyComponent {
constructor(private i18nService: I18nService) { constructor(
private i18nService: I18nService,
private configService: ConfigService,
) {
super(); super();
} }
buildRequest(policiesEnabledMap: Map<PolicyType, boolean>): Promise<PolicyRequest> { async buildRequest(policiesEnabledMap: Map<PolicyType, boolean>): Promise<PolicyRequest> {
if (await this.configService.getFeatureFlag(FeatureFlag.Pm13322AddPolicyDefinitions)) {
// We are now relying on server-side validation only
return super.buildRequest(policiesEnabledMap);
}
if (!this.enabled.value) { if (!this.enabled.value) {
if (policiesEnabledMap.get(PolicyType.RequireSso) ?? false) { if (policiesEnabledMap.get(PolicyType.RequireSso) ?? false) {
throw new Error( throw new Error(

View File

@ -35,6 +35,7 @@ export enum FeatureFlag {
PM11901_RefactorSelfHostingLicenseUploader = "PM-11901-refactor-self-hosting-license-uploader", PM11901_RefactorSelfHostingLicenseUploader = "PM-11901-refactor-self-hosting-license-uploader",
Pm3478RefactorOrganizationUserApi = "pm-3478-refactor-organizationuser-api", Pm3478RefactorOrganizationUserApi = "pm-3478-refactor-organizationuser-api",
AccessIntelligence = "pm-13227-access-intelligence", AccessIntelligence = "pm-13227-access-intelligence",
Pm13322AddPolicyDefinitions = "pm-13322-add-policy-definitions",
} }
export type AllowedFeatureFlagTypes = boolean | number | string; export type AllowedFeatureFlagTypes = boolean | number | string;
@ -80,6 +81,7 @@ export const DefaultFeatureFlagValue = {
[FeatureFlag.PM11901_RefactorSelfHostingLicenseUploader]: FALSE, [FeatureFlag.PM11901_RefactorSelfHostingLicenseUploader]: FALSE,
[FeatureFlag.Pm3478RefactorOrganizationUserApi]: FALSE, [FeatureFlag.Pm3478RefactorOrganizationUserApi]: FALSE,
[FeatureFlag.AccessIntelligence]: FALSE, [FeatureFlag.AccessIntelligence]: FALSE,
[FeatureFlag.Pm13322AddPolicyDefinitions]: FALSE,
} satisfies Record<FeatureFlag, AllowedFeatureFlagTypes>; } satisfies Record<FeatureFlag, AllowedFeatureFlagTypes>;
export type DefaultFeatureFlagValueType = typeof DefaultFeatureFlagValue; export type DefaultFeatureFlagValueType = typeof DefaultFeatureFlagValue;