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

Commit

Permalink
Improve the AccessToken model
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin Mclean committed Aug 24, 2018
1 parent 94d003b commit 989ff50
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions core/models/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

class AccessToken(models.Model):
"""
Extend the django_cyverse_auth Token to add a name
Extend the django_cyverse_auth Token to add a name.
These tokens are created and displayed in the Troposphere settings page to allow
users to manage tokens used for external API access.
"""
token = models.OneToOneField(Token, on_delete=models.CASCADE)
name = models.CharField(max_length=128, null=False, blank=False)
Expand All @@ -16,9 +18,8 @@ class Meta:
app_label = "core"

def create_access_token(user, token_name=None, token_expire=None, remote_ip=None, issuer=None):
if AccessToken.objects.filter(name=token_name, token__user_id=user.id):
if AccessToken.objects.filter(name=token_name, token__user=user):
return None
token = Token(user=user, issuer=issuer)
token.save()
access_token, created = AccessToken.objects.update_or_create(token=token, name=token_name)
token = Token.objects.create(user=user, issuer=issuer)
access_token = AccessToken.objects.create(token=token, name=token_name)
return access_token

0 comments on commit 989ff50

Please sign in to comment.