mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-06 22:14:12 +00:00
feat: decorator group_required
This commit is contained in:
BIN
gestaoRaul/gestaoRaul/__pycache__/decorators.cpython-310.pyc
Normal file
BIN
gestaoRaul/gestaoRaul/__pycache__/decorators.cpython-310.pyc
Normal file
Binary file not shown.
14
gestaoRaul/gestaoRaul/decorators.py
Normal file
14
gestaoRaul/gestaoRaul/decorators.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.http import HttpResponseForbidden
|
||||
|
||||
|
||||
def group_required(groupName):
|
||||
def decorator(view_function):
|
||||
def wrapper(request, *args, **kwargs):
|
||||
if request.user.groups.filter(name=groupName).exists():
|
||||
return view_function(request, *args, **kwargs)
|
||||
else:
|
||||
return HttpResponseForbidden('tu nao tem acesso rapa')
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
Reference in New Issue
Block a user