Closed trueman61 closed 4 years ago
If this is the only type of check you need, it can be done with the basic Django permissions, like described here https://docs.djangoproject.com/en/3.0/topics/auth/default/#limiting-access-to-logged-in-users-that-pass-a-test
Your test can be:
request.user.groups.filter(name='Role2').exists()
If instead you want keep using this library,I suggest you to read the django guardian documentation to understand the difference between per-object permission and global permissions. It looks like you don’t need permissions for a specific entry, but for an entire view which can be achieved with Django auth models only.
Still, Role2 users cannot see the page. The role has no connection with the user. The role assignment depends on the member. So it doesn't depend on the member section?
def sahip_only(view_func):
def wrapper_function(request, *args, **kwargs):
group = None
if request.user.groups.filter(name='Role2').exists():
group = request.user.groups.all()[0].name
return view_func(request, *args, **kwargs)
else:
return HttpResponse('You are not authorized to access this page.')
return wrapper_function
There are two types of members, this depends on how you setup the library:
The second type of members is not relevant for you I guess as you want to limit the page navigation, hence there must be a django user connected to the member.
I can set the page permission according to the user in the group in the decorator below. So how can I set this up for the member's role? Thus, only the member with this role can see the page. I'm waiting for your help.
Screenshot
decorators.py
views.py
forms.py