From e1dcf2e8591c3a7482ba35b243ef1b2c88505420 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 7 May 2024 18:39:50 +0200 Subject: [PATCH] feat: do not save language on the server when in demo mode When the demo mode is enabled, people set the language to their own language - which is understandable. However, this is really confusing for other people when they log in and the language is something unexpected. This change overrides the configured language when saving it while Vikunja is in demo mode. --- frontend/src/modelTypes/IUserSettings.ts | 2 +- frontend/src/stores/auth.ts | 25 +++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/frontend/src/modelTypes/IUserSettings.ts b/frontend/src/modelTypes/IUserSettings.ts index 3358acab9..5f20e3852 100644 --- a/frontend/src/modelTypes/IUserSettings.ts +++ b/frontend/src/modelTypes/IUserSettings.ts @@ -22,6 +22,6 @@ export interface IUserSettings extends IAbstract { defaultProjectId: undefined | IProject['id'] weekStart: 0 | 1 | 2 | 3 | 4 | 5 | 6 timezone: string - language: SupportedLocale + language: SupportedLocale | null frontendSettings: IFrontendSettings } \ No newline at end of file diff --git a/frontend/src/stores/auth.ts b/frontend/src/stores/auth.ts index e7d25a8a4..a6a69d418 100644 --- a/frontend/src/stores/auth.ts +++ b/frontend/src/stores/auth.ts @@ -37,6 +37,8 @@ function redirectToProviderIfNothingElseIsEnabled() { } export const useAuthStore = defineStore('auth', () => { + const configStore = useConfigStore() + const authenticated = ref(false) const isLinkShareAuth = ref(false) const needsTotpPasscode = ref(false) @@ -185,8 +187,7 @@ export const useAuthStore = defineStore('auth', () => { const HTTP = HTTPFactory() setIsLoading(true) - const {auth} = useConfigStore() - const fullProvider: IProvider = auth.openidConnect.providers.find((p: IProvider) => p.key === provider) + const fullProvider: IProvider = configStore.auth.openidConnect.providers.find((p: IProvider) => p.key === provider) const data = { code: code, @@ -357,8 +358,15 @@ export const useAuthStore = defineStore('auth', () => { const cancel = setModuleLoading(setIsLoadingGeneralSettings) try { - const updateSettingsPromise = userSettingsService.update(settings) - setUserSettings({...settings}) + let settingsUpdate = {...settings} + if (configStore.demoModeEnabled) { + settingsUpdate = { + ...settingsUpdate, + language: null, + } + } + const updateSettingsPromise = userSettingsService.update(settingsUpdate) + setUserSettings(settingsUpdate) await setLanguage(settings.language) await updateSettingsPromise if (showMessage) { @@ -403,13 +411,12 @@ export const useAuthStore = defineStore('auth', () => { await checkAuth() // if configured, redirect to OIDC Provider on logout - const {auth} = useConfigStore() if ( - auth.local.enabled === false && - auth.openidConnect.enabled && - auth.openidConnect.providers?.length === 1) + configStore.auth.local.enabled === false && + configStore.auth.openidConnect.enabled && + configStore.auth.openidConnect.providers?.length === 1) { - redirectToProviderOnLogout(auth.openidConnect.providers[0]) + redirectToProviderOnLogout(configStore.auth.openidConnect.providers[0]) } }