mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-15 17:17:02 +02:00
Refine logic for fixture users
This commit is contained in:
parent
8b27c44b89
commit
aa9127875a
3 changed files with 18 additions and 5 deletions
|
@ -99,8 +99,16 @@ def login_callback(request):
|
||||||
return CLIENT.create_authn_request(request.session)
|
return CLIENT.create_authn_request(request.session)
|
||||||
user = authenticate(request=request, **userinfo)
|
user = authenticate(request=request, **userinfo)
|
||||||
if user:
|
if user:
|
||||||
# Set the verification type if it doesn't already exist
|
|
||||||
if not user.verification_type:
|
# Fixture users kind of exist in a superposition of verification types,
|
||||||
|
# because while the system "verified" them, if they login,
|
||||||
|
# we don't know how the user themselves was verified through login.gov until
|
||||||
|
# they actually try logging in. This edge-case only matters in non-production environments.
|
||||||
|
fixture_user = User.VerificationTypeChoices.FIXTURE_USER
|
||||||
|
is_fixture_user = user.verification_type and user.verification_type == fixture_user
|
||||||
|
|
||||||
|
# Set the verification type if it doesn't already exist or if its a fixture user
|
||||||
|
if not user.verification_type or is_fixture_user:
|
||||||
user.set_user_verification_type()
|
user.set_user_verification_type()
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
|
|
|
@ -188,9 +188,6 @@ class UserFixture:
|
||||||
logger.info(f"Going to load {len(users)} users in group {group_name}")
|
logger.info(f"Going to load {len(users)} users in group {group_name}")
|
||||||
for user_data in users:
|
for user_data in users:
|
||||||
try:
|
try:
|
||||||
|
|
||||||
# TODO - Add the fixture user to the VerifiedByStaff table
|
|
||||||
# (To track how this user was verified)
|
|
||||||
user, _ = User.objects.get_or_create(username=user_data["username"])
|
user, _ = User.objects.get_or_create(username=user_data["username"])
|
||||||
user.is_superuser = False
|
user.is_superuser = False
|
||||||
user.first_name = user_data["first_name"]
|
user.first_name = user_data["first_name"]
|
||||||
|
@ -199,6 +196,10 @@ class UserFixture:
|
||||||
user.email = user_data["email"]
|
user.email = user_data["email"]
|
||||||
user.is_staff = True
|
user.is_staff = True
|
||||||
user.is_active = True
|
user.is_active = True
|
||||||
|
# This verification type will get reverted to "regular" (or whichever is applicables)
|
||||||
|
# once the user logs in for the first time (as they then got verified through different means).
|
||||||
|
# In the meantime, we can still describe how the user got here in the first place.
|
||||||
|
user.verification_type = User.VerificationTypeChoices.FIXTURE_USER
|
||||||
group = UserGroup.objects.get(name=group_name)
|
group = UserGroup.objects.get(name=group_name)
|
||||||
user.groups.add(group)
|
user.groups.add(group)
|
||||||
user.save()
|
user.save()
|
||||||
|
|
|
@ -33,6 +33,10 @@ class User(AbstractUser):
|
||||||
VERIFIED_BY_STAFF = "verified_by_staff", "Verified by staff"
|
VERIFIED_BY_STAFF = "verified_by_staff", "Verified by staff"
|
||||||
REGULAR = "regular", "Verified by Login.gov"
|
REGULAR = "regular", "Verified by Login.gov"
|
||||||
INVITED = "invited", "Invited by a domain manager"
|
INVITED = "invited", "Invited by a domain manager"
|
||||||
|
# We need a type for fixture users (rather than using verified by staff)
|
||||||
|
# because those users still do get "verified" through normal means
|
||||||
|
# after they login.
|
||||||
|
FIXTURE_USER = "fixture_user", "Created by fixtures"
|
||||||
|
|
||||||
# #### Constants for choice fields ####
|
# #### Constants for choice fields ####
|
||||||
RESTRICTED = "restricted"
|
RESTRICTED = "restricted"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue