Skip to content

Commit

Permalink
Merge pull request #3091 from mytardis/mt-405-cant-approve-google-auth
Browse files Browse the repository at this point in the history
MT-405 Can't approve Google auth
  • Loading branch information
manishkumr committed Jun 4, 2021
2 parents 8a05589 + c4887d0 commit 7d741f2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tardis/tardis_portal/models/access_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.db.models import Q
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils.functional import lazy


class UserProfile(models.Model):
Expand Down Expand Up @@ -90,12 +91,20 @@ def __str__(self):
return '%s: %s' % (self.user.username, self.group.name)


def get_auth_method_choices():
auth_methods = ()
for auth_method in settings.AUTH_PROVIDERS:
auth_methods += ((auth_method[0], auth_method[1]),)
return auth_methods


# TODO: Generalise auth methods
class UserAuthentication(models.Model):
CHOICES = ()
userProfile = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
username = models.CharField(max_length=50)
authenticationMethod = models.CharField(max_length=30, choices=CHOICES)
authenticationMethod = models.CharField(
max_length=30,
choices=lazy(get_auth_method_choices, tuple)())
approved = models.BooleanField(default=True)
__original_approved = None

Expand All @@ -104,10 +113,7 @@ class Meta:

def __init__(self, *args, **kwargs):
# instantiate comparisonChoices based on settings.AUTH PROVIDERS
self.CHOICES = ()
for authMethods in settings.AUTH_PROVIDERS:
self.CHOICES += ((authMethods[0], authMethods[1]),)
self._comparisonChoicesDict = dict(self.CHOICES)
self._comparisonChoicesDict = dict(get_auth_method_choices())

super().__init__(*args, **kwargs)
self.__original_approved = self.approved
Expand Down

0 comments on commit 7d741f2

Please sign in to comment.