From e554cf2a58cda827d8baed3c1cdb612c3b6597c9 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Thu, 29 Jan 2026 10:50:05 +0100 Subject: [PATCH] feat(frontend): disable_theme_storage (#11208) * feat(frontend): disable_theme_storage * bump API version * fix access pattern --- src/backend/InvenTree/InvenTree/api.py | 6 +++++- src/backend/InvenTree/InvenTree/api_version.py | 5 ++++- src/backend/InvenTree/config_template.yaml | 1 + src/frontend/src/functions/auth.tsx | 10 ++++++++++ src/frontend/src/states/states.tsx | 1 + 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/backend/InvenTree/InvenTree/api.py b/src/backend/InvenTree/InvenTree/api.py index 9f61ade0aa..fa341a90d3 100644 --- a/src/backend/InvenTree/InvenTree/api.py +++ b/src/backend/InvenTree/InvenTree/api.py @@ -34,7 +34,7 @@ from plugin.serializers import MetadataSerializer from users.models import ApiToken from users.permissions import check_user_permission, prefetch_rule_sets -from .helpers import plugins_info +from .helpers import plugins_info, str2bool from .helpers_email import is_email_configured from .mixins import ListAPI, RetrieveUpdateAPI from .status import check_system_health, is_worker_running @@ -238,6 +238,7 @@ class InfoApiSerializer(serializers.Serializer): splash = serializers.CharField() login_message = serializers.CharField(allow_null=True) navbar_message = serializers.CharField(allow_null=True) + disable_theme_storage = serializers.BooleanField(default=False) server = serializers.CharField(read_only=True) id = serializers.CharField(read_only=True, allow_null=True) @@ -310,6 +311,9 @@ class InfoView(APIView): 'splash': helpers.getSplashScreen(), 'login_message': helpers.getCustomOption('login_message'), 'navbar_message': helpers.getCustomOption('navbar_message'), + 'disable_theme_storage': str2bool( + helpers.getCustomOption('disable_theme_storage') + ), }, 'active_plugins': plugins_info(), # Following fields are only available to staff users diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index e5375e2501..97c2697fc3 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,11 +1,14 @@ """InvenTree API version information.""" # InvenTree API version -INVENTREE_API_VERSION = 443 +INVENTREE_API_VERSION = 444 """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" INVENTREE_API_TEXT = """ +v444 -> 2026-01-27 : https://github.com/inventree/InvenTree/pull/11208 + - Add customize option to disable theme loading from user profile (mainly for demo site use) + v443 -> 2026-01-21 : https://github.com/inventree/InvenTree/pull/11177 - Adds IPN ordering option for BomItem API endpoint - Adds IPN ordering option for BuildLine API endpoint diff --git a/src/backend/InvenTree/config_template.yaml b/src/backend/InvenTree/config_template.yaml index 37ce2b8555..ab5f232127 100644 --- a/src/backend/InvenTree/config_template.yaml +++ b/src/backend/InvenTree/config_template.yaml @@ -227,6 +227,7 @@ ldap: # navbar_message:
InvenTree demo mode
# hide_admin_link: true # hide_password_reset: true +# disable_theme_storage: true # logo: img/custom_logo.png # splash: img/custom_splash.jpg diff --git a/src/frontend/src/functions/auth.tsx b/src/frontend/src/functions/auth.tsx index ae3c481e57..e2e58d4da4 100644 --- a/src/frontend/src/functions/auth.tsx +++ b/src/frontend/src/functions/auth.tsx @@ -270,7 +270,15 @@ function observeProfile() { const user = useUserState.getState().getUser(); const { language, setLanguage, userTheme, setTheme, setWidgets, setLayouts } = useLocalState.getState(); + const { server } = useServerApiState.getState(); //(useShallow((state) => [state.server])); + + // fast exit if loading is disabled for this server + if (server.customize?.disable_theme_storage) { + return; + } + if (user) { + // set profile language if (user.profile?.language && language != user.profile.language) { showNotification({ title: t`Language changed`, @@ -281,6 +289,7 @@ function observeProfile() { setLanguage(user.profile.language, true); } + // set profile theme if (user.profile?.theme) { // extract keys of usertheme and set them to the values of user.profile.theme const newTheme = Object.keys(userTheme).map((key) => { @@ -302,6 +311,7 @@ function observeProfile() { } } + // set profile widgets/layouts if (user.profile?.widgets) { const data = user.profile.widgets; // split data into widgets and layouts (either might be undefined) diff --git a/src/frontend/src/states/states.tsx b/src/frontend/src/states/states.tsx index 8369e66631..42b5f23b1d 100644 --- a/src/frontend/src/states/states.tsx +++ b/src/frontend/src/states/states.tsx @@ -37,6 +37,7 @@ export interface ServerAPIProps { splash: string; login_message: string; navbar_message: string; + disable_theme_storage: boolean; }; }