From 143a531c1e631aa56cce72b99cf69620cd8b3fe1 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Wed, 25 Oct 2023 23:40:53 +0200 Subject: [PATCH] Revert "Merge branch 'master' of https://github.com/inventree/InvenTree into matmair/issue5729" This reverts commit 9b6e8fff8801a202379ce1244dd6b7d64f69520a, reversing changes made to 481cd70acadf8157b905cd8805840d82a7b293c6. --- InvenTree/InvenTree/api_version.py | 9 +- InvenTree/InvenTree/middleware.py | 14 +- InvenTree/InvenTree/settings.py | 27 +- 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 - InvenTree/locale/cs/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/da/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/de/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/el/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/en/LC_MESSAGES/django.po | 4319 ++++++++-------- InvenTree/locale/es/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/es_MX/LC_MESSAGES/django.po | 4319 ++++++++-------- InvenTree/locale/fa/LC_MESSAGES/django.po | 3457 ++++++------- InvenTree/locale/fi/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/fr/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/he/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/hi/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/hu/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/id/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/it/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/ja/LC_MESSAGES/django.po | 2916 ++++++----- InvenTree/locale/ko/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/nl/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/no/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/pl/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/pt/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/pt_br/LC_MESSAGES/django.po | 4319 ++++++++-------- InvenTree/locale/ru/LC_MESSAGES/django.po | 2730 +++++----- InvenTree/locale/sl/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/sv/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/th/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/tr/LC_MESSAGES/django.po | 2726 +++++----- InvenTree/locale/vi/LC_MESSAGES/django.po | 3126 ++++++------ InvenTree/locale/zh/LC_MESSAGES/django.po | 2726 +++++----- .../locale/zh_Hans/LC_MESSAGES/django.po | 4405 ++++++++--------- .../locale/zh_hant/LC_MESSAGES/django.po | 4319 ++++++++-------- .../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 | 82 +- InvenTree/plugin/registry.py | 8 +- InvenTree/stock/models.py | 5 +- .../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 +- InvenTree/users/admin.py | 22 +- InvenTree/users/api.py | 65 +- InvenTree/users/authentication.py | 39 - InvenTree/users/migrations/0008_apitoken.py | 35 - .../migrations/0009_auto_20231020_2356.py | 27 - InvenTree/users/models.py | 131 +- InvenTree/users/test_api.py | 105 - InvenTree/users/tests.py | 17 +- docs/docs/start/config.md | 14 +- .../src/components/nav/NotificationDrawer.tsx | 4 +- src/frontend/src/functions/auth.tsx | 12 +- src/frontend/src/locales/cs/messages.po | 961 ++-- src/frontend/src/locales/da/messages.po | 961 ++-- src/frontend/src/locales/de/messages.po | 788 +-- src/frontend/src/locales/el/messages.po | 961 ++-- src/frontend/src/locales/en/messages.po | 827 ++-- src/frontend/src/locales/es/messages.po | 854 ++-- src/frontend/src/locales/fa/messages.po | 848 ++-- src/frontend/src/locales/fi/messages.po | 848 ++-- src/frontend/src/locales/fr/messages.po | 786 +-- src/frontend/src/locales/he/messages.po | 848 ++-- src/frontend/src/locales/hi/messages.po | 848 ++-- src/frontend/src/locales/hu/messages.po | 831 ++-- src/frontend/src/locales/id/messages.po | 1996 ++++++++ src/frontend/src/locales/it/messages.po | 848 ++-- src/frontend/src/locales/ja/messages.po | 791 +-- src/frontend/src/locales/ko/messages.po | 848 ++-- src/frontend/src/locales/nl/messages.po | 848 ++-- src/frontend/src/locales/no/messages.po | 848 ++-- src/frontend/src/locales/pl/messages.po | 848 ++-- .../src/locales/pseudo-LOCALE/messages.po | 823 ++- src/frontend/src/locales/pt/messages.po | 803 +-- src/frontend/src/locales/ru/messages.po | 801 +-- src/frontend/src/locales/sl/messages.po | 848 ++-- src/frontend/src/locales/sv/messages.po | 786 +-- src/frontend/src/locales/th/messages.po | 961 ++-- src/frontend/src/locales/tr/messages.po | 979 ++-- src/frontend/src/locales/vi/messages.po | 1005 ++-- src/frontend/src/locales/zh/messages.po | 1996 ++++++++ src/frontend/src/pages/Index/Playground.tsx | 2 +- tasks.py | 2 +- 95 files changed, 61375 insertions(+), 59606 deletions(-) delete mode 100644 InvenTree/users/authentication.py delete mode 100644 InvenTree/users/migrations/0008_apitoken.py delete mode 100644 InvenTree/users/migrations/0009_auto_20231020_2356.py create mode 100644 src/frontend/src/locales/id/messages.po create mode 100644 src/frontend/src/locales/zh/messages.po diff --git a/InvenTree/InvenTree/api_version.py b/InvenTree/InvenTree/api_version.py index c3dd8a1897..14c180388c 100644 --- a/InvenTree/InvenTree/api_version.py +++ b/InvenTree/InvenTree/api_version.py @@ -2,18 +2,11 @@ # InvenTree API version -INVENTREE_API_VERSION = 141 +INVENTREE_API_VERSION = 139 """ Increment this API version number whenever there is a significant change to the API that any clients need to know about -v141 -> 2023-10-23 : https://github.com/inventree/InvenTree/pull/5774 - - Changed 'part.responsible' from User to Owner - -v140 -> 2023-10-20 : https://github.com/inventree/InvenTree/pull/5664 - - Expand API token functionality - - Multiple API tokens can be generated per user - v139 -> 2023-10-11 : https://github.com/inventree/InvenTree/pull/5509 - Add new BarcodePOReceive endpoint to receive line items by scanning supplier barcodes diff --git a/InvenTree/InvenTree/middleware.py b/InvenTree/InvenTree/middleware.py index 7fac82e13f..542499cb40 100644 --- a/InvenTree/InvenTree/middleware.py +++ b/InvenTree/InvenTree/middleware.py @@ -12,9 +12,9 @@ from django.urls import Resolver404, include, re_path, resolve, reverse_lazy from allauth_2fa.middleware import (AllauthTwoFactorMiddleware, BaseRequire2FAMiddleware) from error_report.middleware import ExceptionProcessor +from rest_framework.authtoken.models import Token from InvenTree.urls import frontendpatterns -from users.models import ApiToken logger = logging.getLogger("inventree") @@ -75,15 +75,13 @@ class AuthRequiredMiddleware(object): # Does the provided token match a valid user? try: - token = ApiToken.objects.get(key=token_key) + token = Token.objects.get(key=token_key) - if token.active and token.user: + # Provide the user information to the request + request.user = token.user + authorized = True - # Provide the user information to the request - request.user = token.user - authorized = True - - except ApiToken.DoesNotExist: + except Token.DoesNotExist: logger.warning("Access denied for unknown token %s", token_key) # No authorization was found for the request diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index a808f6d603..eb9d10effe 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -197,18 +197,7 @@ if DBBACKUP_STORAGE_OPTIONS is None: 'location': config.get_backup_dir(), } -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' -) +# Application definition INSTALLED_APPS = [ # Admin site integration @@ -243,6 +232,7 @@ INSTALLED_APPS = [ # Third part add-ons 'django_filters', # Extended filter functionality 'rest_framework', # DRF (Django Rest Framework) + 'rest_framework.authtoken', # Token authentication for API 'corsheaders', # Cross-origin Resource Sharing for DRF 'crispy_forms', # Improved form rendering 'import_export', # Import / export tables to file @@ -389,6 +379,14 @@ 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 = [ @@ -435,7 +433,7 @@ REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication', - 'users.authentication.ApiTokenAuthentication', + 'rest_framework.authentication.TokenAuthentication', ), 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', 'DEFAULT_PERMISSION_CLASSES': ( @@ -447,8 +445,7 @@ REST_FRAMEWORK = { 'DEFAULT_METADATA_CLASS': 'InvenTree.metadata.InvenTreeMetadata', 'DEFAULT_RENDERER_CLASSES': [ 'rest_framework.renderers.JSONRenderer', - ], - 'TOKEN_MODEL': 'users.models.ApiToken', + ] } if DEBUG: diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 82a21fd331..11ce213d72 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -209,14 +209,11 @@ classic_frontendpatterns = [ new_frontendpatterns = platform_urls -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 = [ + # 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 += backendpatterns diff --git a/InvenTree/build/templates/build/build_base.html b/InvenTree/build/templates/build/build_base.html index 3eb50e1270..2f1ea421b6 100644 --- a/InvenTree/build/templates/build/build_base.html +++ b/InvenTree/build/templates/build/build_base.html @@ -29,9 +29,10 @@ src="{% static 'img/blank_image.png' %}" {% block actions %} -{% admin_url user "build.build" build.pk as url %} +{% if user.is_staff and roles.build.change %} +{% url 'admin:build_build_change' 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 238c53847e..7953635671 100644 --- a/InvenTree/company/templates/company/company_base.html +++ b/InvenTree/company/templates/company/company_base.html @@ -14,9 +14,10 @@ {% block actions %} -{% admin_url user "company.company" company.pk as url %} +{% if user.is_staff and perms.company.change_company %} +{% url 'admin:company_company_change' 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 9f0e8acfbc..abc3d2d91c 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 url and not hidden and user.is_staff %} +{% if not hidden and user.is_staff %}