mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-21 20:09:23 +02:00
checking transition domains on each login rather than on first login only
This commit is contained in:
parent
4311c9289c
commit
93370d45c2
7 changed files with 17 additions and 17 deletions
|
@ -136,7 +136,7 @@ class DomainInvitation {
|
||||||
--
|
--
|
||||||
}
|
}
|
||||||
DomainInvitation -- Domain
|
DomainInvitation -- Domain
|
||||||
DomainInvitation .[#green].> UserDomainRole : User.first_login()
|
DomainInvitation .[#green].> UserDomainRole : User.on_each_login()
|
||||||
|
|
||||||
actor applicant #Red
|
actor applicant #Red
|
||||||
applicant -d-> DomainApplication : **/register**
|
applicant -d-> DomainApplication : **/register**
|
||||||
|
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
@ -49,13 +49,13 @@ class OpenIdConnectBackend(ModelBackend):
|
||||||
user, created = UserModel.objects.update_or_create(**args)
|
user, created = UserModel.objects.update_or_create(**args)
|
||||||
if created:
|
if created:
|
||||||
user = self.configure_user(user, **kwargs)
|
user = self.configure_user(user, **kwargs)
|
||||||
# run a newly created user's callback for a first-time login
|
|
||||||
user.first_login()
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
user = UserModel.objects.get_by_natural_key(username)
|
user = UserModel.objects.get_by_natural_key(username)
|
||||||
except UserModel.DoesNotExist:
|
except UserModel.DoesNotExist:
|
||||||
return None
|
return None
|
||||||
|
# run this callback for a each login
|
||||||
|
user.on_each_login()
|
||||||
return user
|
return user
|
||||||
|
|
||||||
def clean_username(self, username):
|
def clean_username(self, username):
|
||||||
|
|
|
@ -154,10 +154,10 @@ class User(AbstractUser):
|
||||||
new_domain_info = DomainInformation(creator=self, domain=domain)
|
new_domain_info = DomainInformation(creator=self, domain=domain)
|
||||||
new_domain_info.save()
|
new_domain_info.save()
|
||||||
|
|
||||||
def first_login(self):
|
def on_each_login(self):
|
||||||
"""Callback when the user is authenticated for the very first time.
|
"""Callback each time the user is authenticated.
|
||||||
|
|
||||||
When a user first arrives on the site, we need to retrieve any domain
|
When a user arrives on the site each time, we need to retrieve any domain
|
||||||
invitations that match their email address.
|
invitations that match their email address.
|
||||||
|
|
||||||
We also need to check if they are logging in with the same e-mail
|
We also need to check if they are logging in with the same e-mail
|
||||||
|
|
|
@ -609,9 +609,9 @@ class TestInvitations(TestCase):
|
||||||
self.invitation.retrieve()
|
self.invitation.retrieve()
|
||||||
self.assertEqual(self.invitation.status, DomainInvitation.RETRIEVED)
|
self.assertEqual(self.invitation.status, DomainInvitation.RETRIEVED)
|
||||||
|
|
||||||
def test_retrieve_on_first_login(self):
|
def test_retrieve_on_each_login(self):
|
||||||
"""A new user's first_login callback retrieves their invitations."""
|
"""A user's authenticate on_each_login callback retrieves their invitations."""
|
||||||
self.user.first_login()
|
self.user.on_each_login()
|
||||||
self.assertTrue(UserDomainRole.objects.get(user=self.user, domain=self.domain))
|
self.assertTrue(UserDomainRole.objects.get(user=self.user, domain=self.domain))
|
||||||
|
|
||||||
|
|
||||||
|
@ -640,19 +640,19 @@ class TestUser(TestCase):
|
||||||
User.objects.all().delete()
|
User.objects.all().delete()
|
||||||
|
|
||||||
def test_check_transition_domains_on_login(self):
|
def test_check_transition_domains_on_login(self):
|
||||||
"""A new user's first_login callback checks transition domains.
|
"""A user's on_each_login callback checks transition domains.
|
||||||
Makes DomainInformation object."""
|
Makes DomainInformation object."""
|
||||||
self.domain, _ = Domain.objects.get_or_create(name=self.domain_name)
|
self.domain, _ = Domain.objects.get_or_create(name=self.domain_name)
|
||||||
|
|
||||||
self.user.first_login()
|
self.user.on_each_login()
|
||||||
self.assertTrue(DomainInformation.objects.get(domain=self.domain))
|
self.assertTrue(DomainInformation.objects.get(domain=self.domain))
|
||||||
|
|
||||||
def test_check_transition_domains_without_domains_on_login(self):
|
def test_check_transition_domains_without_domains_on_login(self):
|
||||||
"""A new user's first_login callback checks transition domains.
|
"""A user's on_each_login callback checks transition domains.
|
||||||
This test makes sure that in the event a domain does not exist
|
This test makes sure that in the event a domain does not exist
|
||||||
for a given transition domain, both a domain and domain invitation
|
for a given transition domain, both a domain and domain invitation
|
||||||
are created."""
|
are created."""
|
||||||
self.user.first_login()
|
self.user.on_each_login()
|
||||||
self.assertTrue(Domain.objects.get(name=self.domain_name))
|
self.assertTrue(Domain.objects.get(name=self.domain_name))
|
||||||
|
|
||||||
domain = Domain.objects.get(name=self.domain_name)
|
domain = Domain.objects.get(name=self.domain_name)
|
||||||
|
|
|
@ -237,7 +237,7 @@ class TestLogins(TestCase):
|
||||||
user, user_created = User.objects.get_or_create(
|
user, user_created = User.objects.get_or_create(
|
||||||
email=invite.email, username=invite.email
|
email=invite.email, username=invite.email
|
||||||
)
|
)
|
||||||
user.first_login()
|
user.on_each_login()
|
||||||
|
|
||||||
# Analyze the tables
|
# Analyze the tables
|
||||||
expected_total_transition_domains = 8
|
expected_total_transition_domains = 8
|
||||||
|
|
|
@ -1431,8 +1431,8 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
new_user = User.objects.create(username=EMAIL, email=EMAIL)
|
new_user = User.objects.create(username=EMAIL, email=EMAIL)
|
||||||
# log them in to `self.app`
|
# log them in to `self.app`
|
||||||
self.app.set_user(new_user.username)
|
self.app.set_user(new_user.username)
|
||||||
# and manually call the first login callback
|
# and manually call the on each login callback
|
||||||
new_user.first_login()
|
new_user.on_each_login()
|
||||||
|
|
||||||
# Now load the home page and make sure our domain appears there
|
# Now load the home page and make sure our domain appears there
|
||||||
home_page = self.app.get(reverse("home"))
|
home_page = self.app.get(reverse("home"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue