mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 22:19:17 +02:00
See #152: added permission fields on user model and corresponding API permission
This commit is contained in:
parent
23e27e0dd9
commit
ff65a4b935
5 changed files with 159 additions and 17 deletions
19
api/funkwhale_api/users/permissions.py
Normal file
19
api/funkwhale_api/users/permissions.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from rest_framework.permissions import BasePermission
|
||||
|
||||
|
||||
class HasUserPermission(BasePermission):
|
||||
"""
|
||||
Ensure the request user has the proper permissions.
|
||||
|
||||
Usage:
|
||||
|
||||
class MyView(APIView):
|
||||
permission_classes = [HasUserPermission]
|
||||
required_permissions = ['federation']
|
||||
"""
|
||||
def has_permission(self, request, view):
|
||||
if not hasattr(request, 'user') or not request.user:
|
||||
return False
|
||||
if request.user.is_anonymous:
|
||||
return False
|
||||
return request.user.has_permissions(*view.required_permissions)
|
Loading…
Add table
Add a link
Reference in a new issue