def in_group_or_403(user, group_name):
'''
This function mimics the functionality of get_object_or_404, but for permission groups.
The function accepts a user and group name, doing nothing if the user is present in
the permission group; otherwise, throws a PermissionDenied error
Args:
- user (Object) - The user instance
- group_name (String) - The name of the permission group
'''
try:
group = get_group_by_name(group_name)
except:
raise PermissionDenied
if group not in user.groups.all():
raise PermissionDenied
评论列表
文章目录