Private
Public Access
1
0

Oauth2 provider and initial api

This commit is contained in:
Sander Roosendaal
2016-11-20 14:46:46 +01:00
parent 60edc3f3c2
commit d57ecb495b
6 changed files with 89 additions and 4611 deletions

21
rowers/permissions.py Normal file
View File

@@ -0,0 +1,21 @@
from rest_framework import permissions
from rowers.models import Rower
class IsOwnerOrReadOnly(permissions.BasePermission):
"""
Custom permission to only allow owners of an object to edit it.
"""
def has_object_permission(self, request, view, obj):
# Read permissions are allowed to any request,
# so we'll always allow GET, HEAD or OPTIONS requests.
if request.method in permissions.SAFE_METHODS:
return True
# Write permissions are only allowed to the owner of the snippet.
return obj.owner == request.user
class IsOwnerOrNot(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
r = Rower.objects.get(user=request.user)
return (obj.user == r)