diff --git a/InvenTree/InvenTree/static/script/inventree/modals.js b/InvenTree/InvenTree/static/script/inventree/modals.js index 1cb5346a68..80ada1596f 100644 --- a/InvenTree/InvenTree/static/script/inventree/modals.js +++ b/InvenTree/InvenTree/static/script/inventree/modals.js @@ -807,7 +807,19 @@ function launchModalForm(url, options = {}) { } }, error: function (xhr, ajaxOptions, thrownError) { + $(modal).modal('hide'); + + // Permission denied! + if (xhr.status == 403) { + showAlertDialog( + "Permission Denied", + "You do not have the required permissions to access this function" + ); + + return; + } + showAlertDialog('Error requesting form data', renderErrorMessage(xhr)); } }; diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index b64a23a6fb..827769c32a 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -7,7 +7,7 @@ import django import common.models -INVENTREE_SW_VERSION = "0.1.3 pre" +INVENTREE_SW_VERSION = "0.1.4 pre" def inventreeInstanceName(): diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 3f9bc5b0a9..d940229ebe 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -13,6 +13,8 @@ from django.template.loader import render_to_string from django.http import JsonResponse, HttpResponseRedirect from django.urls import reverse_lazy +from django.contrib.auth.mixins import PermissionRequiredMixin + from django.views import View from django.views.generic import UpdateView, CreateView, FormView from django.views.generic.base import TemplateView @@ -105,12 +107,32 @@ class TreeSerializer(views.APIView): return JsonResponse(response, safe=False) -class AjaxMixin(object): +class AjaxMixin(PermissionRequiredMixin): """ AjaxMixin provides basic functionality for rendering a Django form to JSON. Handles jsonResponse rendering, and adds extra data for the modal forms to process on the client side. + + Any view which inherits the AjaxMixin will need + correct permissions set using the 'permission_required' attribute + """ + # By default, allow *any* permissions + permission_required = '*' + + def has_permission(self): + """ + Override the default behaviour of has_permission from PermissionRequiredMixin. + + Basically, if permission_required attribute = '*', + no permissions are actually required! + """ + + if self.permission_required == '*': + return True + else: + return super().has_permission() + # By default, point to the modal_form template # (this can be overridden by a child class) ajax_template_name = 'modal_form.html' diff --git a/InvenTree/build/admin.py b/InvenTree/build/admin.py index 0ef5ccb75b..b47d38e36d 100644 --- a/InvenTree/build/admin.py +++ b/InvenTree/build/admin.py @@ -20,6 +20,12 @@ class BuildAdmin(ImportExportModelAdmin): 'notes', ) + search_fields = [ + 'title', + 'part__name', + 'part__description', + ] + class BuildItemAdmin(admin.ModelAdmin): diff --git a/InvenTree/build/templates/build/build_base.html b/InvenTree/build/templates/build/build_base.html index fb84b467cf..915433b055 100644 --- a/InvenTree/build/templates/build/build_base.html +++ b/InvenTree/build/templates/build/build_base.html @@ -33,7 +33,12 @@ src="{% static 'img/blank_image.png' %}" {% block page_data %}