mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
[P UI] Make base url configurable (#5577)
* made url_base configurable for P UI * fixed test for configurable base url
This commit is contained in:
@ -64,7 +64,7 @@ class AuthRequiredMiddleware(object):
|
||||
elif request.path_info.startswith('/accounts/'):
|
||||
authorized = True
|
||||
|
||||
elif request.path_info.startswith('/platform/') or request.path_info.startswith('/assets/') or request.path_info == '/platform':
|
||||
elif request.path_info.startswith(f'/{settings.PUI_URL_BASE}/') or request.path_info.startswith('/assets/') or request.path_info == f'/{settings.PUI_URL_BASE}':
|
||||
authorized = True
|
||||
|
||||
elif 'Authorization' in request.headers.keys() or 'authorization' in request.headers.keys():
|
||||
|
@ -606,11 +606,6 @@ DATABASES = {
|
||||
REMOTE_LOGIN = get_boolean_setting('INVENTREE_REMOTE_LOGIN', 'remote_login_enabled', False)
|
||||
REMOTE_LOGIN_HEADER = get_setting('INVENTREE_REMOTE_LOGIN_HEADER', 'remote_login_header', 'REMOTE_USER')
|
||||
|
||||
# Magic login django-sesame
|
||||
SESAME_MAX_AGE = 300
|
||||
# LOGIN_REDIRECT_URL = "/platform/logged-in/"
|
||||
LOGIN_REDIRECT_URL = "/index/"
|
||||
|
||||
# sentry.io integration for error reporting
|
||||
SENTRY_ENABLED = get_boolean_setting('INVENTREE_SENTRY_ENABLED', 'sentry_enabled', False)
|
||||
|
||||
@ -981,6 +976,7 @@ CUSTOM_SPLASH = get_custom_file('INVENTREE_CUSTOM_SPLASH', 'customize.splash', '
|
||||
CUSTOMIZE = get_setting('INVENTREE_CUSTOMIZE', 'customize', {})
|
||||
|
||||
# Frontend settings
|
||||
PUI_URL_BASE = get_setting('INVENTREE_PUI_URL_BASE', 'pui_url_base', 'platform')
|
||||
PUI_SETTINGS = get_setting("INVENTREE_PUI_SETTINGS", "pui_settings", {})
|
||||
|
||||
if DEBUG:
|
||||
@ -1008,3 +1004,8 @@ if CUSTOM_FLAGS:
|
||||
else:
|
||||
logger.info(f"Custom flags: {CUSTOM_FLAGS}")
|
||||
FLAGS.update(CUSTOM_FLAGS)
|
||||
|
||||
# Magic login django-sesame
|
||||
SESAME_MAX_AGE = 300
|
||||
# LOGIN_REDIRECT_URL = f"/{PUI_URL_BASE}/logged-in/"
|
||||
LOGIN_REDIRECT_URL = "/index/"
|
||||
|
@ -1211,6 +1211,6 @@ class MagicLoginTest(InvenTreeTestCase):
|
||||
self.assertEqual(resp.url, '/index/')
|
||||
# Note: 2023-08-08 - This test has been changed because "platform UI" is not generally available yet
|
||||
# TODO: In the future, the URL comparison will need to be reverted
|
||||
# self.assertEqual(resp.url, '/platform/logged-in/')
|
||||
# self.assertEqual(resp.url, f'/{settings.PUI_URL_BASE}/logged-in/')
|
||||
# And we should be logged in again
|
||||
self.assertEqual(resp.wsgi_request.user, self.user)
|
||||
|
@ -250,6 +250,8 @@ remote_login_header: HTTP_REMOTE_USER
|
||||
# show_server_selector: false
|
||||
# sentry_dsn: https://84f0c3ea90c64e5092e2bf5dfe325725@o1047628.ingest.sentry.io/4504160008273920
|
||||
# environment: development
|
||||
# Base URL for serving Platform UI
|
||||
# pui_url_base: 'platform'
|
||||
|
||||
# Custom flags
|
||||
# InvenTree uses django-flags; read more in their docs at https://cfpb.github.io/django-flags/conditions/
|
||||
|
@ -10,7 +10,11 @@ from django.utils.safestring import mark_safe
|
||||
logger = getLogger("InvenTree")
|
||||
register = template.Library()
|
||||
|
||||
PUI_SETTINGS = json.dumps(settings.PUI_SETTINGS)
|
||||
PUI_DEFAULTS = {
|
||||
'url_base': settings.PUI_URL_BASE,
|
||||
}
|
||||
PUI_DEFAULTS.update(getattr(settings, 'PUI_SETTINGS', {}))
|
||||
PUI_SETTINGS = json.dumps(PUI_DEFAULTS)
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
|
@ -20,12 +20,12 @@ spa_view = ensure_csrf_cookie(TemplateView.as_view(template_name="web/index.html
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('platform/', include([
|
||||
path(f'{settings.PUI_URL_BASE}/', include([
|
||||
path("assets/<path:path>", RedirectAssetView.as_view()),
|
||||
re_path(r"^(?P<path>.*)/$", spa_view),
|
||||
path("set-password?uid=<uid>&token=<token>", spa_view, name="password_reset_confirm"),
|
||||
path("", spa_view),]
|
||||
)),
|
||||
re_path(r'^platform', spa_view, name='platform'),
|
||||
path(settings.PUI_URL_BASE, spa_view, name='platform'),
|
||||
path("assets/<path:path>", RedirectAssetView.as_view()),
|
||||
]
|
||||
|
Reference in New Issue
Block a user