mirror of
https://github.com/inventree/InvenTree.git
synced 2025-10-14 21:22:20 +00:00
feat(backend): Improve error message on INVE-7 (#10518)
* feat(backend): Improve error message on INVE-7 * change wording * fix test * another fix
This commit is contained in:
@@ -17,6 +17,7 @@ from error_report.middleware import ExceptionProcessor
|
|||||||
from common.settings import get_global_setting
|
from common.settings import get_global_setting
|
||||||
from InvenTree.AllUserRequire2FAMiddleware import AllUserRequire2FAMiddleware
|
from InvenTree.AllUserRequire2FAMiddleware import AllUserRequire2FAMiddleware
|
||||||
from InvenTree.cache import create_session_cache, delete_session_cache
|
from InvenTree.cache import create_session_cache, delete_session_cache
|
||||||
|
from InvenTree.config import CONFIG_LOOKUPS, inventreeInstaller
|
||||||
from users.models import ApiToken
|
from users.models import ApiToken
|
||||||
|
|
||||||
logger = structlog.get_logger('inventree')
|
logger = structlog.get_logger('inventree')
|
||||||
@@ -252,7 +253,11 @@ class InvenTreeHostSettingsMiddleware(MiddlewareMixin):
|
|||||||
# The used url might not be the primary url - next check determines if in a trusted origins
|
# The used url might not be the primary url - next check determines if in a trusted origins
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
msg = f'INVE-E7: The used path `{accessed_scheme}` does not match the SITE_URL `{settings.SITE_URL}`'
|
source = CONFIG_LOOKUPS.get('INVENTREE_SITE_URL', {}).get(
|
||||||
|
'source', 'unknown'
|
||||||
|
)
|
||||||
|
dpl_method = inventreeInstaller()
|
||||||
|
msg = f'INVE-E7: The visited path `{accessed_scheme}` does not match the SITE_URL `{settings.SITE_URL}`. The INVENTREE_SITE_URL is set via `{source}` config method - deployment method `{dpl_method}`'
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
return render(
|
return render(
|
||||||
request, 'config_error.html', {'error_message': msg}, status=500
|
request, 'config_error.html', {'error_message': msg}, status=500
|
||||||
|
@@ -126,7 +126,7 @@ class MiddlewareTests(InvenTreeTestCase):
|
|||||||
SITE_LAX_PROTOCOL_CHECK=False,
|
SITE_LAX_PROTOCOL_CHECK=False,
|
||||||
):
|
):
|
||||||
response = self.client.get(reverse('web'))
|
response = self.client.get(reverse('web'))
|
||||||
self.assertContains(response, 'INVE-E7: The used path', status_code=500)
|
self.assertContains(response, 'INVE-E7: The visited path', status_code=500)
|
||||||
|
|
||||||
def test_site_url_checks_multi(self):
|
def test_site_url_checks_multi(self):
|
||||||
"""Test that the site URL check is correctly working in a multi-site setup."""
|
"""Test that the site URL check is correctly working in a multi-site setup."""
|
||||||
@@ -194,7 +194,9 @@ class MiddlewareTests(InvenTreeTestCase):
|
|||||||
):
|
):
|
||||||
response = self.client.get(reverse('web'))
|
response = self.client.get(reverse('web'))
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
response, 'INVE-E7: The used path `http://testserver` ', status_code=500
|
response,
|
||||||
|
'INVE-E7: The visited path `http://testserver` ',
|
||||||
|
status_code=500,
|
||||||
)
|
)
|
||||||
self.assertNotContains(
|
self.assertNotContains(
|
||||||
response, 'window.INVENTREE_SETTINGS', status_code=500
|
response, 'window.INVENTREE_SETTINGS', status_code=500
|
||||||
@@ -212,6 +214,6 @@ class MiddlewareTests(InvenTreeTestCase):
|
|||||||
# Check that the correct step triggers the error message
|
# Check that the correct step triggers the error message
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
response,
|
response,
|
||||||
'INVE-E7: The used path `http://testserver` does not match',
|
'INVE-E7: The visited path `http://testserver` does not match',
|
||||||
status_code=500,
|
status_code=500,
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user