network_inventory/src/customers/decorators.py

16 lines
480 B
Python
Raw Normal View History

from django.http import HttpResponseForbidden
from .models import Customer
def customer_view_permission(old_function):
def new_function(request, pk, *args, **kwargs):
customer = Customer.objects.get(pk=pk)
user = request.user
2022-03-27 14:50:44 +02:00
if user.has_perm("customers.view_customer", customer):
return old_function(request, pk)
else:
2023-07-10 16:47:01 +02:00
return HttpResponseForbidden("You're not allowed to access this page.")
2022-03-27 14:50:44 +02:00
return new_function