From ad95e00f69b3ef2fca860efb4dbaf5606760c670 Mon Sep 17 00:00:00 2001 From: Calvin Mclean Date: Fri, 24 Aug 2018 12:59:42 -0700 Subject: [PATCH] Improve the AccessToken model --- core/models/access_token.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/models/access_token.py b/core/models/access_token.py index 46549a32d..f8deb37a0 100644 --- a/core/models/access_token.py +++ b/core/models/access_token.py @@ -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) @@ -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