mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-24 21:41:33 +01:00
refactor getOrgPolicies call
This commit is contained in:
parent
688a24bd52
commit
97f9008b60
@ -8,7 +8,6 @@ import { InternalPolicyService } from "@bitwarden/common/admin-console/abstracti
|
||||
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
|
||||
import { OrganizationInvite } from "../../../../../../../../libs/auth/src/common/models/domain/organization-invite";
|
||||
import { RouterService } from "../../../../core/router.service";
|
||||
import { AcceptOrganizationInviteService } from "../../../organization-invite/accept-organization.service";
|
||||
|
||||
@ -23,44 +22,44 @@ export class WebLoginService extends DefaultLoginService implements LoginService
|
||||
this.routerService.setPreviousUrl(route.toString());
|
||||
}
|
||||
|
||||
async getOrganizationInvite(): Promise<OrganizationInvite | null> {
|
||||
return await this.acceptOrganizationInviteService.getOrganizationInvite();
|
||||
}
|
||||
async getOrgPolicies(): Promise<PasswordPolicies | null> {
|
||||
const orgInvite = await this.acceptOrganizationInviteService.getOrganizationInvite();
|
||||
|
||||
async getPasswordPolicies(invite: OrganizationInvite): Promise<PasswordPolicies> {
|
||||
let policies: Policy[];
|
||||
if (orgInvite != null) {
|
||||
let policies: Policy[];
|
||||
|
||||
try {
|
||||
policies = await this.policyApiService.getPoliciesByToken(
|
||||
invite.organizationId,
|
||||
invite.token,
|
||||
invite.email,
|
||||
invite.organizationUserId,
|
||||
try {
|
||||
policies = await this.policyApiService.getPoliciesByToken(
|
||||
orgInvite.organizationId,
|
||||
orgInvite.token,
|
||||
orgInvite.email,
|
||||
orgInvite.organizationUserId,
|
||||
);
|
||||
} catch (e) {
|
||||
this.logService.error(e);
|
||||
}
|
||||
|
||||
if (policies == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const resetPasswordPolicy = this.policyService.getResetPasswordPolicyOptions(
|
||||
policies,
|
||||
orgInvite.organizationId,
|
||||
);
|
||||
} catch (e) {
|
||||
this.logService.error(e);
|
||||
|
||||
const isPolicyAndAutoEnrollEnabled =
|
||||
resetPasswordPolicy[1] && resetPasswordPolicy[0].autoEnrollEnabled;
|
||||
|
||||
const enforcedPasswordPolicyOptions = await firstValueFrom(
|
||||
this.policyService.masterPasswordPolicyOptions$(policies),
|
||||
);
|
||||
|
||||
return {
|
||||
policies,
|
||||
isPolicyAndAutoEnrollEnabled,
|
||||
enforcedPasswordPolicyOptions,
|
||||
};
|
||||
}
|
||||
|
||||
if (policies == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const resetPasswordPolicy = this.policyService.getResetPasswordPolicyOptions(
|
||||
policies,
|
||||
invite.organizationId,
|
||||
);
|
||||
|
||||
const isPolicyAndAutoEnrollEnabled =
|
||||
resetPasswordPolicy[1] && resetPasswordPolicy[0].autoEnrollEnabled;
|
||||
|
||||
const enforcedPasswordPolicyOptions = await firstValueFrom(
|
||||
this.policyService.masterPasswordPolicyOptions$(policies),
|
||||
);
|
||||
|
||||
return {
|
||||
policies,
|
||||
isPolicyAndAutoEnrollEnabled,
|
||||
enforcedPasswordPolicyOptions,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/sym
|
||||
import { CsprngArray } from "@bitwarden/common/types/csprng";
|
||||
import { MasterKey, UserKey } from "@bitwarden/common/types/key";
|
||||
|
||||
import { OrganizationInvite } from "../../../../../../../../libs/auth/src/common/models/domain/organization-invite";
|
||||
import { AcceptOrganizationInviteService } from "../../../organization-invite/accept-organization.service";
|
||||
import { OrganizationInvite } from "../../../organization-invite/organization-invite";
|
||||
|
||||
import { WebRegistrationFinishService } from "./web-registration-finish.service";
|
||||
|
||||
|
@ -10,6 +10,7 @@ import {
|
||||
LoginStrategyServiceAbstraction,
|
||||
LoginEmailServiceAbstraction,
|
||||
RegisterRouteService,
|
||||
OrganizationInvite,
|
||||
} from "@bitwarden/auth/common";
|
||||
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
||||
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||
@ -30,7 +31,6 @@ import { StateService } from "@bitwarden/common/platform/abstractions/state.serv
|
||||
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
||||
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||
|
||||
import { OrganizationInvite } from "../../../../../../libs/auth/src/common/models/domain/organization-invite";
|
||||
import { flagEnabled } from "../../../utils/flags";
|
||||
import { RouterService } from "../../core";
|
||||
import { AcceptOrganizationInviteService } from "../organization-invite/accept-organization.service";
|
||||
|
@ -7,10 +7,10 @@ import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
|
||||
import { OrganizationInvite } from "../../../../../../libs/auth/src/common/models/domain/organization-invite";
|
||||
import { BaseAcceptComponent } from "../../common/base.accept.component";
|
||||
|
||||
import { AcceptOrganizationInviteService } from "./accept-organization.service";
|
||||
import { OrganizationInvite } from "./organization-invite";
|
||||
|
||||
@Component({
|
||||
templateUrl: "accept-organization.component.html",
|
||||
|
@ -17,13 +17,13 @@ import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
||||
import { FakeGlobalState } from "@bitwarden/common/spec/fake-state";
|
||||
import { OrgKey } from "@bitwarden/common/types/key";
|
||||
|
||||
import { OrganizationInvite } from "../../../../../../libs/auth/src/common/models/domain/organization-invite";
|
||||
import { I18nService } from "../../core/i18n.service";
|
||||
|
||||
import {
|
||||
AcceptOrganizationInviteService,
|
||||
ORGANIZATION_INVITE,
|
||||
} from "./accept-organization.service";
|
||||
import { OrganizationInvite } from "./organization-invite";
|
||||
|
||||
describe("AcceptOrganizationInviteService", () => {
|
||||
let sut: AcceptOrganizationInviteService;
|
||||
|
@ -27,7 +27,7 @@ import {
|
||||
} from "@bitwarden/common/platform/state";
|
||||
import { OrgKey } from "@bitwarden/common/types/key";
|
||||
|
||||
import { OrganizationInvite } from "../../../../../../libs/auth/src/common/models/domain/organization-invite";
|
||||
import { OrganizationInvite } from "./organization-invite";
|
||||
|
||||
// We're storing the organization invite for 2 reasons:
|
||||
// 1. If the org requires a MP policy check, we need to keep track that the user has already been redirected when they return.
|
||||
|
@ -18,10 +18,10 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
||||
|
||||
import { OrganizationInvite } from "../../../../../../libs/auth/src/common/models/domain/organization-invite";
|
||||
import { RouterService } from "../../core";
|
||||
import { SharedModule } from "../../shared";
|
||||
import { AcceptOrganizationInviteService } from "../organization-invite/accept-organization.service";
|
||||
import { OrganizationInvite } from "../organization-invite/organization-invite";
|
||||
|
||||
import { TrialInitiationComponent } from "./trial-initiation.component";
|
||||
import { VerticalStepperComponent } from "./vertical-stepper/vertical-stepper.component";
|
||||
|
@ -14,13 +14,13 @@ import { ReferenceEventRequest } from "@bitwarden/common/models/request/referenc
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
|
||||
import { OrganizationInvite } from "../../../../../../libs/auth/src/common/models/domain/organization-invite";
|
||||
import {
|
||||
OrganizationCreatedEvent,
|
||||
SubscriptionProduct,
|
||||
TrialOrganizationType,
|
||||
} from "../../billing/accounts/trial-initiation/trial-billing-step.component";
|
||||
import { AcceptOrganizationInviteService } from "../organization-invite/accept-organization.service";
|
||||
import { OrganizationInvite } from "../organization-invite/organization-invite";
|
||||
|
||||
import { RouterService } from "./../../core/router.service";
|
||||
import { VerticalStepperComponent } from "./vertical-stepper/vertical-stepper.component";
|
||||
|
@ -1,7 +1,5 @@
|
||||
import { UrlTree } from "@angular/router";
|
||||
|
||||
import { OrganizationInvite } from "@bitwarden/auth/common";
|
||||
|
||||
import { LoginService, PasswordPolicies } from "./login.service";
|
||||
|
||||
export class DefaultLoginService implements LoginService {
|
||||
@ -9,11 +7,7 @@ export class DefaultLoginService implements LoginService {
|
||||
return null;
|
||||
}
|
||||
|
||||
async getOrganizationInvite(): Promise<OrganizationInvite | null> {
|
||||
return null;
|
||||
}
|
||||
|
||||
async getPasswordPolicies(invite: OrganizationInvite): Promise<PasswordPolicies | null> {
|
||||
async getOrgPolicies(): Promise<PasswordPolicies | null> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,9 @@ import { first, firstValueFrom, Subject, takeUntil } from "rxjs";
|
||||
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { LoginEmailServiceAbstraction } from "@bitwarden/auth/common";
|
||||
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
||||
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
|
||||
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
||||
import { ClientType } from "@bitwarden/common/enums";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import {
|
||||
AsyncActionsModule,
|
||||
@ -56,10 +53,7 @@ export class LoginComponentV2 implements OnInit {
|
||||
private formBuilder: FormBuilder,
|
||||
private loginEmailService: LoginEmailServiceAbstraction,
|
||||
private loginService: LoginService,
|
||||
private logService: LogService,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
private policyApiService: PolicyApiServiceAbstraction,
|
||||
private policyService: InternalPolicyService,
|
||||
private router: Router,
|
||||
) {
|
||||
this.clientType = this.platformUtilsService.getClientType();
|
||||
@ -93,15 +87,12 @@ export class LoginComponentV2 implements OnInit {
|
||||
|
||||
if (this.clientType === ClientType.Web) {
|
||||
// If there's an existing org invite, use it to get the password policies
|
||||
const orgInvite = await this.loginService.getOrganizationInvite();
|
||||
if (orgInvite != null) {
|
||||
const { policies, isPolicyAndAutoEnrollEnabled, enforcedPasswordPolicyOptions } =
|
||||
await this.loginService.getPasswordPolicies(orgInvite);
|
||||
const { policies, isPolicyAndAutoEnrollEnabled, enforcedPasswordPolicyOptions } =
|
||||
await this.loginService.getOrgPolicies();
|
||||
|
||||
this.policies = policies;
|
||||
this.showResetPasswordAutoEnrollWarning = isPolicyAndAutoEnrollEnabled;
|
||||
this.enforcedPasswordPolicyOptions = enforcedPasswordPolicyOptions;
|
||||
}
|
||||
this.policies = policies;
|
||||
this.showResetPasswordAutoEnrollWarning = isPolicyAndAutoEnrollEnabled;
|
||||
this.enforcedPasswordPolicyOptions = enforcedPasswordPolicyOptions;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { UrlTree } from "@angular/router";
|
||||
|
||||
import { OrganizationInvite } from "@bitwarden/auth/common";
|
||||
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
|
||||
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
||||
|
||||
@ -12,7 +11,6 @@ export interface PasswordPolicies {
|
||||
|
||||
export abstract class LoginService {
|
||||
// Web specific
|
||||
getOrganizationInvite: () => Promise<OrganizationInvite | null>;
|
||||
getPasswordPolicies: (invite: OrganizationInvite) => Promise<PasswordPolicies | null>;
|
||||
getOrgPolicies: () => Promise<PasswordPolicies | null>;
|
||||
setPreviousUrl: (route: UrlTree) => void | null;
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
export * from "./organization-invite";
|
||||
export * from "./rotateable-key-set";
|
||||
export * from "./login-credentials";
|
||||
export * from "./user-decryption-options";
|
||||
|
Loading…
Reference in New Issue
Block a user