mirror of
https://github.com/Nebucatnetzer/network_inventory.git
synced 2024-06-27 11:45:23 +02:00
change the superuser_required decorator to return 404
This commit is contained in:
parent
70d4d5176f
commit
9f30375f6b
|
@ -1,19 +1,10 @@
|
|||
from django.contrib.admin.views.decorators import user_passes_test
|
||||
from django.contrib.auth import REDIRECT_FIELD_NAME
|
||||
from django.http import Http404
|
||||
|
||||
|
||||
def superuser_required(view_func=None, redirect_field_name=REDIRECT_FIELD_NAME,
|
||||
login_url='account_login_url'):
|
||||
"""
|
||||
Decorator for views that checks that the user is logged in and is a
|
||||
superuser, redirecting to the login page if necessary.
|
||||
https://stackoverflow.com/a/46318226/7723859
|
||||
"""
|
||||
actual_decorator = user_passes_test(
|
||||
lambda u: u.is_active and u.is_superuser,
|
||||
login_url=login_url,
|
||||
redirect_field_name=redirect_field_name
|
||||
)
|
||||
if view_func:
|
||||
return actual_decorator(view_func)
|
||||
return actual_decorator
|
||||
def superuser_required(old_function):
|
||||
def new_function(request, *args, **kwargs):
|
||||
if request.user.is_superuser:
|
||||
return old_function(request)
|
||||
else:
|
||||
raise Http404
|
||||
return new_function
|
||||
|
|
Loading…
Reference in New Issue
Block a user