network_inventory/customers/decorators.py

18 lines
510 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:
return HttpResponseForbidden(
"You're not allowed to access this page."
2020-08-03 13:41:49 +02:00
)
2022-03-27 14:50:44 +02:00
return new_function