You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
674 B
20 lines
674 B
from pprint import pprint |
|
from rest_framework import permissions |
|
from caremyway.api.models import Client, Provider |
|
|
|
class UserTypePermission(permissions.BasePermission): |
|
""" |
|
Disallow creation of client or provider if one already exists |
|
""" |
|
message = "User is already either a client or a provider." |
|
|
|
def has_permission(self, request, view): |
|
user = request.data.get('user', None) |
|
|
|
if request.method != 'POST' or user is None: |
|
return True |
|
elif not Client.objects.filter(user=user).exists() \ |
|
and not Provider.objects.filter(user=user).exists(): |
|
return True |
|
else: |
|
return False
|
|
|