From b335728e298f985f9a086749f3ee2b33ab57f3ad Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 21 Oct 2023 22:12:14 +1100 Subject: [PATCH] Fix admin site - Custom admin URL (#5766) * Update config template file * Add entry to docs * Add INVENTREE_ADMIN_ENABLED to settings.py * Add helper functions for improving admin links * Refactor existing admin links * remove debug statements * Fix custom admin URL * Expand documentation * Fix URL * Improve wording in config_template.yaml * Extend admin_url tag - Allow lookup without pk - Handle case where pk not found --- InvenTree/InvenTree/settings.py | 21 ++++---- InvenTree/InvenTree/urls.py | 13 +++-- .../build/templates/build/build_base.html | 5 +- .../templates/company/company_base.html | 5 +- .../templates/company/manufacturer_part.html | 6 +-- .../templates/company/supplier_part.html | 5 +- InvenTree/config_template.yaml | 8 +++ .../order/templates/order/order_base.html | 6 +-- .../templates/order/return_order_base.html | 5 +- .../templates/order/sales_order_base.html | 5 +- InvenTree/part/templates/part/category.html | 5 +- InvenTree/part/templates/part/part_base.html | 4 +- .../part/templatetags/inventree_extras.py | 51 ++++++++++++++++++- InvenTree/plugin/registry.py | 8 ++- .../stock/templates/stock/item_base.html | 5 +- InvenTree/stock/templates/stock/location.html | 5 +- .../templates/InvenTree/settings/plugin.html | 2 +- InvenTree/templates/admin_button.html | 2 +- InvenTree/templates/navbar.html | 5 +- .../templates/registration/logged_out.html | 3 +- docs/docs/start/config.md | 14 ++++- 21 files changed, 130 insertions(+), 53 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 5630adf282..206b4a697b 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -197,7 +197,18 @@ if DBBACKUP_STORAGE_OPTIONS is None: 'location': config.get_backup_dir(), } -# Application definition +INVENTREE_ADMIN_ENABLED = get_boolean_setting( + 'INVENTREE_ADMIN_ENABLED', + config_key='admin_enabled', + default_value=True +) + +# Base URL for admin pages (default="admin") +INVENTREE_ADMIN_URL = get_setting( + 'INVENTREE_ADMIN_URL', + config_key='admin_url', + default_value='admin' +) INSTALLED_APPS = [ # Admin site integration @@ -378,14 +389,6 @@ if DEBUG: INSTALLED_APPS.append('sslserver') # InvenTree URL configuration - -# Base URL for admin pages (default="admin") -INVENTREE_ADMIN_URL = get_setting( - 'INVENTREE_ADMIN_URL', - config_key='admin_url', - default_value='admin' -) - ROOT_URLCONF = 'InvenTree.urls' TEMPLATES = [ diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 742848c328..b55bf78fbb 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -209,11 +209,14 @@ classic_frontendpatterns = [ new_frontendpatterns = platform_urls -urlpatterns = [ - # admin sites - re_path(f'^{settings.INVENTREE_ADMIN_URL}/error_log/', include('error_report.urls')), - re_path(f'^{settings.INVENTREE_ADMIN_URL}/', admin.site.urls, name='inventree-admin'), -] +urlpatterns = [] + +if settings.INVENTREE_ADMIN_ENABLED: + admin_url = settings.INVENTREE_ADMIN_URL, + urlpatterns += [ + path(f'{admin_url}/error_log/', include('error_report.urls')), + path(f'{admin_url}/', admin.site.urls, name='inventree-admin'), + ] urlpatterns += backendpatterns diff --git a/InvenTree/build/templates/build/build_base.html b/InvenTree/build/templates/build/build_base.html index 2f1ea421b6..3eb50e1270 100644 --- a/InvenTree/build/templates/build/build_base.html +++ b/InvenTree/build/templates/build/build_base.html @@ -29,10 +29,9 @@ src="{% static 'img/blank_image.png' %}" {% block actions %} -{% if user.is_staff and roles.build.change %} -{% url 'admin:build_build_change' build.pk as url %} +{% admin_url user "build.build" build.pk as url %} {% include "admin_button.html" with url=url %} -{% endif %} + {% if barcodes %}
diff --git a/InvenTree/company/templates/company/company_base.html b/InvenTree/company/templates/company/company_base.html index 7953635671..238c53847e 100644 --- a/InvenTree/company/templates/company/company_base.html +++ b/InvenTree/company/templates/company/company_base.html @@ -14,10 +14,9 @@ {% block actions %} -{% if user.is_staff and perms.company.change_company %} -{% url 'admin:company_company_change' company.pk as url %} +{% admin_url user "company.company" company.pk as url %} {% include "admin_button.html" with url=url %} -{% endif %} + {% if company.is_supplier and roles.purchase_order.add %} diff --git a/InvenTree/templates/admin_button.html b/InvenTree/templates/admin_button.html index abc3d2d91c..9f0e8acfbc 100644 --- a/InvenTree/templates/admin_button.html +++ b/InvenTree/templates/admin_button.html @@ -3,7 +3,7 @@ {% inventree_customize 'hide_admin_link' as hidden %} -{% if not hidden and user.is_staff %} +{% if url and not hidden and user.is_staff %}