2
0
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:
Matthias Mair
2025-10-07 02:25:13 +02:00
committed by GitHub
parent ac6028b871
commit 13845c69da
2 changed files with 11 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ from error_report.middleware import ExceptionProcessor
from common.settings import get_global_setting
from InvenTree.AllUserRequire2FAMiddleware import AllUserRequire2FAMiddleware
from InvenTree.cache import create_session_cache, delete_session_cache
from InvenTree.config import CONFIG_LOOKUPS, inventreeInstaller
from users.models import ApiToken
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
pass
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)
return render(
request, 'config_error.html', {'error_message': msg}, status=500

View File

@@ -126,7 +126,7 @@ class MiddlewareTests(InvenTreeTestCase):
SITE_LAX_PROTOCOL_CHECK=False,
):
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):
"""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'))
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(
response, 'window.INVENTREE_SETTINGS', status_code=500
@@ -212,6 +214,6 @@ class MiddlewareTests(InvenTreeTestCase):
# Check that the correct step triggers the error message
self.assertContains(
response,
'INVE-E7: The used path `http://testserver` does not match',
'INVE-E7: The visited path `http://testserver` does not match',
status_code=500,
)