From 5cba82b34382175bfd1914ea20f8bd13fac21036 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:30:45 -0600 Subject: [PATCH 01/59] Basic logic --- src/registrar/admin.py | 4 +- src/registrar/models/user.py | 99 ++++++++++++++----- .../admin/includes/contact_detail_list.html | 2 +- .../admin/includes/detail_table_fieldset.html | 4 +- 4 files changed, 83 insertions(+), 26 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index b62ea80b8..6869df94a 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -490,7 +490,7 @@ class MyUserAdmin(BaseUserAdmin): fieldsets = ( ( None, - {"fields": ("username", "password", "status")}, + {"fields": ("username", "password", "status", "verification_type")}, ), ("Personal Info", {"fields": ("first_name", "last_name", "email")}), ( @@ -508,6 +508,8 @@ class MyUserAdmin(BaseUserAdmin): ("Important dates", {"fields": ("last_login", "date_joined")}), ) + readonly_fields = ("verification_type") + # Hide Username (uuid), Groups and Permissions # Q: Now that we're using Groups and Permissions, # do we expose those to analysts to view? diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index 2688ef57f..c69672100 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -1,3 +1,4 @@ +from enum import Enum import logging from django.contrib.auth.models import AbstractUser @@ -23,6 +24,16 @@ class User(AbstractUser): but can be customized later. """ + class VerificationTypeChoices(models.TextChoices): + """ + Users achieve access to our system in a few different ways. + These choices reflect those pathways. + """ + GRANDFATHERED = "grandfathered", "Legacy user" + VERIFIED_BY_STAFF = "verified_by_staff", "Verified by staff" + REGULAR = "regular", "Verified by Login.gov" + INVITED = "invited", "Invited by a domain manager" + # #### Constants for choice fields #### RESTRICTED = "restricted" STATUS_CHOICES = ((RESTRICTED, RESTRICTED),) @@ -48,6 +59,13 @@ class User(AbstractUser): db_index=True, ) + verification_type = models.CharField( + choices=VerificationTypeChoices, + null=True, + blank=True, + help_text="The means through which this user was verified", + ) + def __str__(self): # this info is pulled from Login.gov if self.first_name or self.last_name: @@ -95,6 +113,22 @@ class User(AbstractUser): def has_contact_info(self): return bool(self.contact.title or self.contact.email or self.contact.phone) + + @classmethod + def get_existing_user_from_uuid(cls, uuid): + existing_user = None + try: + existing_user = cls.objects.get(username=uuid) + if existing_user and UserDomainRole.objects.filter(user=existing_user).exists(): + return (False, existing_user) + except cls.DoesNotExist: + # Do nothing when the user is not found, as we're checking for existence. + pass + except Exception as err: + raise err + + return (True, existing_user) + @classmethod def needs_identity_verification(cls, email, uuid): """A method used by our oidc classes to test whether a user needs email/uuid verification @@ -102,33 +136,52 @@ class User(AbstractUser): # An existing user who is a domain manager of a domain (that is, # they have an entry in UserDomainRole for their User) - try: - existing_user = cls.objects.get(username=uuid) - if existing_user and UserDomainRole.objects.filter(user=existing_user).exists(): - return False - except cls.DoesNotExist: - # Do nothing when the user is not found, as we're checking for existence. - pass - except Exception as err: - raise err + user_exists, existing_user = cls.existing_user(uuid) + if not user_exists: + return False - # A new incoming user who is a domain manager for one of the domains - # that we inputted from Verisign (that is, their email address appears - # in the username field of a TransitionDomain) + # The user needs identity verification if they don't meet + # any special criteria, i.e. we are validating them "regularly" + existing_user.verification_type = cls.get_verification_type_from_email(email) + return existing_user.verification_type == cls.VerificationTypeChoices.REGULAR + + @classmethod + def get_verification_type_from_email(cls, email, invitation_status=DomainInvitation.DomainInvitationStatus.INVITED): + """Retrieves the verification type based off of a provided email address""" + + verification_type = None if TransitionDomain.objects.filter(username=email).exists(): - return False + # A new incoming user who is a domain manager for one of the domains + # that we inputted from Verisign (that is, their email address appears + # in the username field of a TransitionDomain) + verification_type = cls.VerificationTypeChoices.GRANDFATHERED + elif VerifiedByStaff.objects.filter(email=email).exists(): + # New users flagged by Staff to bypass ial2 + verification_type = cls.VerificationTypeChoices.VERIFIED_BY_STAFF + elif DomainInvitation.objects.filter(email=email, status=invitation_status).exists(): + # A new incoming user who is being invited to be a domain manager (that is, + # their email address is in DomainInvitation for an invitation that is not yet "retrieved"). + verification_type = cls.VerificationTypeChoices.INVITED + else: + verification_type = cls.VerificationTypeChoices.REGULAR + + return verification_type - # New users flagged by Staff to bypass ial2 - if VerifiedByStaff.objects.filter(email=email).exists(): - return False + def user_verification_type(self, check_if_user_exists=False): + if self.verification_type is None: + # Would need to check audit log + retrieved = DomainInvitation.DomainInvitationStatus.RETRIEVED + user_exists, _ = self.existing_user(self.username) + verification_type = self.get_verification_type_from_email(self.email, invitation_status=retrieved) - # A new incoming user who is being invited to be a domain manager (that is, - # their email address is in DomainInvitation for an invitation that is not yet "retrieved"). - invited = DomainInvitation.DomainInvitationStatus.INVITED - if DomainInvitation.objects.filter(email=email, status=invited).exists(): - return False - - return True + # This should check if the type is unknown, use check_if_user_exists? + if verification_type == self.VerificationTypeChoices.REGULAR and not user_exists: + raise ValueError(f"No verification_type was found for {self} with id: {self.pk}") + else: + self.verification_type = verification_type + return self.verification_type + else: + return self.verification_type def check_domain_invitations_on_login(self): """When a user first arrives on the site, we need to retrieve any domain diff --git a/src/registrar/templates/django/admin/includes/contact_detail_list.html b/src/registrar/templates/django/admin/includes/contact_detail_list.html index 0ac9c4c49..5ac5452e3 100644 --- a/src/registrar/templates/django/admin/includes/contact_detail_list.html +++ b/src/registrar/templates/django/admin/includes/contact_detail_list.html @@ -3,7 +3,7 @@
{% if show_formatted_name %} - {% if contact.get_formatted_name %} + {% if user.get_formatted_name %} {{ user.get_formatted_name }}
{% else %} None
diff --git a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html index fb7303352..7b468faec 100644 --- a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html +++ b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html @@ -6,7 +6,9 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html) {% endcomment %} {% block field_readonly %} {% with all_contacts=original_object.other_contacts.all %} - {% if field.field.name == "other_contacts" %} + {% if field.field.name == "creator" %} +
{{ field.contents }} ({{ user.verification_type }})
+ {% elif field.field.name == "other_contacts" %} {% if all_contacts.count > 2 %}
{% for contact in all_contacts %} From 3e7f143a1e8911f6dd70878a01154a3b8873fcd0 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 19 Apr 2024 15:30:37 -0600 Subject: [PATCH 02/59] Fix verification type --- src/djangooidc/views.py | 3 ++ src/registrar/admin.py | 15 ++++++---- src/registrar/fixtures_users.py | 4 +++ .../migrations/0085_user_verification_type.py | 28 +++++++++++++++++++ src/registrar/models/user.py | 18 ++++++------ 5 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 src/registrar/migrations/0085_user_verification_type.py diff --git a/src/djangooidc/views.py b/src/djangooidc/views.py index ab81ccff1..b887b7a14 100644 --- a/src/djangooidc/views.py +++ b/src/djangooidc/views.py @@ -99,8 +99,11 @@ def login_callback(request): return CLIENT.create_authn_request(request.session) user = authenticate(request=request, **userinfo) if user: + # Set the verification type + user.set_user_verification_type() login(request, user) logger.info("Successfully logged in user %s" % user) + # Clear the flag if the exception is not caught request.session.pop("redirect_attempted", None) return redirect(request.session.get("next", "/")) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 6869df94a..dd016b470 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -508,7 +508,7 @@ class MyUserAdmin(BaseUserAdmin): ("Important dates", {"fields": ("last_login", "date_joined")}), ) - readonly_fields = ("verification_type") + readonly_fields = ("verification_type",) # Hide Username (uuid), Groups and Permissions # Q: Now that we're using Groups and Permissions, @@ -516,7 +516,7 @@ class MyUserAdmin(BaseUserAdmin): analyst_fieldsets = ( ( None, - {"fields": ("password", "status")}, + {"fields": ("password", "status", "verification_type")}, ), ("Personal Info", {"fields": ("first_name", "last_name", "email")}), ( @@ -636,11 +636,14 @@ class MyUserAdmin(BaseUserAdmin): return [] def get_readonly_fields(self, request, obj=None): + readonly_fields = list(self.readonly_fields) + if request.user.has_perm("registrar.full_access_permission"): - return () # No read-only fields for all access users - # Return restrictive Read-only fields for analysts and - # users who might not belong to groups - return self.analyst_readonly_fields + return readonly_fields + else: + # Return restrictive Read-only fields for analysts and + # users who might not belong to groups + return self.analyst_readonly_fields class HostIPInline(admin.StackedInline): diff --git a/src/registrar/fixtures_users.py b/src/registrar/fixtures_users.py index 99fe4910e..4c2b85233 100644 --- a/src/registrar/fixtures_users.py +++ b/src/registrar/fixtures_users.py @@ -6,6 +6,7 @@ from registrar.models import ( User, UserGroup, ) +from registrar.models.verified_by_staff import VerifiedByStaff fake = Faker() logger = logging.getLogger(__name__) @@ -187,6 +188,9 @@ class UserFixture: logger.info(f"Going to load {len(users)} users in group {group_name}") for user_data in users: 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.is_superuser = False user.first_name = user_data["first_name"] diff --git a/src/registrar/migrations/0085_user_verification_type.py b/src/registrar/migrations/0085_user_verification_type.py new file mode 100644 index 000000000..2790ea3b7 --- /dev/null +++ b/src/registrar/migrations/0085_user_verification_type.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.10 on 2024-04-19 21:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("registrar", "0084_create_groups_v11"), + ] + + operations = [ + migrations.AddField( + model_name="user", + name="verification_type", + field=models.CharField( + blank=True, + choices=[ + ("grandfathered", "Legacy user"), + ("verified_by_staff", "Verified by staff"), + ("regular", "Verified by Login.gov"), + ("invited", "Invited by a domain manager"), + ], + help_text="The means through which this user was verified", + null=True, + ), + ), + ] diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index c69672100..9320a80ff 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -60,7 +60,7 @@ class User(AbstractUser): ) verification_type = models.CharField( - choices=VerificationTypeChoices, + choices=VerificationTypeChoices.choices, null=True, blank=True, help_text="The means through which this user was verified", @@ -115,19 +115,19 @@ class User(AbstractUser): @classmethod - def get_existing_user_from_uuid(cls, uuid): + def existing_user(cls, uuid): existing_user = None try: existing_user = cls.objects.get(username=uuid) if existing_user and UserDomainRole.objects.filter(user=existing_user).exists(): - return (False, existing_user) + return False except cls.DoesNotExist: # Do nothing when the user is not found, as we're checking for existence. pass except Exception as err: raise err - return (True, existing_user) + return True @classmethod def needs_identity_verification(cls, email, uuid): @@ -136,14 +136,14 @@ class User(AbstractUser): # An existing user who is a domain manager of a domain (that is, # they have an entry in UserDomainRole for their User) - user_exists, existing_user = cls.existing_user(uuid) + user_exists = cls.existing_user(uuid) if not user_exists: return False # The user needs identity verification if they don't meet # any special criteria, i.e. we are validating them "regularly" - existing_user.verification_type = cls.get_verification_type_from_email(email) - return existing_user.verification_type == cls.VerificationTypeChoices.REGULAR + verification_type = cls.get_verification_type_from_email(email) + return verification_type == cls.VerificationTypeChoices.REGULAR @classmethod def get_verification_type_from_email(cls, email, invitation_status=DomainInvitation.DomainInvitationStatus.INVITED): @@ -167,11 +167,11 @@ class User(AbstractUser): return verification_type - def user_verification_type(self, check_if_user_exists=False): + def set_user_verification_type(self): if self.verification_type is None: # Would need to check audit log retrieved = DomainInvitation.DomainInvitationStatus.RETRIEVED - user_exists, _ = self.existing_user(self.username) + user_exists = self.existing_user(self.username) verification_type = self.get_verification_type_from_email(self.email, invitation_status=retrieved) # This should check if the type is unknown, use check_if_user_exists? From a047380b59111916522de1d3ef605b9f793b0467 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 19 Apr 2024 15:44:26 -0600 Subject: [PATCH 03/59] Fix logic --- src/djangooidc/views.py | 7 +++++-- src/registrar/models/user.py | 18 ++++-------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/djangooidc/views.py b/src/djangooidc/views.py index b887b7a14..12b82f242 100644 --- a/src/djangooidc/views.py +++ b/src/djangooidc/views.py @@ -99,8 +99,11 @@ def login_callback(request): return CLIENT.create_authn_request(request.session) user = authenticate(request=request, **userinfo) if user: - # Set the verification type - user.set_user_verification_type() + # Set the verification type if it doesn't already exist + if not user.verification_type: + user.set_user_verification_type() + user.save() + login(request, user) logger.info("Successfully logged in user %s" % user) diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index 9320a80ff..423f93595 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -168,20 +168,10 @@ class User(AbstractUser): return verification_type def set_user_verification_type(self): - if self.verification_type is None: - # Would need to check audit log - retrieved = DomainInvitation.DomainInvitationStatus.RETRIEVED - user_exists = self.existing_user(self.username) - verification_type = self.get_verification_type_from_email(self.email, invitation_status=retrieved) - - # This should check if the type is unknown, use check_if_user_exists? - if verification_type == self.VerificationTypeChoices.REGULAR and not user_exists: - raise ValueError(f"No verification_type was found for {self} with id: {self.pk}") - else: - self.verification_type = verification_type - return self.verification_type - else: - return self.verification_type + # Would need to check audit log + retrieved = DomainInvitation.DomainInvitationStatus.RETRIEVED + verification_type = self.get_verification_type_from_email(self.email, invitation_status=retrieved) + self.verification_type = verification_type def check_domain_invitations_on_login(self): """When a user first arrives on the site, we need to retrieve any domain From 8b27c44b89f30632018f627fa6d6df882f5b3868 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 19 Apr 2024 15:47:03 -0600 Subject: [PATCH 04/59] Cleanup --- src/registrar/models/user.py | 40 +++++++++++++++--------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index 423f93595..b67421d3f 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -113,10 +113,13 @@ class User(AbstractUser): def has_contact_info(self): return bool(self.contact.title or self.contact.email or self.contact.phone) - @classmethod - def existing_user(cls, uuid): - existing_user = None + def needs_identity_verification(cls, email, uuid): + """A method used by our oidc classes to test whether a user needs email/uuid verification + or the full identity PII verification""" + + # An existing user who is a domain manager of a domain (that is, + # they have an entry in UserDomainRole for their User) try: existing_user = cls.objects.get(username=uuid) if existing_user and UserDomainRole.objects.filter(user=existing_user).exists(): @@ -126,24 +129,21 @@ class User(AbstractUser): pass except Exception as err: raise err - - return True - @classmethod - def needs_identity_verification(cls, email, uuid): - """A method used by our oidc classes to test whether a user needs email/uuid verification - or the full identity PII verification""" - - # An existing user who is a domain manager of a domain (that is, - # they have an entry in UserDomainRole for their User) - user_exists = cls.existing_user(uuid) - if not user_exists: - return False + # We can't set the verification type here because the user may not + # always exist at this point. We do it down the line. + verification_type = cls.get_verification_type_from_email(email) # The user needs identity verification if they don't meet # any special criteria, i.e. we are validating them "regularly" - verification_type = cls.get_verification_type_from_email(email) - return verification_type == cls.VerificationTypeChoices.REGULAR + needs_verification = verification_type == cls.VerificationTypeChoices.REGULAR + return needs_verification + + def set_user_verification_type(self): + # Would need to check audit log + retrieved = DomainInvitation.DomainInvitationStatus.RETRIEVED + verification_type = self.get_verification_type_from_email(self.email, invitation_status=retrieved) + self.verification_type = verification_type @classmethod def get_verification_type_from_email(cls, email, invitation_status=DomainInvitation.DomainInvitationStatus.INVITED): @@ -167,12 +167,6 @@ class User(AbstractUser): return verification_type - def set_user_verification_type(self): - # Would need to check audit log - retrieved = DomainInvitation.DomainInvitationStatus.RETRIEVED - verification_type = self.get_verification_type_from_email(self.email, invitation_status=retrieved) - self.verification_type = verification_type - def check_domain_invitations_on_login(self): """When a user first arrives on the site, we need to retrieve any domain invitations that match their email address.""" From aa9127875ad29181c838953520d15d858693fb48 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 22 Apr 2024 10:40:21 -0600 Subject: [PATCH 05/59] Refine logic for fixture users --- src/djangooidc/views.py | 12 ++++++++++-- src/registrar/fixtures_users.py | 7 ++++--- src/registrar/models/user.py | 4 ++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/djangooidc/views.py b/src/djangooidc/views.py index 12b82f242..815df4ecf 100644 --- a/src/djangooidc/views.py +++ b/src/djangooidc/views.py @@ -99,8 +99,16 @@ def login_callback(request): return CLIENT.create_authn_request(request.session) user = authenticate(request=request, **userinfo) 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.save() diff --git a/src/registrar/fixtures_users.py b/src/registrar/fixtures_users.py index 4c2b85233..a901b83e6 100644 --- a/src/registrar/fixtures_users.py +++ b/src/registrar/fixtures_users.py @@ -188,9 +188,6 @@ class UserFixture: logger.info(f"Going to load {len(users)} users in group {group_name}") for user_data in users: 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.is_superuser = False user.first_name = user_data["first_name"] @@ -199,6 +196,10 @@ class UserFixture: user.email = user_data["email"] user.is_staff = 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) user.groups.add(group) user.save() diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index b67421d3f..79bf905b9 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -33,6 +33,10 @@ class User(AbstractUser): VERIFIED_BY_STAFF = "verified_by_staff", "Verified by staff" REGULAR = "regular", "Verified by Login.gov" 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 #### RESTRICTED = "restricted" From 68e44eb98eb936ad2a1e8c0c219a92eb86b48d47 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 22 Apr 2024 10:41:08 -0600 Subject: [PATCH 06/59] Fix migrations after merge --- ...r_verification_type.py => 0087_user_verification_type.py} | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename src/registrar/migrations/{0085_user_verification_type.py => 0087_user_verification_type.py} (78%) diff --git a/src/registrar/migrations/0085_user_verification_type.py b/src/registrar/migrations/0087_user_verification_type.py similarity index 78% rename from src/registrar/migrations/0085_user_verification_type.py rename to src/registrar/migrations/0087_user_verification_type.py index 2790ea3b7..599d067d5 100644 --- a/src/registrar/migrations/0085_user_verification_type.py +++ b/src/registrar/migrations/0087_user_verification_type.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.10 on 2024-04-19 21:02 +# Generated by Django 4.2.10 on 2024-04-22 16:40 from django.db import migrations, models @@ -6,7 +6,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ("registrar", "0084_create_groups_v11"), + ("registrar", "0086_domaininformation_updated_federal_agency_and_more"), ] operations = [ @@ -20,6 +20,7 @@ class Migration(migrations.Migration): ("verified_by_staff", "Verified by staff"), ("regular", "Verified by Login.gov"), ("invited", "Invited by a domain manager"), + ("fixture_user", "Created by fixtures"), ], help_text="The means through which this user was verified", null=True, From 2a7eb6db817d0bd38b4c08431bc788ba02358969 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 22 Apr 2024 11:08:59 -0600 Subject: [PATCH 07/59] Fix test + lint --- src/registrar/fixtures_users.py | 2 +- src/registrar/models/user.py | 9 +++++---- src/registrar/tests/test_admin.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/registrar/fixtures_users.py b/src/registrar/fixtures_users.py index a901b83e6..9669ce071 100644 --- a/src/registrar/fixtures_users.py +++ b/src/registrar/fixtures_users.py @@ -6,7 +6,7 @@ from registrar.models import ( User, UserGroup, ) -from registrar.models.verified_by_staff import VerifiedByStaff + fake = Faker() logger = logging.getLogger(__name__) diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index 20a84bec4..adc198d3a 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -29,12 +29,13 @@ class User(AbstractUser): Users achieve access to our system in a few different ways. These choices reflect those pathways. """ + GRANDFATHERED = "grandfathered", "Legacy user" VERIFIED_BY_STAFF = "verified_by_staff", "Verified by staff" REGULAR = "regular", "Verified by Login.gov" 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 + # because those users still do get "verified" through normal means # after they login. FIXTURE_USER = "fixture_user", "Created by fixtures" @@ -153,7 +154,7 @@ class User(AbstractUser): @classmethod def get_verification_type_from_email(cls, email, invitation_status=DomainInvitation.DomainInvitationStatus.INVITED): """Retrieves the verification type based off of a provided email address""" - + verification_type = None if TransitionDomain.objects.filter(username=email).exists(): # A new incoming user who is a domain manager for one of the domains @@ -164,12 +165,12 @@ class User(AbstractUser): # New users flagged by Staff to bypass ial2 verification_type = cls.VerificationTypeChoices.VERIFIED_BY_STAFF elif DomainInvitation.objects.filter(email=email, status=invitation_status).exists(): - # A new incoming user who is being invited to be a domain manager (that is, + # A new incoming user who is being invited to be a domain manager (that is, # their email address is in DomainInvitation for an invitation that is not yet "retrieved"). verification_type = cls.VerificationTypeChoices.INVITED else: verification_type = cls.VerificationTypeChoices.REGULAR - + return verification_type def check_domain_invitations_on_login(self): diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index bca1a94cb..20ada4d14 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -2820,7 +2820,7 @@ class MyUserAdminTest(TestCase): request.user = create_user() fieldsets = self.admin.get_fieldsets(request) expected_fieldsets = ( - (None, {"fields": ("password", "status")}), + (None, {"fields": ("password", "status", "verification_type")}), ("Personal Info", {"fields": ("first_name", "last_name", "email")}), ("Permissions", {"fields": ("is_active", "groups")}), ("Important dates", {"fields": ("last_login", "date_joined")}), From 2f494466fc5d2f5b1e2320d043fa08968aae9c56 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 22 Apr 2024 13:09:16 -0600 Subject: [PATCH 08/59] Check created at date for invited --- src/registrar/models/user.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index adc198d3a..f775c77ad 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -28,6 +28,13 @@ class User(AbstractUser): """ Users achieve access to our system in a few different ways. These choices reflect those pathways. + + Overview of verification types: + - GRANDFATHERED: User exists in the `TransitionDomain` table + - VERIFIED_BY_STAFF: User exists in the `VerifiedByStaff` table + - INVITED: User exists in the `DomainInvitation` table + - REGULAR: User was verified through IAL2 + - FIXTURE_USER: User was created by fixtures """ GRANDFATHERED = "grandfathered", "Legacy user" @@ -146,9 +153,23 @@ class User(AbstractUser): return needs_verification def set_user_verification_type(self): - # Would need to check audit log + """ + Given pre-existing data from TransitionDomain, VerifiedByStaff, and DomainInvitation, + set the verification "type" defined in VerificationTypeChoices. + """ retrieved = DomainInvitation.DomainInvitationStatus.RETRIEVED verification_type = self.get_verification_type_from_email(self.email, invitation_status=retrieved) + + # An existing user may have been invited to a domain after they got verified. + # We need to check for this condition. + if verification_type == User.VerificationTypeChoices.INVITED: + invitation = DomainInvitation.objects.filter(email=self.email, status=retrieved).order_by("created_at").first() + + # If you joined BEFORE the oldest invitation was created, then you were verified normally. + # (See logic in get_verification_type_from_email) + if self.date_joined < invitation.created_at: + verification_type = User.VerificationTypeChoices.REGULAR + self.verification_type = verification_type @classmethod From c24a235d8ec6e2c3c23dfd66c807bf7669f279c5 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 22 Apr 2024 13:51:22 -0600 Subject: [PATCH 09/59] Add script to populate data --- docs/operations/data_migration.md | 34 ++++++++++++-- .../commands/populate_verification_type.py | 46 +++++++++++++++++++ 2 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 src/registrar/management/commands/populate_verification_type.py diff --git a/docs/operations/data_migration.md b/docs/operations/data_migration.md index 0846208de..e4543a28c 100644 --- a/docs/operations/data_migration.md +++ b/docs/operations/data_migration.md @@ -602,18 +602,18 @@ That data are synthesized from the generic_org_type field and the is_election_bo The latest domain_election_board csv can be found [here](https://drive.google.com/file/d/1aDeCqwHmBnXBl2arvoFCN0INoZmsEGsQ/view). After downloading this file, place it in `src/migrationdata` -#### Step 2: Upload the domain_election_board file to your sandbox +#### Step 3: Upload the domain_election_board file to your sandbox Follow [Step 1: Transfer data to sandboxes](#step-1-transfer-data-to-sandboxes) and [Step 2: Transfer uploaded files to the getgov directory](#step-2-transfer-uploaded-files-to-the-getgov-directory) from the [Set Up Migrations on Sandbox](#set-up-migrations-on-sandbox) portion of this doc. -#### Step 2: SSH into your environment +#### Step 4: SSH into your environment ```cf ssh getgov-{space}``` Example: `cf ssh getgov-za` -#### Step 3: Create a shell instance +#### Step 5: Create a shell instance ```/tmp/lifecycle/shell``` -#### Step 4: Running the script +#### Step 6: Running the script ```./manage.py populate_organization_type {domain_election_board_filename}``` - The domain_election_board_filename file must adhere to this format: @@ -642,3 +642,29 @@ Example (assuming that this is being ran from src/): | | Parameter | Description | |:-:|:------------------------------------|:-------------------------------------------------------------------| | 1 | **domain_election_board_filename** | A file containing every domain that is an election office. + + +## Populate Verification Type +This section outlines how to run the `populate_verification_type` script. +The script is used to update the verification_type field on User when it is None. + +### Running on sandboxes + +#### Step 1: Login to CloudFoundry +```cf login -a api.fr.cloud.gov --sso``` + +#### Step 2: SSH into your environment +```cf ssh getgov-{space}``` + +Example: `cf ssh getgov-za` + +#### Step 3: Create a shell instance +```/tmp/lifecycle/shell``` + +#### Step 4: Running the script +```./manage.py populate_verification_type``` + +### Running locally + +#### Step 1: Running the script +```docker-compose exec app ./manage.py populate_verification_type``` diff --git a/src/registrar/management/commands/populate_verification_type.py b/src/registrar/management/commands/populate_verification_type.py new file mode 100644 index 000000000..959fefe6c --- /dev/null +++ b/src/registrar/management/commands/populate_verification_type.py @@ -0,0 +1,46 @@ +import argparse +import logging +from typing import List +from django.core.management import BaseCommand +from registrar.management.commands.utility.terminal_helper import TerminalColors, TerminalHelper, ScriptDataHelper +from registrar.models import User + +logger = logging.getLogger(__name__) + + +class Command(BaseCommand): + help = "Loops through each valid User object and updates its verification_type value" + + def handle(self, **kwargs): + """Loops through each valid User object and updates its verification_type value""" + + users = User.objects.filter(verification_type__isnull=True) + + # Code execution will stop here if the user prompts "N" + TerminalHelper.prompt_for_execution( + system_exit_on_terminate=True, + info_to_inspect=f""" + ==Proposed Changes== + Number of User objects to change: {len(users)} + This field will be updated on each record: verification_type + """, + prompt_title="Do you wish to patch verification_type data?", + ) + logger.info("Updating...") + + user_to_update: List[User] = [] + user_failed_to_update: List[User] = [] + for user in users: + try: + user.set_user_verification_type() + user_to_update.append(user) + except Exception as err: + user_failed_to_update.append(user) + logger.error(err) + logger.error(f"{TerminalColors.FAIL}" f"Failed to update {user}" f"{TerminalColors.ENDC}") + + # Do a bulk update on the first_ready field + ScriptDataHelper.bulk_update_fields(User, user_to_update, ["verification_type"]) + + # Log what happened + TerminalHelper.log_script_run_summary(user_to_update, user_failed_to_update, skipped=[], debug=True) From 5aa4e8f484295f1270613bdd7a0478eeff27fb11 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 22 Apr 2024 14:32:42 -0600 Subject: [PATCH 10/59] Add script template --- .../commands/populate_verification_type.py | 46 ++++------------- .../commands/utility/terminal_helper.py | 51 +++++++++++++++++++ 2 files changed, 62 insertions(+), 35 deletions(-) diff --git a/src/registrar/management/commands/populate_verification_type.py b/src/registrar/management/commands/populate_verification_type.py index 959fefe6c..ceaaccc2e 100644 --- a/src/registrar/management/commands/populate_verification_type.py +++ b/src/registrar/management/commands/populate_verification_type.py @@ -1,46 +1,22 @@ -import argparse import logging from typing import List from django.core.management import BaseCommand -from registrar.management.commands.utility.terminal_helper import TerminalColors, TerminalHelper, ScriptDataHelper +from registrar.management.commands.utility.terminal_helper import ScriptTemplate, TerminalColors from registrar.models import User logger = logging.getLogger(__name__) -class Command(BaseCommand): +class Command(ScriptTemplate): help = "Loops through each valid User object and updates its verification_type value" - def handle(self, **kwargs): + def handle(self): """Loops through each valid User object and updates its verification_type value""" - - users = User.objects.filter(verification_type__isnull=True) - - # Code execution will stop here if the user prompts "N" - TerminalHelper.prompt_for_execution( - system_exit_on_terminate=True, - info_to_inspect=f""" - ==Proposed Changes== - Number of User objects to change: {len(users)} - This field will be updated on each record: verification_type - """, - prompt_title="Do you wish to patch verification_type data?", - ) - logger.info("Updating...") - - user_to_update: List[User] = [] - user_failed_to_update: List[User] = [] - for user in users: - try: - user.set_user_verification_type() - user_to_update.append(user) - except Exception as err: - user_failed_to_update.append(user) - logger.error(err) - logger.error(f"{TerminalColors.FAIL}" f"Failed to update {user}" f"{TerminalColors.ENDC}") - - # Do a bulk update on the first_ready field - ScriptDataHelper.bulk_update_fields(User, user_to_update, ["verification_type"]) - - # Log what happened - TerminalHelper.log_script_run_summary(user_to_update, user_failed_to_update, skipped=[], debug=True) + filter_condition = { + "verification_type__isnull": True + } + ScriptTemplate.mass_populate_field(User, filter_condition, ["verification_type"]) + + def populate_field(self, field_to_update): + """Defines how we update the verification_type field""" + field_to_update.set_user_verification_type() diff --git a/src/registrar/management/commands/utility/terminal_helper.py b/src/registrar/management/commands/utility/terminal_helper.py index b54209750..f42ebc1cb 100644 --- a/src/registrar/management/commands/utility/terminal_helper.py +++ b/src/registrar/management/commands/utility/terminal_helper.py @@ -2,6 +2,7 @@ import logging import sys from django.core.paginator import Paginator from typing import List +from django.core.management import BaseCommand from registrar.utility.enums import LogCode logger = logging.getLogger(__name__) @@ -58,6 +59,56 @@ class ScriptDataHelper: model_class.objects.bulk_update(page.object_list, fields_to_update) +class ScriptTemplate(BaseCommand): + """ + Contains common script actions for our scripts which can be prefilled as templates. + """ + + @staticmethod + def mass_populate_field(sender, filter_conditions, fields_to_update): + """Loops through each valid "sender" object - specified by filter_conditions - and + updates fields defined by fields_to_update using populate_function. + + You must define populate_field before you can use this function. + """ + + objects = sender.objects.filter(**filter_conditions) + + # Code execution will stop here if the user prompts "N" + TerminalHelper.prompt_for_execution( + system_exit_on_terminate=True, + info_to_inspect=f""" + ==Proposed Changes== + Number of {sender} objects to change: {len(objects)} + These fields will be updated on each record: {fields_to_update} + """, + prompt_title="Do you wish to patch this data?", + ) + logger.info("Updating...") + + to_update: List[sender] = [] + failed_to_update: List[sender] = [] + for updated_object in objects: + try: + ScriptTemplate.populate_field(updated_object) + to_update.append(updated_object) + except Exception as err: + to_update.append(updated_object) + logger.error(err) + logger.error(f"{TerminalColors.FAIL}" f"Failed to update {updated_object}" f"{TerminalColors.ENDC}") + + # Do a bulk update on the first_ready field + ScriptDataHelper.bulk_update_fields(sender, to_update, fields_to_update) + + # Log what happened + TerminalHelper.log_script_run_summary(to_update, failed_to_update, skipped=[], debug=True) + + @staticmethod + def populate_field(field_to_update): + """Defines how we update each field. Must be defined before using mass_populate_field.""" + raise NotImplementedError("This method should be implemented by the child class.") + + class TerminalHelper: @staticmethod def log_script_run_summary(to_update, failed_to_update, skipped, debug: bool, log_header=None): From 705febe37a7b254952c9a7cce6c68e221bbfdc2d Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 22 Apr 2024 15:25:53 -0600 Subject: [PATCH 11/59] Add kwargs --- src/registrar/management/commands/populate_verification_type.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registrar/management/commands/populate_verification_type.py b/src/registrar/management/commands/populate_verification_type.py index ceaaccc2e..a59f16570 100644 --- a/src/registrar/management/commands/populate_verification_type.py +++ b/src/registrar/management/commands/populate_verification_type.py @@ -10,7 +10,7 @@ logger = logging.getLogger(__name__) class Command(ScriptTemplate): help = "Loops through each valid User object and updates its verification_type value" - def handle(self): + def handle(self, **kwargs): """Loops through each valid User object and updates its verification_type value""" filter_condition = { "verification_type__isnull": True From 9b3466475f0fe7f2dbe0008a860acd648d13bd32 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 22 Apr 2024 15:34:03 -0600 Subject: [PATCH 12/59] Change override --- .../management/commands/populate_verification_type.py | 2 +- .../management/commands/utility/terminal_helper.py | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/registrar/management/commands/populate_verification_type.py b/src/registrar/management/commands/populate_verification_type.py index a59f16570..63ef641d8 100644 --- a/src/registrar/management/commands/populate_verification_type.py +++ b/src/registrar/management/commands/populate_verification_type.py @@ -15,7 +15,7 @@ class Command(ScriptTemplate): filter_condition = { "verification_type__isnull": True } - ScriptTemplate.mass_populate_field(User, filter_condition, ["verification_type"]) + self.mass_populate_field(User, filter_condition, ["verification_type"]) def populate_field(self, field_to_update): """Defines how we update the verification_type field""" diff --git a/src/registrar/management/commands/utility/terminal_helper.py b/src/registrar/management/commands/utility/terminal_helper.py index f42ebc1cb..305be8d8d 100644 --- a/src/registrar/management/commands/utility/terminal_helper.py +++ b/src/registrar/management/commands/utility/terminal_helper.py @@ -64,8 +64,7 @@ class ScriptTemplate(BaseCommand): Contains common script actions for our scripts which can be prefilled as templates. """ - @staticmethod - def mass_populate_field(sender, filter_conditions, fields_to_update): + def mass_populate_field(self, sender, filter_conditions, fields_to_update): """Loops through each valid "sender" object - specified by filter_conditions - and updates fields defined by fields_to_update using populate_function. @@ -90,7 +89,7 @@ class ScriptTemplate(BaseCommand): failed_to_update: List[sender] = [] for updated_object in objects: try: - ScriptTemplate.populate_field(updated_object) + self.populate_field(updated_object) to_update.append(updated_object) except Exception as err: to_update.append(updated_object) @@ -102,9 +101,8 @@ class ScriptTemplate(BaseCommand): # Log what happened TerminalHelper.log_script_run_summary(to_update, failed_to_update, skipped=[], debug=True) - - @staticmethod - def populate_field(field_to_update): + + def populate_field(self, field_to_update): """Defines how we update each field. Must be defined before using mass_populate_field.""" raise NotImplementedError("This method should be implemented by the child class.") From 3f6a9ec1ce08ca5e441a1919ecc651c11e5e6c91 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:13:55 -0600 Subject: [PATCH 13/59] Fix unit test --- src/registrar/tests/test_admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index 20ada4d14..8e9701d59 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -2820,7 +2820,7 @@ class MyUserAdminTest(TestCase): request.user = create_user() fieldsets = self.admin.get_fieldsets(request) expected_fieldsets = ( - (None, {"fields": ("password", "status", "verification_type")}), + (None, {"fields": ("status", "verification_type")}), ("Personal Info", {"fields": ("first_name", "last_name", "email")}), ("Permissions", {"fields": ("is_active", "groups")}), ("Important dates", {"fields": ("last_login", "date_joined")}), From 9ce10c370e48f07880b9d3822c26fdaf7b51560b Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:18:08 -0600 Subject: [PATCH 14/59] Revert "Fix unit test" This reverts commit 3f6a9ec1ce08ca5e441a1919ecc651c11e5e6c91. --- src/registrar/tests/test_admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index 8e9701d59..20ada4d14 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -2820,7 +2820,7 @@ class MyUserAdminTest(TestCase): request.user = create_user() fieldsets = self.admin.get_fieldsets(request) expected_fieldsets = ( - (None, {"fields": ("status", "verification_type")}), + (None, {"fields": ("password", "status", "verification_type")}), ("Personal Info", {"fields": ("first_name", "last_name", "email")}), ("Permissions", {"fields": ("is_active", "groups")}), ("Important dates", {"fields": ("last_login", "date_joined")}), From 54b615d7f88cbce3efc18bed285954bc299395ed Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 23 Apr 2024 13:46:20 -0600 Subject: [PATCH 15/59] Unit tests --- src/djangooidc/tests/test_views.py | 132 +++++++++++++++++++++++++++++ src/registrar/models/user.py | 3 +- 2 files changed, 134 insertions(+), 1 deletion(-) diff --git a/src/djangooidc/tests/test_views.py b/src/djangooidc/tests/test_views.py index f10afcbaf..fc93db82e 100644 --- a/src/djangooidc/tests/test_views.py +++ b/src/djangooidc/tests/test_views.py @@ -4,8 +4,10 @@ from django.http import HttpResponse from django.test import Client, TestCase, RequestFactory from django.urls import reverse +from api.tests.common import less_console_noise_decorator from djangooidc.exceptions import StateMismatch, InternalError from ..views import login_callback +from registrar.models import User, Contact, VerifiedByStaff, DomainInvitation, TransitionDomain, Domain from .common import less_console_noise @@ -15,6 +17,14 @@ class ViewsTest(TestCase): def setUp(self): self.client = Client() self.factory = RequestFactory() + + def tearDown(self): + User.objects.all().delete() + Contact.objects.all().delete() + DomainInvitation.objects.all().delete() + VerifiedByStaff.objects.all().delete() + TransitionDomain.objects.all().delete() + Domain.objects.all().delete() def say_hi(*args): return HttpResponse("Hi") @@ -228,6 +238,128 @@ class ViewsTest(TestCase): # assert that redirect is to / when no 'next' is set self.assertEqual(response.status_code, 302) self.assertEqual(response.url, "/") + + @less_console_noise_decorator + def test_login_callback_sets_verification_type_regular(self, mock_client): + """Test that openid sets the verification type to regular on the returned user""" + # SETUP + session = self.client.session + session.save() + # MOCK + # mock that callback returns user_info; this is the expected behavior + mock_client.callback.side_effect = self.user_info + # patch that the request does not require step up auth + with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch("djangooidc.views._initialize_client") as mock_init_client: + with patch("djangooidc.views._client_is_none", return_value=True): + # TEST + # test the login callback url + response = self.client.get(reverse("openid_login_callback")) + + # assert that _initialize_client was called + mock_init_client.assert_called_once() + + # Assert that we get a redirect + self.assertEqual(response.status_code, 302) + self.assertEqual(response.url, "/") + + # Test the created user object + created_user = User.objects.get(email="test@example.com") + self.assertEqual(created_user.verification_type, User.VerificationTypeChoices.REGULAR) + + @less_console_noise_decorator + def test_login_callback_sets_verification_type_invited(self, mock_client): + """Test that openid sets the verification type to invited on the returned user + when they exist in the DomainInvitation table""" + # SETUP + session = self.client.session + session.save() + + domain, _ = Domain.objects.get_or_create(name="test123.gov") + invitation, _ = DomainInvitation.objects.get_or_create(email="test@example.com", domain=domain) + # MOCK + # mock that callback returns user_info; this is the expected behavior + mock_client.callback.side_effect = self.user_info + # patch that the request does not require step up auth + with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch("djangooidc.views._initialize_client") as mock_init_client: + with patch("djangooidc.views._client_is_none", return_value=True): + # TEST + # test the login callback url + response = self.client.get(reverse("openid_login_callback")) + + # assert that _initialize_client was called + mock_init_client.assert_called_once() + + # Assert that we get a redirect + self.assertEqual(response.status_code, 302) + self.assertEqual(response.url, "/") + + # Test the created user object + created_user = User.objects.get(email="test@example.com") + self.assertEqual(created_user.email, invitation.email) + self.assertEqual(created_user.verification_type, User.VerificationTypeChoices.INVITED) + + @less_console_noise_decorator + def test_login_callback_sets_verification_type_grandfathered(self, mock_client): + """Test that openid sets the verification type to grandfathered on a user which exists in our TransitionDomain table""" + # SETUP + session = self.client.session + session.save() + # MOCK + # mock that callback returns user_info; this is the expected behavior + mock_client.callback.side_effect = self.user_info + + td, _ = TransitionDomain.objects.get_or_create(username="test@example.com", domain_name="test123.gov") + + # patch that the request does not require step up auth + with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch("djangooidc.views._initialize_client") as mock_init_client: + with patch("djangooidc.views._client_is_none", return_value=True): + # TEST + # test the login callback url + response = self.client.get(reverse("openid_login_callback")) + + # assert that _initialize_client was called + mock_init_client.assert_called_once() + + # Assert that we get a redirect + self.assertEqual(response.status_code, 302) + self.assertEqual(response.url, "/") + + # Test the created user object + created_user = User.objects.get(email="test@example.com") + self.assertEqual(created_user.email, td.username) + self.assertEqual(created_user.verification_type, User.VerificationTypeChoices.GRANDFATHERED) + + @less_console_noise_decorator + def test_login_callback_sets_verification_type_verified_by_staff(self, mock_client): + """Test that openid sets the verification type to verified_by_staff + on a user which exists in our VerifiedByStaff table""" + # SETUP + session = self.client.session + session.save() + # MOCK + # mock that callback returns user_info; this is the expected behavior + mock_client.callback.side_effect = self.user_info + + vip, _ = VerifiedByStaff.objects.get_or_create(email="test@example.com") + + # patch that the request does not require step up auth + with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch("djangooidc.views._initialize_client") as mock_init_client: + with patch("djangooidc.views._client_is_none", return_value=True): + # TEST + # test the login callback url + response = self.client.get(reverse("openid_login_callback")) + + # assert that _initialize_client was called + mock_init_client.assert_called_once() + + # Assert that we get a redirect + self.assertEqual(response.status_code, 302) + self.assertEqual(response.url, "/") + + # Test the created user object + created_user = User.objects.get(email="test@example.com") + self.assertEqual(created_user.email, vip.email) + self.assertEqual(created_user.verification_type, User.VerificationTypeChoices.VERIFIED_BY_STAFF) def test_login_callback_no_step_up_auth(self, mock_client): """Walk through login_callback when _requires_step_up_auth returns False diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index f775c77ad..45532f8ea 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -3,6 +3,7 @@ import logging from django.contrib.auth.models import AbstractUser from django.db import models +from django.db.models import Q from registrar.models.user_domain_role import UserDomainRole @@ -177,7 +178,7 @@ class User(AbstractUser): """Retrieves the verification type based off of a provided email address""" verification_type = None - if TransitionDomain.objects.filter(username=email).exists(): + if TransitionDomain.objects.filter(Q(username=email) | Q(email=email)).exists(): # A new incoming user who is a domain manager for one of the domains # that we inputted from Verisign (that is, their email address appears # in the username field of a TransitionDomain) From d1fcb922c635b087d5c356e0f344845a0b3ab63a Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:17:08 -0600 Subject: [PATCH 16/59] Unit tests --- .../commands/populate_verification_type.py | 9 +- .../commands/utility/terminal_helper.py | 2 +- src/registrar/models/user.py | 9 +- .../tests/test_management_scripts.py | 91 ++++++++++++++++++- 4 files changed, 103 insertions(+), 8 deletions(-) diff --git a/src/registrar/management/commands/populate_verification_type.py b/src/registrar/management/commands/populate_verification_type.py index 63ef641d8..da493b8cf 100644 --- a/src/registrar/management/commands/populate_verification_type.py +++ b/src/registrar/management/commands/populate_verification_type.py @@ -12,11 +12,12 @@ class Command(ScriptTemplate): def handle(self, **kwargs): """Loops through each valid User object and updates its verification_type value""" - filter_condition = { - "verification_type__isnull": True - } + filter_condition = {"verification_type__isnull": True} self.mass_populate_field(User, filter_condition, ["verification_type"]) - + def populate_field(self, field_to_update): """Defines how we update the verification_type field""" field_to_update.set_user_verification_type() + logger.info( + f"{TerminalColors.OKCYAN}Updating {field_to_update} => {field_to_update.verification_type}{TerminalColors.OKCYAN}" + ) diff --git a/src/registrar/management/commands/utility/terminal_helper.py b/src/registrar/management/commands/utility/terminal_helper.py index 305be8d8d..1d411e403 100644 --- a/src/registrar/management/commands/utility/terminal_helper.py +++ b/src/registrar/management/commands/utility/terminal_helper.py @@ -65,7 +65,7 @@ class ScriptTemplate(BaseCommand): """ def mass_populate_field(self, sender, filter_conditions, fields_to_update): - """Loops through each valid "sender" object - specified by filter_conditions - and + """Loops through each valid "sender" object - specified by filter_conditions - and updates fields defined by fields_to_update using populate_function. You must define populate_field before you can use this function. diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index 45532f8ea..eb21971f8 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -158,13 +158,18 @@ class User(AbstractUser): Given pre-existing data from TransitionDomain, VerifiedByStaff, and DomainInvitation, set the verification "type" defined in VerificationTypeChoices. """ + email_or_username = self.email or self.username retrieved = DomainInvitation.DomainInvitationStatus.RETRIEVED - verification_type = self.get_verification_type_from_email(self.email, invitation_status=retrieved) + verification_type = self.get_verification_type_from_email(email_or_username, invitation_status=retrieved) # An existing user may have been invited to a domain after they got verified. # We need to check for this condition. if verification_type == User.VerificationTypeChoices.INVITED: - invitation = DomainInvitation.objects.filter(email=self.email, status=retrieved).order_by("created_at").first() + invitation = ( + DomainInvitation.objects.filter(email=email_or_username, status=retrieved) + .order_by("created_at") + .first() + ) # If you joined BEFORE the oldest invitation was created, then you were verified normally. # (See logic in get_verification_type_from_email) diff --git a/src/registrar/tests/test_management_scripts.py b/src/registrar/tests/test_management_scripts.py index 26161b272..68b7f04c9 100644 --- a/src/registrar/tests/test_management_scripts.py +++ b/src/registrar/tests/test_management_scripts.py @@ -14,8 +14,9 @@ from registrar.models import ( TransitionDomain, DomainInformation, UserDomainRole, + VerifiedByStaff, + PublicContact, ) -from registrar.models.public_contact import PublicContact from django.core.management import call_command from unittest.mock import patch, call @@ -25,6 +26,94 @@ from .common import MockEppLib, less_console_noise, completed_domain_request from api.tests.common import less_console_noise_decorator +class TestPopulateVerificationType(MockEppLib): + """Tests for the populate_organization_type script""" + + def setUp(self): + """Creates a fake domain object""" + super().setUp() + + # Get the domain requests + self.domain_request_1 = completed_domain_request( + name="lasers.gov", + generic_org_type=DomainRequest.OrganizationChoices.FEDERAL, + is_election_board=True, + status=DomainRequest.DomainRequestStatus.IN_REVIEW, + ) + + # Approve the request + self.domain_request_1.approve() + + # Get the domains + self.domain_1 = Domain.objects.get(name="lasers.gov") + + # Get users + self.regular_user, _ = User.objects.get_or_create(username="testuser@igormail.gov") + + vip, _ = VerifiedByStaff.objects.get_or_create(email="vipuser@igormail.gov") + self.verified_by_staff_user, _ = User.objects.get_or_create(username="vipuser@igormail.gov") + + grandfathered, _ = TransitionDomain.objects.get_or_create( + username="grandpa@igormail.gov", domain_name=self.domain_1.name + ) + self.grandfathered_user, _ = User.objects.get_or_create(username="grandpa@igormail.gov") + + invited, _ = DomainInvitation.objects.get_or_create(email="invited@igormail.gov", domain=self.domain_1) + self.invited_user, _ = User.objects.get_or_create(username="invited@igormail.gov") + + self.untouched_user, _ = User.objects.get_or_create( + username="iaminvincible@igormail.gov", verification_type=User.VerificationTypeChoices.GRANDFATHERED + ) + + def tearDown(self): + """Deletes all DB objects related to migrations""" + super().tearDown() + + # Delete domains and related information + Domain.objects.all().delete() + DomainInformation.objects.all().delete() + DomainRequest.objects.all().delete() + User.objects.all().delete() + Contact.objects.all().delete() + Website.objects.all().delete() + + @less_console_noise_decorator + def run_populate_verification_type(self): + """ + This method executes the populate_organization_type command. + + The 'call_command' function from Django's management framework is then used to + execute the populate_organization_type command with the specified arguments. + """ + with patch( + "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa + return_value=True, + ): + call_command("populate_verification_type") + + @less_console_noise_decorator + def test_verification_type_script_populates_data(self): + """Ensures that the verification type script actually populates data""" + + # Run the script + self.run_populate_verification_type() + + # Scripts don't work as we'd expect in our test environment, we need to manually + # trigger the refresh event + self.regular_user.refresh_from_db() + self.grandfathered_user.refresh_from_db() + self.invited_user.refresh_from_db() + self.verified_by_staff_user.refresh_from_db() + self.untouched_user.refresh_from_db() + + # Test all users + self.assertEqual(self.regular_user.verification_type, User.VerificationTypeChoices.REGULAR) + self.assertEqual(self.grandfathered_user.verification_type, User.VerificationTypeChoices.GRANDFATHERED) + self.assertEqual(self.invited_user.verification_type, User.VerificationTypeChoices.INVITED) + self.assertEqual(self.verified_by_staff_user.verification_type, User.VerificationTypeChoices.VERIFIED_BY_STAFF) + self.assertEqual(self.untouched_user.verification_type, User.VerificationTypeChoices.GRANDFATHERED) + + class TestPopulateOrganizationType(MockEppLib): """Tests for the populate_organization_type script""" From 883595ba446a3df7c431897f39afcea6b9acb614 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:25:48 -0600 Subject: [PATCH 17/59] Add unit tests --- src/registrar/models/user.py | 4 ++-- src/registrar/tests/test_management_scripts.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index eb21971f8..3a37f5b61 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -158,7 +158,7 @@ class User(AbstractUser): Given pre-existing data from TransitionDomain, VerifiedByStaff, and DomainInvitation, set the verification "type" defined in VerificationTypeChoices. """ - email_or_username = self.email or self.username + email_or_username = self.email if self.email else self.username retrieved = DomainInvitation.DomainInvitationStatus.RETRIEVED verification_type = self.get_verification_type_from_email(email_or_username, invitation_status=retrieved) @@ -173,7 +173,7 @@ class User(AbstractUser): # If you joined BEFORE the oldest invitation was created, then you were verified normally. # (See logic in get_verification_type_from_email) - if self.date_joined < invitation.created_at: + if invitation is not None and self.date_joined < invitation.created_at: verification_type = User.VerificationTypeChoices.REGULAR self.verification_type = verification_type diff --git a/src/registrar/tests/test_management_scripts.py b/src/registrar/tests/test_management_scripts.py index 68b7f04c9..617e305a1 100644 --- a/src/registrar/tests/test_management_scripts.py +++ b/src/registrar/tests/test_management_scripts.py @@ -58,13 +58,21 @@ class TestPopulateVerificationType(MockEppLib): ) self.grandfathered_user, _ = User.objects.get_or_create(username="grandpa@igormail.gov") - invited, _ = DomainInvitation.objects.get_or_create(email="invited@igormail.gov", domain=self.domain_1) + invited, _ = DomainInvitation.objects.get_or_create( + email="invited@igormail.gov", domain=self.domain_1, status=DomainInvitation.DomainInvitationStatus.RETRIEVED + ) self.invited_user, _ = User.objects.get_or_create(username="invited@igormail.gov") self.untouched_user, _ = User.objects.get_or_create( username="iaminvincible@igormail.gov", verification_type=User.VerificationTypeChoices.GRANDFATHERED ) + # Fixture users should be untouched by the script. These will auto update once the + # user logs in / creates an account. + self.fixture_user, _ = User.objects.get_or_create( + username="fixture@igormail.gov", verification_type=User.VerificationTypeChoices.FIXTURE_USER + ) + def tearDown(self): """Deletes all DB objects related to migrations""" super().tearDown() @@ -112,6 +120,7 @@ class TestPopulateVerificationType(MockEppLib): self.assertEqual(self.invited_user.verification_type, User.VerificationTypeChoices.INVITED) self.assertEqual(self.verified_by_staff_user.verification_type, User.VerificationTypeChoices.VERIFIED_BY_STAFF) self.assertEqual(self.untouched_user.verification_type, User.VerificationTypeChoices.GRANDFATHERED) + self.assertEqual(self.fixture_user.verification_type, User.VerificationTypeChoices.FIXTURE_USER) class TestPopulateOrganizationType(MockEppLib): From aad29096c1dbd6c279964094d67a6f88026e2018 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Wed, 24 Apr 2024 09:19:15 -0600 Subject: [PATCH 18/59] Fix migrations --- ...ication_type.py => 0088_user_verification_type.py} | 4 ++-- .../django/admin/includes/detail_table_fieldset.html | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) rename src/registrar/migrations/{0087_user_verification_type.py => 0088_user_verification_type.py} (84%) diff --git a/src/registrar/migrations/0087_user_verification_type.py b/src/registrar/migrations/0088_user_verification_type.py similarity index 84% rename from src/registrar/migrations/0087_user_verification_type.py rename to src/registrar/migrations/0088_user_verification_type.py index 599d067d5..7fac95a3d 100644 --- a/src/registrar/migrations/0087_user_verification_type.py +++ b/src/registrar/migrations/0088_user_verification_type.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.10 on 2024-04-22 16:40 +# Generated by Django 4.2.10 on 2024-04-23 20:47 from django.db import migrations, models @@ -6,7 +6,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ("registrar", "0086_domaininformation_updated_federal_agency_and_more"), + ("registrar", "0087_alter_domain_deleted_alter_domain_expiration_date_and_more"), ] operations = [ diff --git a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html index 6374406c1..0f4202b7e 100644 --- a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html +++ b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html @@ -4,10 +4,11 @@ {% comment %} This is using a custom implementation fieldset.html (see admin/fieldset.html) {% endcomment %} + {% block field_readonly %} {% with all_contacts=original_object.other_contacts.all %} {% if field.field.name == "creator" %} -
{{ field.contents }} ({{ user.verification_type }})
+
{{ field.contents }} ({{ user.get_verification_type_display }})
{% elif field.field.name == "other_contacts" %} {% if all_contacts.count > 2 %}
@@ -68,9 +69,15 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html) {% endblock field_readonly %} {% block help_text %} -
+
{{ field.field.help_text|safe }}
+ + {% if not field.is_readonly and field.field.name == "creator" %} +
+
({{ user.get_verification_type_display }})
+
+ {% endif %} {% endblock help_text %} From 4fa777d671bfd46b233b67dd8c9dc34c74072bda Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:58:45 -0600 Subject: [PATCH 19/59] Add verification type --- .../admin/includes/contact_detail_list.html | 7 ++++++- .../admin/includes/detail_table_fieldset.html | 19 ++----------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/registrar/templates/django/admin/includes/contact_detail_list.html b/src/registrar/templates/django/admin/includes/contact_detail_list.html index 5ac5452e3..3b49e62a4 100644 --- a/src/registrar/templates/django/admin/includes/contact_detail_list.html +++ b/src/registrar/templates/django/admin/includes/contact_detail_list.html @@ -47,7 +47,12 @@ {% else %} None
{% endif %} + {% else %} - No additional contact information found. + No additional contact information found.
+ {% endif %} + + {% if user_verification_type %} + {{ user_verification_type }} {% endif %}
diff --git a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html index 0f4202b7e..c85bfd27a 100644 --- a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html +++ b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html @@ -7,9 +7,7 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html) {% block field_readonly %} {% with all_contacts=original_object.other_contacts.all %} - {% if field.field.name == "creator" %} -
{{ field.contents }} ({{ user.get_verification_type_display }})
- {% elif field.field.name == "other_contacts" %} + {% if field.field.name == "other_contacts" %} {% if all_contacts.count > 2 %}
{% for contact in all_contacts %} @@ -68,24 +66,11 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html) {% endwith %} {% endblock field_readonly %} -{% block help_text %} -
-
{{ field.field.help_text|safe }}
-
- - {% if not field.is_readonly and field.field.name == "creator" %} -
-
({{ user.get_verification_type_display }})
-
- {% endif %} -{% endblock help_text %} - - {% block after_help_text %} {% if field.field.name == "creator" %}
- {% include "django/admin/includes/contact_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly %} + {% include "django/admin/includes/contact_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly user_verification_type=original_object.creator.get_verification_type_display%}
{% include "django/admin/includes/user_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly %} {% elif field.field.name == "submitter" %} From 07ac2b8fa4f2f15fb62b5f550c44c28b275fb1fa Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:06:23 -0600 Subject: [PATCH 20/59] Add padding --- src/registrar/assets/sass/_theme/_admin.scss | 4 ++++ .../django/admin/includes/detail_table_fieldset.html | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/registrar/assets/sass/_theme/_admin.scss b/src/registrar/assets/sass/_theme/_admin.scss index f5717d067..e22ec905e 100644 --- a/src/registrar/assets/sass/_theme/_admin.scss +++ b/src/registrar/assets/sass/_theme/_admin.scss @@ -617,3 +617,7 @@ address.dja-address-contact-list { .usa-button__small-text { font-size: small; } + +.padding-left-0__important { + padding-left: 0px !important; +} diff --git a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html index c85bfd27a..123773313 100644 --- a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html +++ b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html @@ -66,9 +66,15 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html) {% endwith %} {% endblock field_readonly %} +{% block help_text %} +
+
{{ field.field.help_text|safe }}
+
+{% endblock help_text %} + {% block after_help_text %} {% if field.field.name == "creator" %} -
+
{% include "django/admin/includes/contact_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly user_verification_type=original_object.creator.get_verification_type_display%}
From 2a10e76c5d7b244e63c18b51c6f0e5e7ecf32a4c Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:12:50 -0600 Subject: [PATCH 21/59] Add additional padding --- .../django/admin/includes/detail_table_fieldset.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html index 123773313..d96fa469c 100644 --- a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html +++ b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html @@ -74,13 +74,13 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html) {% block after_help_text %} {% if field.field.name == "creator" %} -
+
{% include "django/admin/includes/contact_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly user_verification_type=original_object.creator.get_verification_type_display%}
{% include "django/admin/includes/user_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly %} {% elif field.field.name == "submitter" %} -
+
{% include "django/admin/includes/contact_detail_list.html" with user=original_object.submitter no_title_top_padding=field.is_readonly %}
From 9e6cddb02e94e950ef4a01d7a0d9c6e0e17c8b22 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:18:25 -0600 Subject: [PATCH 22/59] Margin top 2 --- .../django/admin/includes/detail_table_fieldset.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html index d96fa469c..9ec5e500d 100644 --- a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html +++ b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html @@ -74,13 +74,13 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html) {% block after_help_text %} {% if field.field.name == "creator" %} -
+
{% include "django/admin/includes/contact_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly user_verification_type=original_object.creator.get_verification_type_display%}
{% include "django/admin/includes/user_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly %} {% elif field.field.name == "submitter" %} -
+
{% include "django/admin/includes/contact_detail_list.html" with user=original_object.submitter no_title_top_padding=field.is_readonly %}
From 9d1f87ce7873af9d53f599d2a4d521a592fcb5ff Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:46:49 -0600 Subject: [PATCH 23/59] Switch to ABC --- .../management/commands/populate_verification_type.py | 4 ++-- .../management/commands/utility/terminal_helper.py | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/registrar/management/commands/populate_verification_type.py b/src/registrar/management/commands/populate_verification_type.py index da493b8cf..a20c3e809 100644 --- a/src/registrar/management/commands/populate_verification_type.py +++ b/src/registrar/management/commands/populate_verification_type.py @@ -1,13 +1,13 @@ import logging from typing import List from django.core.management import BaseCommand -from registrar.management.commands.utility.terminal_helper import ScriptTemplate, TerminalColors +from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors from registrar.models import User logger = logging.getLogger(__name__) -class Command(ScriptTemplate): +class Command(BaseCommand, PopulateScriptTemplate): help = "Loops through each valid User object and updates its verification_type value" def handle(self, **kwargs): diff --git a/src/registrar/management/commands/utility/terminal_helper.py b/src/registrar/management/commands/utility/terminal_helper.py index 1d411e403..5076d1de8 100644 --- a/src/registrar/management/commands/utility/terminal_helper.py +++ b/src/registrar/management/commands/utility/terminal_helper.py @@ -1,5 +1,6 @@ import logging import sys +from abc import ABC, abstractmethod from django.core.paginator import Paginator from typing import List from django.core.management import BaseCommand @@ -59,9 +60,9 @@ class ScriptDataHelper: model_class.objects.bulk_update(page.object_list, fields_to_update) -class ScriptTemplate(BaseCommand): +class PopulateScriptTemplate(ABC): """ - Contains common script actions for our scripts which can be prefilled as templates. + Contains an ABC for generic populate scripts """ def mass_populate_field(self, sender, filter_conditions, fields_to_update): @@ -102,9 +103,10 @@ class ScriptTemplate(BaseCommand): # Log what happened TerminalHelper.log_script_run_summary(to_update, failed_to_update, skipped=[], debug=True) + @abstractmethod def populate_field(self, field_to_update): """Defines how we update each field. Must be defined before using mass_populate_field.""" - raise NotImplementedError("This method should be implemented by the child class.") + pass class TerminalHelper: From 86ef903a0794f05460ac1675fa0ffa052220dce2 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 26 Apr 2024 08:00:34 -0600 Subject: [PATCH 24/59] Remove help text padding css --- src/registrar/assets/sass/_theme/_admin.scss | 5 +++-- .../django/admin/includes/detail_table_fieldset.html | 6 ------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/registrar/assets/sass/_theme/_admin.scss b/src/registrar/assets/sass/_theme/_admin.scss index e22ec905e..5c577dbb7 100644 --- a/src/registrar/assets/sass/_theme/_admin.scss +++ b/src/registrar/assets/sass/_theme/_admin.scss @@ -618,6 +618,7 @@ address.dja-address-contact-list { font-size: small; } -.padding-left-0__important { - padding-left: 0px !important; +// Get rid of padding on all help texts +form .aligned p.help, form .aligned div.help { + padding-left: 0px } diff --git a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html index 9ec5e500d..ea8e7579f 100644 --- a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html +++ b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html @@ -66,12 +66,6 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html) {% endwith %} {% endblock field_readonly %} -{% block help_text %} -
-
{{ field.field.help_text|safe }}
-
-{% endblock help_text %} - {% block after_help_text %} {% if field.field.name == "creator" %}
From d9408076b13f63c5f85571da1487f0fb0ecf2af5 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 26 Apr 2024 08:07:50 -0600 Subject: [PATCH 25/59] Fix migrations, PR suggestions --- src/djangooidc/tests/test_views.py | 5 ++++- .../management/commands/utility/terminal_helper.py | 2 +- ..._verification_type.py => 0089_user_verification_type.py} | 4 ++-- src/registrar/models/user.py | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) rename src/registrar/migrations/{0088_user_verification_type.py => 0089_user_verification_type.py} (84%) diff --git a/src/djangooidc/tests/test_views.py b/src/djangooidc/tests/test_views.py index fc93db82e..faf9cbdd8 100644 --- a/src/djangooidc/tests/test_views.py +++ b/src/djangooidc/tests/test_views.py @@ -241,7 +241,10 @@ class ViewsTest(TestCase): @less_console_noise_decorator def test_login_callback_sets_verification_type_regular(self, mock_client): - """Test that openid sets the verification type to regular on the returned user""" + """ + Test that openid sets the verification type to regular on the returned user. + Regular, in this context, means that this user was "Verifed by Login.gov" + """ # SETUP session = self.client.session session.save() diff --git a/src/registrar/management/commands/utility/terminal_helper.py b/src/registrar/management/commands/utility/terminal_helper.py index 5076d1de8..2376439a6 100644 --- a/src/registrar/management/commands/utility/terminal_helper.py +++ b/src/registrar/management/commands/utility/terminal_helper.py @@ -93,7 +93,7 @@ class PopulateScriptTemplate(ABC): self.populate_field(updated_object) to_update.append(updated_object) except Exception as err: - to_update.append(updated_object) + failed_to_update.append(updated_object) logger.error(err) logger.error(f"{TerminalColors.FAIL}" f"Failed to update {updated_object}" f"{TerminalColors.ENDC}") diff --git a/src/registrar/migrations/0088_user_verification_type.py b/src/registrar/migrations/0089_user_verification_type.py similarity index 84% rename from src/registrar/migrations/0088_user_verification_type.py rename to src/registrar/migrations/0089_user_verification_type.py index 7fac95a3d..e021e89e1 100644 --- a/src/registrar/migrations/0088_user_verification_type.py +++ b/src/registrar/migrations/0089_user_verification_type.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.10 on 2024-04-23 20:47 +# Generated by Django 4.2.10 on 2024-04-26 14:03 from django.db import migrations, models @@ -6,7 +6,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ("registrar", "0087_alter_domain_deleted_alter_domain_expiration_date_and_more"), + ("registrar", "0088_domaininformation_cisa_representative_email_and_more"), ] operations = [ diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index 0b16d45cb..0ae785562 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -149,10 +149,10 @@ class User(AbstractUser): # always exist at this point. We do it down the line. verification_type = cls.get_verification_type_from_email(email) + # Checks if the user needs verification. # The user needs identity verification if they don't meet # any special criteria, i.e. we are validating them "regularly" - needs_verification = verification_type == cls.VerificationTypeChoices.REGULAR - return needs_verification + return verification_type == cls.VerificationTypeChoices.REGULAR def set_user_verification_type(self): """ @@ -174,7 +174,7 @@ class User(AbstractUser): # If you joined BEFORE the oldest invitation was created, then you were verified normally. # (See logic in get_verification_type_from_email) - if invitation is not None and self.date_joined < invitation.created_at: + if not invitation and self.date_joined < invitation.created_at: verification_type = User.VerificationTypeChoices.REGULAR self.verification_type = verification_type From 83c7a5cdfdbbd22d1d3f224d3b7cf8ad5e1143be Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 26 Apr 2024 08:11:43 -0600 Subject: [PATCH 26/59] Linting --- src/djangooidc/tests/test_views.py | 22 +++++++++++++++------- src/registrar/admin.py | 7 ++++++- src/registrar/models/user.py | 1 - src/registrar/tests/test_admin.py | 10 +++++++++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/djangooidc/tests/test_views.py b/src/djangooidc/tests/test_views.py index faf9cbdd8..36a7e1e47 100644 --- a/src/djangooidc/tests/test_views.py +++ b/src/djangooidc/tests/test_views.py @@ -17,7 +17,7 @@ class ViewsTest(TestCase): def setUp(self): self.client = Client() self.factory = RequestFactory() - + def tearDown(self): User.objects.all().delete() Contact.objects.all().delete() @@ -238,7 +238,7 @@ class ViewsTest(TestCase): # assert that redirect is to / when no 'next' is set self.assertEqual(response.status_code, 302) self.assertEqual(response.url, "/") - + @less_console_noise_decorator def test_login_callback_sets_verification_type_regular(self, mock_client): """ @@ -252,7 +252,9 @@ class ViewsTest(TestCase): # mock that callback returns user_info; this is the expected behavior mock_client.callback.side_effect = self.user_info # patch that the request does not require step up auth - with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch("djangooidc.views._initialize_client") as mock_init_client: + with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch( + "djangooidc.views._initialize_client" + ) as mock_init_client: with patch("djangooidc.views._client_is_none", return_value=True): # TEST # test the login callback url @@ -283,7 +285,9 @@ class ViewsTest(TestCase): # mock that callback returns user_info; this is the expected behavior mock_client.callback.side_effect = self.user_info # patch that the request does not require step up auth - with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch("djangooidc.views._initialize_client") as mock_init_client: + with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch( + "djangooidc.views._initialize_client" + ) as mock_init_client: with patch("djangooidc.views._client_is_none", return_value=True): # TEST # test the login callback url @@ -314,7 +318,9 @@ class ViewsTest(TestCase): td, _ = TransitionDomain.objects.get_or_create(username="test@example.com", domain_name="test123.gov") # patch that the request does not require step up auth - with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch("djangooidc.views._initialize_client") as mock_init_client: + with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch( + "djangooidc.views._initialize_client" + ) as mock_init_client: with patch("djangooidc.views._client_is_none", return_value=True): # TEST # test the login callback url @@ -334,7 +340,7 @@ class ViewsTest(TestCase): @less_console_noise_decorator def test_login_callback_sets_verification_type_verified_by_staff(self, mock_client): - """Test that openid sets the verification type to verified_by_staff + """Test that openid sets the verification type to verified_by_staff on a user which exists in our VerifiedByStaff table""" # SETUP session = self.client.session @@ -346,7 +352,9 @@ class ViewsTest(TestCase): vip, _ = VerifiedByStaff.objects.get_or_create(email="test@example.com") # patch that the request does not require step up auth - with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch("djangooidc.views._initialize_client") as mock_init_client: + with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch( + "djangooidc.views._initialize_client" + ) as mock_init_client: with patch("djangooidc.views._client_is_none", return_value=True): # TEST # test the login callback url diff --git a/src/registrar/admin.py b/src/registrar/admin.py index b7a5a0503..e1378ec53 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -563,7 +563,12 @@ class MyUserAdmin(BaseUserAdmin): analyst_fieldsets = ( ( None, - {"fields": ("status", "verification_type",)}, + { + "fields": ( + "status", + "verification_type", + ) + }, ), ("Personal Info", {"fields": ("first_name", "last_name", "email")}), ( diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index 0ae785562..5e4c88f63 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -1,4 +1,3 @@ -from enum import Enum import logging from django.contrib.auth.models import AbstractUser diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index eeda99efb..f853c7b11 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -3043,7 +3043,15 @@ class TestMyUserAdmin(TestCase): request.user = create_user() fieldsets = self.admin.get_fieldsets(request) expected_fieldsets = ( - (None, {"fields": ("status", "verification_type",)}), + ( + None, + { + "fields": ( + "status", + "verification_type", + ) + }, + ), ("Personal Info", {"fields": ("first_name", "last_name", "email")}), ("Permissions", {"fields": ("is_active", "groups")}), ("Important dates", {"fields": ("last_login", "date_joined")}), From a7ef0cfa03d2ee96804709240a38254a084c5dfa Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 26 Apr 2024 08:21:53 -0600 Subject: [PATCH 27/59] Update _admin.scss --- src/registrar/assets/sass/_theme/_admin.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registrar/assets/sass/_theme/_admin.scss b/src/registrar/assets/sass/_theme/_admin.scss index 5c577dbb7..82224e6ee 100644 --- a/src/registrar/assets/sass/_theme/_admin.scss +++ b/src/registrar/assets/sass/_theme/_admin.scss @@ -620,5 +620,5 @@ address.dja-address-contact-list { // Get rid of padding on all help texts form .aligned p.help, form .aligned div.help { - padding-left: 0px + padding-left: 0px !important; } From 0e92cd41dbfd1cbddf9900c74a835e7e003992e2 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 26 Apr 2024 08:28:50 -0600 Subject: [PATCH 28/59] Linting pt 2 --- .../management/commands/populate_verification_type.py | 3 ++- src/registrar/management/commands/utility/terminal_helper.py | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/registrar/management/commands/populate_verification_type.py b/src/registrar/management/commands/populate_verification_type.py index a20c3e809..802116fbc 100644 --- a/src/registrar/management/commands/populate_verification_type.py +++ b/src/registrar/management/commands/populate_verification_type.py @@ -19,5 +19,6 @@ class Command(BaseCommand, PopulateScriptTemplate): """Defines how we update the verification_type field""" field_to_update.set_user_verification_type() logger.info( - f"{TerminalColors.OKCYAN}Updating {field_to_update} => {field_to_update.verification_type}{TerminalColors.OKCYAN}" + f"{TerminalColors.OKCYAN}Updating {field_to_update} => " + f"{field_to_update.verification_type}{TerminalColors.OKCYAN}" ) diff --git a/src/registrar/management/commands/utility/terminal_helper.py b/src/registrar/management/commands/utility/terminal_helper.py index 2376439a6..255d576db 100644 --- a/src/registrar/management/commands/utility/terminal_helper.py +++ b/src/registrar/management/commands/utility/terminal_helper.py @@ -3,7 +3,6 @@ import sys from abc import ABC, abstractmethod from django.core.paginator import Paginator from typing import List -from django.core.management import BaseCommand from registrar.utility.enums import LogCode logger = logging.getLogger(__name__) @@ -106,7 +105,7 @@ class PopulateScriptTemplate(ABC): @abstractmethod def populate_field(self, field_to_update): """Defines how we update each field. Must be defined before using mass_populate_field.""" - pass + pass # noqa class TerminalHelper: From 914cab8fc8cebadc0e86215ccdc218626400f000 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 26 Apr 2024 12:21:08 -0600 Subject: [PATCH 29/59] Linting fix --- src/djangooidc/tests/test_views.py | 3 ++- .../management/commands/populate_verification_type.py | 1 - src/registrar/management/commands/utility/terminal_helper.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/djangooidc/tests/test_views.py b/src/djangooidc/tests/test_views.py index 36a7e1e47..bdd61b346 100644 --- a/src/djangooidc/tests/test_views.py +++ b/src/djangooidc/tests/test_views.py @@ -307,7 +307,8 @@ class ViewsTest(TestCase): @less_console_noise_decorator def test_login_callback_sets_verification_type_grandfathered(self, mock_client): - """Test that openid sets the verification type to grandfathered on a user which exists in our TransitionDomain table""" + """Test that openid sets the verification type to grandfathered + on a user which exists in our TransitionDomain table""" # SETUP session = self.client.session session.save() diff --git a/src/registrar/management/commands/populate_verification_type.py b/src/registrar/management/commands/populate_verification_type.py index 802116fbc..b61521977 100644 --- a/src/registrar/management/commands/populate_verification_type.py +++ b/src/registrar/management/commands/populate_verification_type.py @@ -1,5 +1,4 @@ import logging -from typing import List from django.core.management import BaseCommand from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors from registrar.models import User diff --git a/src/registrar/management/commands/utility/terminal_helper.py b/src/registrar/management/commands/utility/terminal_helper.py index 255d576db..db3e4a9d3 100644 --- a/src/registrar/management/commands/utility/terminal_helper.py +++ b/src/registrar/management/commands/utility/terminal_helper.py @@ -105,7 +105,7 @@ class PopulateScriptTemplate(ABC): @abstractmethod def populate_field(self, field_to_update): """Defines how we update each field. Must be defined before using mass_populate_field.""" - pass # noqa + raise NotImplementedError class TerminalHelper: From cb88a49079d2921cba819dae117639ba1ddaaac7 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 10:37:31 -0600 Subject: [PATCH 30/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index f7f4a0d65..a50abc421 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -38,6 +38,9 @@ jobs: runs-on: ubuntu-latest needs: [variables] steps: + - uses: actions/setup-node@v4 + with: + node-version: '23.0.0-nightly202404297c3dce0e4f' - uses: actions/checkout@v3 - name: Compile USWDS assets working-directory: ./src From eeb5206c157e7d152c48be040437e6fa81daca9f Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 10:43:08 -0600 Subject: [PATCH 31/59] Change uses order --- .github/workflows/deploy-sandbox.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index a50abc421..a6b315d6b 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -38,10 +38,10 @@ jobs: runs-on: ubuntu-latest needs: [variables] steps: + - uses: actions/checkout@v3 - uses: actions/setup-node@v4 with: node-version: '23.0.0-nightly202404297c3dce0e4f' - - uses: actions/checkout@v3 - name: Compile USWDS assets working-directory: ./src run: | From 00c8d1cd42a46f69e080eb8094c50be8decd53bb Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 12:29:05 -0600 Subject: [PATCH 32/59] Update package.json --- src/package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/package.json b/src/package.json index 274e0e282..780ef587f 100644 --- a/src/package.json +++ b/src/package.json @@ -3,6 +3,10 @@ "version": "1.0.0", "description": "========================", "main": "index.js", + "engines": { + "node": "21.7.3" + }, + "engineStrict": true, "scripts": { "pa11y-ci": "pa11y-ci", "test": "echo \"Error: no test specified\" && exit 1" From 13ab27aee27ad7baaf14214cfc9af8f8e1163016 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:02:06 -0600 Subject: [PATCH 33/59] Update version --- .github/workflows/deploy-sandbox.yaml | 3 --- src/node.Dockerfile | 6 ++++-- src/package-lock.json | 4 ++++ src/package.json | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index a6b315d6b..f7f4a0d65 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -39,9 +39,6 @@ jobs: needs: [variables] steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v4 - with: - node-version: '23.0.0-nightly202404297c3dce0e4f' - name: Compile USWDS assets working-directory: ./src run: | diff --git a/src/node.Dockerfile b/src/node.Dockerfile index b478a8a26..cf0b6acc6 100644 --- a/src/node.Dockerfile +++ b/src/node.Dockerfile @@ -1,5 +1,5 @@ FROM docker.io/cimg/node:current-browsers - +FROM node:21.7.3 WORKDIR /app # Install app dependencies @@ -7,4 +7,6 @@ WORKDIR /app # where available (npm@5+) COPY --chown=circleci:circleci package*.json ./ -RUN npm install + +RUN npm install -g npm@10.5.0 +RUN npm install \ No newline at end of file diff --git a/src/package-lock.json b/src/package-lock.json index dc1464ee8..9df99a739 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -15,6 +15,10 @@ }, "devDependencies": { "@uswds/compile": "^1.0.0-beta.3" + }, + "engines": { + "node": "21.7.3", + "npm": "10.5.0" } }, "node_modules/@gulp-sourcemaps/identity-map": { diff --git a/src/package.json b/src/package.json index 780ef587f..1ceb8cb93 100644 --- a/src/package.json +++ b/src/package.json @@ -4,7 +4,8 @@ "description": "========================", "main": "index.js", "engines": { - "node": "21.7.3" + "node": "21.7.3", + "npm": "10.5.0" }, "engineStrict": true, "scripts": { From 09b8ec67ef38d59f517687fd617c2afdef219613 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:08:16 -0600 Subject: [PATCH 34/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index f7f4a0d65..3e0f1e881 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -39,6 +39,9 @@ jobs: needs: [variables] steps: - uses: actions/checkout@v3 + - uses: actions/setup-node@v4 + with: + node-version: '21.7.3' - name: Compile USWDS assets working-directory: ./src run: | From 5e03834954e51e43095418c43bf128b530fbebeb Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:12:57 -0600 Subject: [PATCH 35/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 3e0f1e881..78d924155 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -39,9 +39,13 @@ jobs: needs: [variables] steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v4 + - name: Set up Node js + uses: actions/setup-node@v4 with: node-version: '21.7.3' + run: | + npm install -g npm@10.5.0 + npm install -g node@21.7.3 - name: Compile USWDS assets working-directory: ./src run: | From ec69d7f6967f6eca39444d8d73aee35ed451f7e1 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:14:35 -0600 Subject: [PATCH 36/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 78d924155..0eba23b83 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -39,16 +39,13 @@ jobs: needs: [variables] steps: - uses: actions/checkout@v3 - - name: Set up Node js - uses: actions/setup-node@v4 - with: - node-version: '21.7.3' - run: | - npm install -g npm@10.5.0 - npm install -g node@21.7.3 - name: Compile USWDS assets + uses: actions/setup-node@v4 + with: + node-version: '21.7.3' working-directory: ./src run: | + docker compose run node npm install -g npm@10.5.0 docker compose run node npm install && docker compose run node npx gulp copyAssets && docker compose run node npx gulp compile From e1e04d977859bb395629ce30e97bea4a7d4001d4 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:16:35 -0600 Subject: [PATCH 37/59] Specify node version --- .github/workflows/deploy-sandbox.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 0eba23b83..036cbe503 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -40,12 +40,10 @@ jobs: steps: - uses: actions/checkout@v3 - name: Compile USWDS assets - uses: actions/setup-node@v4 - with: - node-version: '21.7.3' working-directory: ./src run: | - docker compose run node npm install -g npm@10.5.0 + docker compose run node npm install -g node@21.7.3 && + docker compose run node npm install -g npm@10.5.0 && docker compose run node npm install && docker compose run node npx gulp copyAssets && docker compose run node npx gulp compile From 2f4ac994c7e02eae1201b71159ae97c791efb422 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:21:39 -0600 Subject: [PATCH 38/59] use nvm --- .github/workflows/deploy-sandbox.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 036cbe503..4253d9a41 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -42,8 +42,8 @@ jobs: - name: Compile USWDS assets working-directory: ./src run: | - docker compose run node npm install -g node@21.7.3 && - docker compose run node npm install -g npm@10.5.0 && + nvm install 21.7.3 && + nvm use 21.7.3 && docker compose run node npm install && docker compose run node npx gulp copyAssets && docker compose run node npx gulp compile From 3865d8440c7a327e0fa0f4ccf024627cacf9b7df Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:23:09 -0600 Subject: [PATCH 39/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 4253d9a41..7be51fbba 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -42,6 +42,10 @@ jobs: - name: Compile USWDS assets working-directory: ./src run: | + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" nvm install 21.7.3 && nvm use 21.7.3 && docker compose run node npm install && From 04080d85f32c9fe847f5755ece1192b74bac7eb9 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:28:27 -0600 Subject: [PATCH 40/59] Use correct node version --- .github/workflows/deploy-sandbox.yaml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 7be51fbba..77593b3d5 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -39,15 +39,13 @@ jobs: needs: [variables] steps: - uses: actions/checkout@v3 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '21.7.3' - name: Compile USWDS assets working-directory: ./src run: | - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" - [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" - nvm install 21.7.3 && - nvm use 21.7.3 && docker compose run node npm install && docker compose run node npx gulp copyAssets && docker compose run node npx gulp compile From 66558ae80c39e8abc34ad975cbbcb0387d1c3773 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:34:00 -0600 Subject: [PATCH 41/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 77593b3d5..67a8e7476 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -40,13 +40,21 @@ jobs: steps: - uses: actions/checkout@v3 - name: Setup Node.js + working-directory: ./src uses: actions/setup-node@v4 with: node-version: '21.7.3' + cache: 'npm' + + - name: Prepare Node environment and install dependencies + working-directory: ./src + run: | + docker compose run node npm install -g npm@10.5.0 + docker compose run node npm install + - name: Compile USWDS assets working-directory: ./src run: | - docker compose run node npm install && docker compose run node npx gulp copyAssets && docker compose run node npx gulp compile - name: Collect static assets From e663dee659cf38183cb3dc7e086e9bc36934e2fe Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:35:58 -0600 Subject: [PATCH 42/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 67a8e7476..e7972454f 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -45,12 +45,10 @@ jobs: with: node-version: '21.7.3' cache: 'npm' - - - name: Prepare Node environment and install dependencies + - name: Prepare Node environment and adjust permissions working-directory: ./src run: | - docker compose run node npm install -g npm@10.5.0 - docker compose run node npm install + docker compose run node sh -c "chown circleci:circleci package*.json && npm install -g npm@10.5.0 && npm install" - name: Compile USWDS assets working-directory: ./src From 1313527b9d45f663d904326155de92e8a789087c Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:36:22 -0600 Subject: [PATCH 43/59] Remove cache --- .github/workflows/deploy-sandbox.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index e7972454f..b7798f858 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -44,7 +44,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: '21.7.3' - cache: 'npm' + - name: Prepare Node environment and adjust permissions working-directory: ./src run: | From 9ca48c06d9f082e4ccf452c9bc0661fa0382e71f Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:38:00 -0600 Subject: [PATCH 44/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index b7798f858..6c9821112 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -44,15 +44,11 @@ jobs: uses: actions/setup-node@v4 with: node-version: '21.7.3' - - - name: Prepare Node environment and adjust permissions - working-directory: ./src - run: | - docker compose run node sh -c "chown circleci:circleci package*.json && npm install -g npm@10.5.0 && npm install" - - name: Compile USWDS assets working-directory: ./src run: | + docker compose run node npm install && + docker compose run node npm install npm@10.5.0 && docker compose run node npx gulp copyAssets && docker compose run node npx gulp compile - name: Collect static assets From 708c53b8cb49a61c91b0e97a6e69b5480f255841 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:38:44 -0600 Subject: [PATCH 45/59] Add correct spacing --- .github/workflows/deploy-sandbox.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 6c9821112..ec7e5623f 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -42,13 +42,17 @@ jobs: - name: Setup Node.js working-directory: ./src uses: actions/setup-node@v4 - with: - node-version: '21.7.3' + with: + node-version: '21.7.3' + + - name: Prepare Node environment and adjust permissions + working-directory: ./src + run: | + docker compose run node sh -c "chown circleci:circleci package*.json && npm install -g npm@10.5.0 && npm install" + - name: Compile USWDS assets working-directory: ./src run: | - docker compose run node npm install && - docker compose run node npm install npm@10.5.0 && docker compose run node npx gulp copyAssets && docker compose run node npx gulp compile - name: Collect static assets From bb24f723551c2485ee711ddfc4487e720aaba6af Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:43:59 -0600 Subject: [PATCH 46/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index ec7e5623f..b7798f858 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -42,8 +42,8 @@ jobs: - name: Setup Node.js working-directory: ./src uses: actions/setup-node@v4 - with: - node-version: '21.7.3' + with: + node-version: '21.7.3' - name: Prepare Node environment and adjust permissions working-directory: ./src From 0e66070e85ea9da09e870401c323def5e24ade1f Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:44:44 -0600 Subject: [PATCH 47/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index b7798f858..4dead7625 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -40,7 +40,6 @@ jobs: steps: - uses: actions/checkout@v3 - name: Setup Node.js - working-directory: ./src uses: actions/setup-node@v4 with: node-version: '21.7.3' From 3965c7d199c0d865c9a280739e61d0c84929ff4b Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:46:36 -0600 Subject: [PATCH 48/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 4dead7625..e8edb096a 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -44,14 +44,11 @@ jobs: with: node-version: '21.7.3' - - name: Prepare Node environment and adjust permissions - working-directory: ./src - run: | - docker compose run node sh -c "chown circleci:circleci package*.json && npm install -g npm@10.5.0 && npm install" - - name: Compile USWDS assets working-directory: ./src run: | + npm install && + docker compose run node npm install npm@10.5.0 && docker compose run node npx gulp copyAssets && docker compose run node npx gulp compile - name: Collect static assets From ad72c49de7fa043935ec4e4331478e47d237a97a Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:55:13 -0600 Subject: [PATCH 49/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index e8edb096a..45975cfa8 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -39,10 +39,10 @@ jobs: needs: [variables] steps: - uses: actions/checkout@v3 - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '21.7.3' + - uses: actions/setup-node@v4 + with: + node-version: '21.7.3' + cache: 'npm' - name: Compile USWDS assets working-directory: ./src From 1d58ead3e1407e79774e567aab60ef797d1a1aa3 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:55:21 -0600 Subject: [PATCH 50/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 45975cfa8..93564efb7 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -40,9 +40,9 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v4 - with: - node-version: '21.7.3' - cache: 'npm' + with: + node-version: '21.7.3' + cache: 'npm' - name: Compile USWDS assets working-directory: ./src From 65635dc8e3d11eb75fffaee825afd17cdd42c6f2 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:55:47 -0600 Subject: [PATCH 51/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 93564efb7..62e27293e 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -47,7 +47,7 @@ jobs: - name: Compile USWDS assets working-directory: ./src run: | - npm install && + docker compose run node npm install && docker compose run node npm install npm@10.5.0 && docker compose run node npx gulp copyAssets && docker compose run node npx gulp compile From 596afdb6de3c902e1fc4dfe98aeea6f1b9b57cf7 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:57:20 -0600 Subject: [PATCH 52/59] Add cache dependency path --- .github/workflows/deploy-sandbox.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 62e27293e..916b8c6de 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -43,6 +43,7 @@ jobs: with: node-version: '21.7.3' cache: 'npm' + cache-dependency-path: ./src/package-lock.json - name: Compile USWDS assets working-directory: ./src From 6e06779c30efa1eeda72327126d168743e62242e Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:05:20 -0600 Subject: [PATCH 53/59] Update deploy-sandbox.yaml --- .github/workflows/deploy-sandbox.yaml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 916b8c6de..d32cbb3e2 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -39,17 +39,11 @@ jobs: needs: [variables] steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v4 - with: - node-version: '21.7.3' - cache: 'npm' - cache-dependency-path: ./src/package-lock.json - - name: Compile USWDS assets working-directory: ./src run: | + docker compose run node npm install --global --force node@21.7.3 && docker compose run node npm install && - docker compose run node npm install npm@10.5.0 && docker compose run node npx gulp copyAssets && docker compose run node npx gulp compile - name: Collect static assets From 40795f2e47dfe7d9575e7423cb2de27d330f5ed6 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:07:22 -0600 Subject: [PATCH 54/59] Force install node version --- .github/workflows/deploy-sandbox.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index d32cbb3e2..2af58f716 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -42,8 +42,8 @@ jobs: - name: Compile USWDS assets working-directory: ./src run: | - docker compose run node npm install --global --force node@21.7.3 && docker compose run node npm install && + docker compose run node npm install --global --force node@21.7.3 && docker compose run node npx gulp copyAssets && docker compose run node npx gulp compile - name: Collect static assets From 75f3a1cca1ecc13365cb1edb3ce01f42170af437 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:19:40 -0600 Subject: [PATCH 55/59] Try nvm --- .github/workflows/deploy-sandbox.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 2af58f716..d53313e08 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -39,11 +39,20 @@ jobs: needs: [variables] steps: - uses: actions/checkout@v3 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '21.7.3' - name: Compile USWDS assets working-directory: ./src run: | + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" + docker compose run node nvm install 21.7.3 && + docker compose run node nvm use 21.7.3 && docker compose run node npm install && - docker compose run node npm install --global --force node@21.7.3 && docker compose run node npx gulp copyAssets && docker compose run node npx gulp compile - name: Collect static assets From 4c6e555a054e2ecce81ebf14e8ea94e970daace1 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:21:24 -0600 Subject: [PATCH 56/59] Run nvm inside of docker shell --- .github/workflows/deploy-sandbox.yaml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index d53313e08..5e76e2eb7 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -46,15 +46,16 @@ jobs: - name: Compile USWDS assets working-directory: ./src run: | - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" - [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" - docker compose run node nvm install 21.7.3 && - docker compose run node nvm use 21.7.3 && - docker compose run node npm install && - docker compose run node npx gulp copyAssets && - docker compose run node npx gulp compile + docker compose run node bash -c "\ + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash && \ + export NVM_DIR=\"\$HOME/.nvm\" && \ + [ -s \"\$NVM_DIR/nvm.sh\" ] && \. \"\$NVM_DIR/nvm.sh\" && \ + [ -s \"\$NVM_DIR/bash_completion\" ] && \. \"\$NVM_DIR/bash_completion\" && \ + nvm install 21.7.3 && \ + nvm use 21.7.3 && \ + npm install && \ + npx gulp copyAssets && \ + npx gulp compile" - name: Collect static assets working-directory: ./src run: docker compose run app python manage.py collectstatic --no-input From 140735a7936a46a756693bf8552696854ec40c32 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:28:32 -0600 Subject: [PATCH 57/59] Remove setup node.js --- .github/workflows/deploy-sandbox.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index 5e76e2eb7..ffad69abe 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -39,10 +39,6 @@ jobs: needs: [variables] steps: - uses: actions/checkout@v3 - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '21.7.3' - name: Compile USWDS assets working-directory: ./src run: | From 7848a6e6e5fa0ea1f8c0bf09f1b85049ae1d541b Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:33:48 -0600 Subject: [PATCH 58/59] Add bash script for each yaml --- .github/workflows/deploy-development.yaml | 13 ++++++++++--- .github/workflows/deploy-stable.yaml | 13 ++++++++++--- .github/workflows/deploy-staging.yaml | 13 ++++++++++--- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy-development.yaml b/.github/workflows/deploy-development.yaml index 686635c20..12a1b5861 100644 --- a/.github/workflows/deploy-development.yaml +++ b/.github/workflows/deploy-development.yaml @@ -22,9 +22,16 @@ jobs: - name: Compile USWDS assets working-directory: ./src run: | - docker compose run node npm install && - docker compose run node npx gulp copyAssets && - docker compose run node npx gulp compile + docker compose run node bash -c "\ + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash && \ + export NVM_DIR=\"\$HOME/.nvm\" && \ + [ -s \"\$NVM_DIR/nvm.sh\" ] && \. \"\$NVM_DIR/nvm.sh\" && \ + [ -s \"\$NVM_DIR/bash_completion\" ] && \. \"\$NVM_DIR/bash_completion\" && \ + nvm install 21.7.3 && \ + nvm use 21.7.3 && \ + npm install && \ + npx gulp copyAssets && \ + npx gulp compile" - name: Collect static assets working-directory: ./src run: docker compose run app python manage.py collectstatic --no-input diff --git a/.github/workflows/deploy-stable.yaml b/.github/workflows/deploy-stable.yaml index 0ded4a3a6..9d0573e01 100644 --- a/.github/workflows/deploy-stable.yaml +++ b/.github/workflows/deploy-stable.yaml @@ -23,9 +23,16 @@ jobs: - name: Compile USWDS assets working-directory: ./src run: | - docker compose run node npm install && - docker compose run node npx gulp copyAssets && - docker compose run node npx gulp compile + docker compose run node bash -c "\ + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash && \ + export NVM_DIR=\"\$HOME/.nvm\" && \ + [ -s \"\$NVM_DIR/nvm.sh\" ] && \. \"\$NVM_DIR/nvm.sh\" && \ + [ -s \"\$NVM_DIR/bash_completion\" ] && \. \"\$NVM_DIR/bash_completion\" && \ + nvm install 21.7.3 && \ + nvm use 21.7.3 && \ + npm install && \ + npx gulp copyAssets && \ + npx gulp compile" - name: Collect static assets working-directory: ./src run: docker compose run app python manage.py collectstatic --no-input diff --git a/.github/workflows/deploy-staging.yaml b/.github/workflows/deploy-staging.yaml index 1df08f412..ad4a437c1 100644 --- a/.github/workflows/deploy-staging.yaml +++ b/.github/workflows/deploy-staging.yaml @@ -23,9 +23,16 @@ jobs: - name: Compile USWDS assets working-directory: ./src run: | - docker compose run node npm install && - docker compose run node npx gulp copyAssets && - docker compose run node npx gulp compile + docker compose run node bash -c "\ + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash && \ + export NVM_DIR=\"\$HOME/.nvm\" && \ + [ -s \"\$NVM_DIR/nvm.sh\" ] && \. \"\$NVM_DIR/nvm.sh\" && \ + [ -s \"\$NVM_DIR/bash_completion\" ] && \. \"\$NVM_DIR/bash_completion\" && \ + nvm install 21.7.3 && \ + nvm use 21.7.3 && \ + npm install && \ + npx gulp copyAssets && \ + npx gulp compile" - name: Collect static assets working-directory: ./src run: docker compose run app python manage.py collectstatic --no-input From 51c1baf0e04f1789c2885fc85cdcfb6b6fbe0524 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:35:11 -0600 Subject: [PATCH 59/59] Update node.Dockerfile --- src/node.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node.Dockerfile b/src/node.Dockerfile index cf0b6acc6..9178f8862 100644 --- a/src/node.Dockerfile +++ b/src/node.Dockerfile @@ -9,4 +9,4 @@ COPY --chown=circleci:circleci package*.json ./ RUN npm install -g npm@10.5.0 -RUN npm install \ No newline at end of file +RUN npm install