mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-05 18:53:28 +02:00
Update user.py
This commit is contained in:
parent
c457f862fc
commit
6c0509d4b5
1 changed files with 0 additions and 56 deletions
|
@ -97,51 +97,6 @@ class User(AbstractUser):
|
||||||
new_domain_invitation = DomainInvitation(email=transition_domain_email.lower(), domain=new_domain)
|
new_domain_invitation = DomainInvitation(email=transition_domain_email.lower(), domain=new_domain)
|
||||||
new_domain_invitation.save()
|
new_domain_invitation.save()
|
||||||
|
|
||||||
def check_transition_domains_on_login(self):
|
|
||||||
"""When a user first arrives on the site, we need to check
|
|
||||||
if they are logging in with the same e-mail as a
|
|
||||||
transition domain and update our database accordingly."""
|
|
||||||
|
|
||||||
for transition_domain in TransitionDomain.objects.filter(username=self.email):
|
|
||||||
# Looks like the user logged in with the same e-mail as
|
|
||||||
# one or more corresponding transition domains.
|
|
||||||
# Create corresponding DomainInformation objects.
|
|
||||||
|
|
||||||
# NOTE: adding an ADMIN user role for this user
|
|
||||||
# for each domain should already be done
|
|
||||||
# in the invitation.retrieve() method.
|
|
||||||
# However, if the migration scripts for transition
|
|
||||||
# domain objects were not executed correctly,
|
|
||||||
# there could be transition domains without
|
|
||||||
# any corresponding Domain & DomainInvitation objects,
|
|
||||||
# which means the invitation.retrieve() method might
|
|
||||||
# not execute.
|
|
||||||
# Check that there is a corresponding domain object
|
|
||||||
# for this transition domain. If not, we have an error
|
|
||||||
# with our data and migrations need to be run again.
|
|
||||||
|
|
||||||
# Get the domain that corresponds with this transition domain
|
|
||||||
domain_exists = Domain.objects.filter(name=transition_domain.domain_name).exists()
|
|
||||||
if not domain_exists:
|
|
||||||
logger.warn(
|
|
||||||
"""There are transition domains without
|
|
||||||
corresponding domain objects!
|
|
||||||
Please run migration scripts for transition domains
|
|
||||||
(See data_migration.md)"""
|
|
||||||
)
|
|
||||||
# No need to throw an exception...just create a domain
|
|
||||||
# and domain invite, then proceed as normal
|
|
||||||
self.create_domain_and_invite(transition_domain)
|
|
||||||
|
|
||||||
domain = Domain.objects.get(name=transition_domain.domain_name)
|
|
||||||
|
|
||||||
# Create a domain information object, if one doesn't
|
|
||||||
# already exist
|
|
||||||
domain_info_exists = DomainInformation.objects.filter(domain=domain).exists()
|
|
||||||
if not domain_info_exists:
|
|
||||||
new_domain_info = DomainInformation(creator=self, domain=domain)
|
|
||||||
new_domain_info.save()
|
|
||||||
|
|
||||||
def on_each_login(self):
|
def on_each_login(self):
|
||||||
"""Callback each time the user is authenticated.
|
"""Callback each time the user is authenticated.
|
||||||
|
|
||||||
|
@ -152,17 +107,6 @@ class User(AbstractUser):
|
||||||
as a transition domain and update our domainInfo objects accordingly.
|
as a transition domain and update our domainInfo objects accordingly.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# PART 1: TRANSITION DOMAINS
|
|
||||||
#
|
|
||||||
# NOTE: THIS MUST RUN FIRST
|
|
||||||
# (If we have an issue where transition domains were
|
|
||||||
# not fully converted into Domain and DomainInvitation
|
|
||||||
# objects, this method will fill in the gaps.
|
|
||||||
# This will ensure the Domain Invitations method
|
|
||||||
# runs correctly (no missing invites))
|
|
||||||
self.check_transition_domains_on_login()
|
|
||||||
|
|
||||||
# PART 2: DOMAIN INVITATIONS
|
|
||||||
self.check_domain_invitations_on_login()
|
self.check_domain_invitations_on_login()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue