mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
[UI] Web Prefix (#9334)
* [UI] Change default web prefix - Adjust default from "platform" to "web" - Much more standard prefix * Cleanup * Fixes for playwright tests * Fix unit tests * Refactor base_url into getBaseUrl
This commit is contained in:
@ -33,8 +33,8 @@ class AllUserRequire2FAMiddleware(MiddlewareMixin):
|
||||
'api-token',
|
||||
# web platform urls
|
||||
'password_reset_confirm',
|
||||
'platform',
|
||||
'platform-wildcard',
|
||||
'web',
|
||||
'web-wildcard',
|
||||
'web-assets',
|
||||
]
|
||||
app_names = ['headless']
|
||||
|
@ -7,7 +7,6 @@ import os
|
||||
import random
|
||||
import shutil
|
||||
import string
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
@ -401,51 +400,33 @@ def get_custom_file(
|
||||
|
||||
|
||||
def get_frontend_settings(debug=True):
|
||||
"""Return a dictionary of settings for the frontend interface.
|
||||
|
||||
Note that the new config settings use the 'FRONTEND' key,
|
||||
whereas the legacy key was 'PUI' (platform UI) which is now deprecated
|
||||
"""
|
||||
# Legacy settings
|
||||
pui_settings = get_setting(
|
||||
'INVENTREE_PUI_SETTINGS', 'pui_settings', {}, typecast=dict
|
||||
)
|
||||
|
||||
if len(pui_settings) > 0:
|
||||
warnings.warn(
|
||||
"The 'INVENTREE_PUI_SETTINGS' key is deprecated. Please use 'INVENTREE_FRONTEND_SETTINGS' instead",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
"""Return a dictionary of settings for the frontend interface."""
|
||||
# New settings
|
||||
frontend_settings = get_setting(
|
||||
'INVENTREE_FRONTEND_SETTINGS', 'frontend_settings', {}, typecast=dict
|
||||
)
|
||||
|
||||
# Merge settings
|
||||
settings = {**pui_settings, **frontend_settings}
|
||||
|
||||
# Set the base URL
|
||||
if 'base_url' not in settings:
|
||||
settings['base_url'] = get_setting(
|
||||
'INVENTREE_FRONTEND_URL_BASE', 'frontend_url_base', 'platform'
|
||||
if 'base_url' not in frontend_settings:
|
||||
frontend_settings['base_url'] = (
|
||||
get_setting('INVENTREE_FRONTEND_URL_BASE', 'frontend_url_base', 'web')
|
||||
or 'web'
|
||||
)
|
||||
|
||||
# Set the server list
|
||||
settings['server_list'] = settings.get('server_list', [])
|
||||
frontend_settings['server_list'] = frontend_settings.get('server_list', [])
|
||||
|
||||
# Set the debug flag
|
||||
settings['debug'] = debug
|
||||
frontend_settings['debug'] = debug
|
||||
|
||||
if 'environment' not in settings:
|
||||
settings['environment'] = 'development' if debug else 'production'
|
||||
if 'environment' not in frontend_settings:
|
||||
frontend_settings['environment'] = 'development' if debug else 'production'
|
||||
|
||||
if (debug and 'show_server_selector' not in settings) or len(
|
||||
settings['server_list']
|
||||
if (debug and 'show_server_selector' not in frontend_settings) or len(
|
||||
frontend_settings['server_list']
|
||||
) == 0:
|
||||
# In debug mode, show server selector by default
|
||||
# If no servers are specified, show server selector
|
||||
settings['show_server_selector'] = True
|
||||
frontend_settings['show_server_selector'] = True
|
||||
|
||||
return settings
|
||||
return frontend_settings
|
||||
|
@ -1039,7 +1039,7 @@ def inheritors(
|
||||
|
||||
|
||||
def pui_url(subpath: str) -> str:
|
||||
"""Return the URL for a PUI subpath."""
|
||||
"""Return the URL for a web subpath."""
|
||||
if not subpath.startswith('/'):
|
||||
subpath = '/' + subpath
|
||||
return f'/{settings.FRONTEND_URL_BASE}{subpath}'
|
||||
|
@ -46,4 +46,4 @@ class ViewTests(InvenTreeTestCase):
|
||||
f'/accounts/login/?next=/&login={self.username}&password={self.password}'
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(response.url, '/platform')
|
||||
self.assertEqual(response.url, '/web')
|
||||
|
@ -31,7 +31,7 @@ class BuildTestSimple(InvenTreeTestCase):
|
||||
def test_url(self):
|
||||
"""Test URL lookup."""
|
||||
b1 = Build.objects.get(pk=1)
|
||||
self.assertEqual(b1.get_absolute_url(), '/platform/manufacturing/build-order/1')
|
||||
self.assertEqual(b1.get_absolute_url(), '/web/manufacturing/build-order/1')
|
||||
|
||||
def test_is_complete(self):
|
||||
"""Test build completion status."""
|
||||
|
@ -59,7 +59,7 @@ class CompanySimpleTest(TestCase):
|
||||
def test_company_url(self):
|
||||
"""Test the detail URL for a company."""
|
||||
c = Company.objects.get(pk=1)
|
||||
self.assertEqual(c.get_absolute_url(), '/platform/purchasing/manufacturer/1')
|
||||
self.assertEqual(c.get_absolute_url(), '/web/purchasing/manufacturer/1')
|
||||
|
||||
def test_image_renamer(self):
|
||||
"""Test the company image upload functionality."""
|
||||
|
@ -43,7 +43,7 @@ class OrderTest(TestCase, ExchangeRateMixin):
|
||||
for pk in range(1, 8):
|
||||
order = PurchaseOrder.objects.get(pk=pk)
|
||||
self.assertEqual(
|
||||
order.get_absolute_url(), f'/platform/purchasing/purchase-order/{pk}'
|
||||
order.get_absolute_url(), f'/web/purchasing/purchase-order/{pk}'
|
||||
)
|
||||
|
||||
self.assertEqual(order.reference, f'PO-{pk:04d}')
|
||||
|
@ -127,9 +127,7 @@ class CategoryTest(TestCase):
|
||||
|
||||
def test_url(self):
|
||||
"""Test that the PartCategory URL works."""
|
||||
self.assertEqual(
|
||||
self.capacitors.get_absolute_url(), '/platform/part/category/3'
|
||||
)
|
||||
self.assertEqual(self.capacitors.get_absolute_url(), '/web/part/category/3')
|
||||
|
||||
def test_part_count(self):
|
||||
"""Test that the Category part count works."""
|
||||
|
@ -245,7 +245,7 @@ class PartTest(TestCase):
|
||||
def test_attributes(self):
|
||||
"""Test Part attributes."""
|
||||
self.assertEqual(self.r1.name, 'R_2K2_0805')
|
||||
self.assertEqual(self.r1.get_absolute_url(), '/platform/part/3')
|
||||
self.assertEqual(self.r1.get_absolute_url(), '/web/part/3')
|
||||
|
||||
def test_category(self):
|
||||
"""Test PartCategory path."""
|
||||
|
@ -285,7 +285,7 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase):
|
||||
response.data['stocklocation']['api_url'], '/api/stock/location/5/'
|
||||
)
|
||||
self.assertEqual(
|
||||
response.data['stocklocation']['web_url'], '/platform/stock/location/5'
|
||||
response.data['stocklocation']['web_url'], '/web/stock/location/5'
|
||||
)
|
||||
self.assertEqual(response.data['plugin'], 'InvenTreeBarcode')
|
||||
|
||||
@ -327,7 +327,7 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase):
|
||||
response.data['stocklocation']['api_url'], '/api/stock/location/5/'
|
||||
)
|
||||
self.assertEqual(
|
||||
response.data['stocklocation']['web_url'], '/platform/stock/location/5'
|
||||
response.data['stocklocation']['web_url'], '/web/stock/location/5'
|
||||
)
|
||||
self.assertEqual(response.data['plugin'], 'InvenTreeBarcode')
|
||||
|
||||
|
@ -175,8 +175,8 @@ class ReportTagTest(PartImageTestMixin, InvenTreeTestCase):
|
||||
# Test might return one of two results, depending on test env
|
||||
# If INVENTREE_SITE_URL is not set in the CI environment, the link will be relative
|
||||
options = [
|
||||
f'<a href="http://localhost:8000/platform/part/{obj.pk}">test</a>',
|
||||
f'<a href="/platform/part/{obj.pk}">test</a>',
|
||||
f'<a href="http://localhost:8000/web/part/{obj.pk}">test</a>',
|
||||
f'<a href="/web/part/{obj.pk}">test</a>',
|
||||
]
|
||||
|
||||
self.assertIn(link, options)
|
||||
|
@ -262,8 +262,8 @@ class StockTest(StockTestBase):
|
||||
def test_url(self):
|
||||
"""Test get_absolute_url function."""
|
||||
it = StockItem.objects.get(pk=2)
|
||||
self.assertEqual(it.get_absolute_url(), '/platform/stock/item/2')
|
||||
self.assertEqual(self.home.get_absolute_url(), '/platform/stock/location/1')
|
||||
self.assertEqual(it.get_absolute_url(), '/web/stock/item/2')
|
||||
self.assertEqual(self.home.get_absolute_url(), '/web/stock/location/1')
|
||||
|
||||
def test_strings(self):
|
||||
"""Test str function."""
|
||||
|
@ -273,7 +273,7 @@ class GetAuthToken(GenericAPIView):
|
||||
|
||||
data = {'token': token.key, 'name': token.name, 'expiry': token.expiry}
|
||||
|
||||
# Ensure that the users session is logged in (PUI -> CUI login)
|
||||
# Ensure that the users session is logged in
|
||||
if not get_user(request).is_authenticated:
|
||||
login(
|
||||
request, user, backend='django.contrib.auth.backends.ModelBackend'
|
||||
|
@ -113,7 +113,7 @@ class UserAPITests(InvenTreeAPITestCase):
|
||||
def test_login_redirect(self):
|
||||
"""Test login redirect endpoint."""
|
||||
response = self.get(reverse('api-login-redirect'), expected_code=302)
|
||||
self.assertEqual(response.url, '/platform/logged-in/')
|
||||
self.assertEqual(response.url, '/web/logged-in/')
|
||||
|
||||
|
||||
class UserTokenTests(InvenTreeAPITestCase):
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""Tests for PUI backend stuff."""
|
||||
"""Tests for web backend functionality."""
|
||||
|
||||
import json
|
||||
import os
|
||||
@ -68,7 +68,7 @@ class TemplateTagTest(InvenTreeTestCase):
|
||||
self.assertSettings(rsp)
|
||||
|
||||
# No base_url
|
||||
envs = {'INVENTREE_PUI_URL_BASE': ''}
|
||||
envs = {'INVENTREE_FRONTEND_URL_BASE': ''}
|
||||
with mock.patch.dict(os.environ, envs):
|
||||
rsp = get_frontend_settings()
|
||||
self.assertSettings(rsp)
|
||||
@ -79,7 +79,9 @@ class TemplateTagTest(InvenTreeTestCase):
|
||||
self.assertTrue(rsp['show_server_selector'])
|
||||
|
||||
# No debug, serverlist -> no selector
|
||||
envs = {'INVENTREE_PUI_SETTINGS': json.dumps({'server_list': ['aa', 'bb']})}
|
||||
envs = {
|
||||
'INVENTREE_FRONTEND_SETTINGS': json.dumps({'server_list': ['aa', 'bb']})
|
||||
}
|
||||
with mock.patch.dict(os.environ, envs):
|
||||
rsp = get_frontend_settings(False)
|
||||
self.assertNotIn('show_server_selector', rsp)
|
||||
|
@ -16,8 +16,8 @@ urlpatterns = [
|
||||
spa_view,
|
||||
name='password_reset_confirm',
|
||||
),
|
||||
re_path('.*', spa_view, name='platform-wildcard'),
|
||||
re_path('.*', spa_view, name='web-wildcard'),
|
||||
]),
|
||||
),
|
||||
path(settings.FRONTEND_URL_BASE, spa_view, name='platform'),
|
||||
path(settings.FRONTEND_URL_BASE, spa_view, name='web'),
|
||||
]
|
||||
|
Reference in New Issue
Block a user