Last active
June 17, 2021 12:24
-
-
Save dmitry-naumenko/5dae27a68ce29612b404b03611365449 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import Http404 | |
from .constants import Group | |
def check_user_able_to_see_page(*groups: Group): | |
def decorator(function): | |
def wrapper(request, *args, **kwargs): | |
if request.user.groups.filter( | |
name__in=[group.name for group in groups] | |
).exists(): | |
return function(request, *args, **kwargs) | |
raise Http404 | |
return wrapper | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment