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 %}