diff --git a/packages/web-pkg/src/services/passwordPolicy/passwordPolicy.ts b/packages/web-pkg/src/services/passwordPolicy/passwordPolicy.ts index 89635a60ccd..a01905993df 100644 --- a/packages/web-pkg/src/services/passwordPolicy/passwordPolicy.ts +++ b/packages/web-pkg/src/services/passwordPolicy/passwordPolicy.ts @@ -23,14 +23,17 @@ interface GeneratePasswordRules { } export class PasswordPolicyService { - private readonly capability: PasswordPolicyCapability private readonly language: Language + private capability: PasswordPolicyCapability private policy: PasswordPolicy private generatePasswordRules: GeneratePasswordRules - constructor({ store, language }: { store: Store; language: Language }) { - this.capability = get(store, 'getters.capabilities.password_policy', {}) + constructor({ language }: { language: Language }) { this.language = language + } + + public initialize(store: Store) { + this.capability = get(store, 'getters.capabilities.password_policy', {}) this.buildGeneratePasswordRules() this.buildPolicy() } diff --git a/packages/web-pkg/tests/unit/services/passwordPolicy.spec.ts b/packages/web-pkg/tests/unit/services/passwordPolicy.spec.ts index 31bbe83e2dc..dc2a4e03e93 100644 --- a/packages/web-pkg/tests/unit/services/passwordPolicy.spec.ts +++ b/packages/web-pkg/tests/unit/services/passwordPolicy.spec.ts @@ -43,7 +43,8 @@ describe('PasswordPolicyService', () => { ] ] ])('capability "%s"', (capability: PasswordPolicyCapability, expected: Array) => { - const { passwordPolicyService } = getWrapper(capability) + const { passwordPolicyService, store } = getWrapper(capability) + passwordPolicyService.initialize(store) expect(Object.keys((passwordPolicyService.getPolicy() as any).rules)).toEqual(expected) }) }) @@ -100,7 +101,8 @@ describe('PasswordPolicyService', () => { passwords: Array, expected: Array ) => { - const { passwordPolicyService } = getWrapper(capability) + const { passwordPolicyService, store } = getWrapper(capability) + passwordPolicyService.initialize(store) const policy = passwordPolicyService.getPolicy() for (let i = 0; i < passwords.length; i++) { expect((policy as any).check(passwords[i])).toEqual(expected[i]) @@ -119,8 +121,8 @@ const getWrapper = (capability: PasswordPolicyCapability) => { }) const store = createStore(storeOptions) return { + store, passwordPolicyService: new PasswordPolicyService({ - store, language: { current: 'en' } as Language }) } diff --git a/packages/web-runtime/src/container/bootstrap.ts b/packages/web-runtime/src/container/bootstrap.ts index a81c373b848..f82f35042eb 100644 --- a/packages/web-runtime/src/container/bootstrap.ts +++ b/packages/web-runtime/src/container/bootstrap.ts @@ -474,15 +474,9 @@ export const announceAuthService = ({ /** * @param vue */ -export const announcePasswordPolicyService = ({ - app, - store -}: { - app: App - store: Store -}): void => { +export const announcePasswordPolicyService = ({ app }: { app: App }): void => { const language = app.config.globalProperties.$language - const passwordPolicyService = new PasswordPolicyService({ store, language }) + const passwordPolicyService = new PasswordPolicyService({ language }) app.config.globalProperties.passwordPolicyService = passwordPolicyService app.provide('$passwordPolicyService', passwordPolicyService) } diff --git a/packages/web-runtime/src/index.ts b/packages/web-runtime/src/index.ts index 352d6225e78..76cb96e0109 100644 --- a/packages/web-runtime/src/index.ts +++ b/packages/web-runtime/src/index.ts @@ -90,6 +90,7 @@ export const bootstrapApp = async (configurationPath: string): Promise => app.provide('$archiverService', app.config.globalProperties.$archiverService) announceLoadingService({ app }) announcePreviewService({ app, store, configurationManager }) + announcePasswordPolicyService({ app }) await announceClient(runtimeConfiguration) app.config.globalProperties.$wormhole = createWormhole() @@ -165,9 +166,9 @@ export const bootstrapApp = async (configurationPath: string): Promise => return } - announcePasswordPolicyService({ app, store }) - const clientService = app.config.globalProperties.$clientService + const passwordPolicyService = app.config.globalProperties.passwordPolicyService + passwordPolicyService.initialize(store) // Register SSE event listeners if (store.getters.capabilities?.core?.['support-sse']) {