Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Validate API create requests using serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin Mclean committed Aug 24, 2018
1 parent 851bcb5 commit 6514f37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/v2/serializers/details/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ class AccessTokenSerializer(serializers.ModelSerializer):
class Meta:
model = AccessToken
fields = ('name', 'id')

def validate(self, data):
name = data.get('name', None)
if name and type(name) != unicode:
raise Exception("Name must be a unicode string, not {}".format(type(name)))
1 change: 1 addition & 0 deletions api/v2/views/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def get_queryset(self):
return AccessToken.objects.filter(token__user=self.request.user)

def create(self, request):
AccessTokenSerializer().validate(request.data)
name = request.data.get('name', None)
user = request.user
access_token = create_access_token(user, name, issuer="Personal-Access-Token")
Expand Down

0 comments on commit 6514f37

Please sign in to comment.