mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36: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:
parent
6c5b9e0108
commit
8432297d3c
@ -64,7 +64,7 @@ class AuthRequiredMiddleware(object):
|
|||||||
elif request.path_info.startswith('/accounts/'):
|
elif request.path_info.startswith('/accounts/'):
|
||||||
authorized = True
|
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
|
authorized = True
|
||||||
|
|
||||||
elif 'Authorization' in request.headers.keys() or 'authorization' in request.headers.keys():
|
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 = get_boolean_setting('INVENTREE_REMOTE_LOGIN', 'remote_login_enabled', False)
|
||||||
REMOTE_LOGIN_HEADER = get_setting('INVENTREE_REMOTE_LOGIN_HEADER', 'remote_login_header', 'REMOTE_USER')
|
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.io integration for error reporting
|
||||||
SENTRY_ENABLED = get_boolean_setting('INVENTREE_SENTRY_ENABLED', 'sentry_enabled', False)
|
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', {})
|
CUSTOMIZE = get_setting('INVENTREE_CUSTOMIZE', 'customize', {})
|
||||||
|
|
||||||
# Frontend settings
|
# Frontend settings
|
||||||
|
PUI_URL_BASE = get_setting('INVENTREE_PUI_URL_BASE', 'pui_url_base', 'platform')
|
||||||
PUI_SETTINGS = get_setting("INVENTREE_PUI_SETTINGS", "pui_settings", {})
|
PUI_SETTINGS = get_setting("INVENTREE_PUI_SETTINGS", "pui_settings", {})
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
@ -1008,3 +1004,8 @@ if CUSTOM_FLAGS:
|
|||||||
else:
|
else:
|
||||||
logger.info(f"Custom flags: {CUSTOM_FLAGS}")
|
logger.info(f"Custom flags: {CUSTOM_FLAGS}")
|
||||||
FLAGS.update(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/')
|
self.assertEqual(resp.url, '/index/')
|
||||||
# Note: 2023-08-08 - This test has been changed because "platform UI" is not generally available yet
|
# 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
|
# 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
|
# And we should be logged in again
|
||||||
self.assertEqual(resp.wsgi_request.user, self.user)
|
self.assertEqual(resp.wsgi_request.user, self.user)
|
||||||
|
@ -250,6 +250,8 @@ remote_login_header: HTTP_REMOTE_USER
|
|||||||
# show_server_selector: false
|
# show_server_selector: false
|
||||||
# sentry_dsn: https://84f0c3ea90c64e5092e2bf5dfe325725@o1047628.ingest.sentry.io/4504160008273920
|
# sentry_dsn: https://84f0c3ea90c64e5092e2bf5dfe325725@o1047628.ingest.sentry.io/4504160008273920
|
||||||
# environment: development
|
# environment: development
|
||||||
|
# Base URL for serving Platform UI
|
||||||
|
# pui_url_base: 'platform'
|
||||||
|
|
||||||
# Custom flags
|
# Custom flags
|
||||||
# InvenTree uses django-flags; read more in their docs at https://cfpb.github.io/django-flags/conditions/
|
# 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")
|
logger = getLogger("InvenTree")
|
||||||
register = template.Library()
|
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
|
@register.simple_tag
|
||||||
|
@ -20,12 +20,12 @@ spa_view = ensure_csrf_cookie(TemplateView.as_view(template_name="web/index.html
|
|||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('platform/', include([
|
path(f'{settings.PUI_URL_BASE}/', include([
|
||||||
path("assets/<path:path>", RedirectAssetView.as_view()),
|
path("assets/<path:path>", RedirectAssetView.as_view()),
|
||||||
re_path(r"^(?P<path>.*)/$", spa_view),
|
re_path(r"^(?P<path>.*)/$", spa_view),
|
||||||
path("set-password?uid=<uid>&token=<token>", spa_view, name="password_reset_confirm"),
|
path("set-password?uid=<uid>&token=<token>", spa_view, name="password_reset_confirm"),
|
||||||
path("", spa_view),]
|
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()),
|
path("assets/<path:path>", RedirectAssetView.as_view()),
|
||||||
]
|
]
|
||||||
|
@ -14,6 +14,7 @@ declare global {
|
|||||||
server_list: HostList;
|
server_list: HostList;
|
||||||
default_server: string;
|
default_server: string;
|
||||||
show_server_selector: boolean;
|
show_server_selector: boolean;
|
||||||
|
url_base: string;
|
||||||
sentry_dsn?: string;
|
sentry_dsn?: string;
|
||||||
environment?: string;
|
environment?: string;
|
||||||
};
|
};
|
||||||
@ -55,13 +56,15 @@ if (window.INVENTREE_SETTINGS.sentry_dsn) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const url_base = window.INVENTREE_SETTINGS.url_base || 'platform';
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
|
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<App />
|
<App />
|
||||||
</React.StrictMode>
|
</React.StrictMode>
|
||||||
);
|
);
|
||||||
|
|
||||||
// Redirect to /platform if on /
|
// Redirect to base url if on /
|
||||||
if (window.location.pathname === '/') {
|
if (window.location.pathname === '/') {
|
||||||
window.location.replace('/platform');
|
window.location.replace(`/${url_base}`);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import { BrowserRouter } from 'react-router-dom';
|
|||||||
import { queryClient, setApiDefaults } from '../App';
|
import { queryClient, setApiDefaults } from '../App';
|
||||||
import { BaseContext } from '../contexts/BaseContext';
|
import { BaseContext } from '../contexts/BaseContext';
|
||||||
import { defaultHostList } from '../defaults/defaultHostList';
|
import { defaultHostList } from '../defaults/defaultHostList';
|
||||||
|
import { url_base } from '../main';
|
||||||
import { routes } from '../router';
|
import { routes } from '../router';
|
||||||
import { useApiState } from '../states/ApiState';
|
import { useApiState } from '../states/ApiState';
|
||||||
import { useLocalState } from '../states/LocalState';
|
import { useLocalState } from '../states/LocalState';
|
||||||
@ -35,7 +36,7 @@ export default function DesktopAppView() {
|
|||||||
return (
|
return (
|
||||||
<BaseContext>
|
<BaseContext>
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<BrowserRouter basename="platform">{routes}</BrowserRouter>
|
<BrowserRouter basename={url_base}>{routes}</BrowserRouter>
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
</BaseContext>
|
</BaseContext>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user