diff --git a/src/djangooidc/backends.py b/src/djangooidc/backends.py index cf326eca4..7a192e4a5 100644 --- a/src/djangooidc/backends.py +++ b/src/djangooidc/backends.py @@ -65,8 +65,9 @@ class OpenIdConnectBackend(ModelBackend): return user def update_existing_user(self, user, kwargs): - # Update other fields without overwriting first_name and last_name. - # Overwrite first_name and last_name if not empty string + """Update other fields without overwriting first_name and last_name. + Overwrite first_name and last_name if not empty string""" + for key, value in kwargs.items(): # Check if the key is not first_name or last_name or value is not empty string if key not in ["first_name", "last_name"] or value: diff --git a/src/registrar/management/commands/copy_names_from_contacts_to_users.py b/src/registrar/management/commands/copy_names_from_contacts_to_users.py index c5e2364e9..6d089f721 100644 --- a/src/registrar/management/commands/copy_names_from_contacts_to_users.py +++ b/src/registrar/management/commands/copy_names_from_contacts_to_users.py @@ -17,7 +17,7 @@ logger = logging.getLogger(__name__) class Command(BaseCommand): help = """Copy first and last names from a contact to a related user if it exists and if its first and last name - properties are null""" + properties are null or blank strings.""" # ====================================================== # ===================== ARGUMENTS ===================== @@ -112,12 +112,12 @@ class Command(BaseCommand): # ---- UPDATE THE USER IF IT DOES NOT HAVE A FIRST AND LAST NAMES # ---- LET'S KEEP A LIGHT TOUCH if not eligible_user.first_name and not eligible_user.last_name: - processed_user = eligible_user # (expression has type "str | None", variable has type "str | int | Combinable") # so we'll ignore type - processed_user.first_name = contact.first_name # type: ignore - processed_user.last_name = contact.last_name # type: ignore - processed_user.save() + eligible_user.first_name = contact.first_name # type: ignore + eligible_user.last_name = contact.last_name # type: ignore + eligible_user.save() + processed_user = eligible_user return ( eligible_user, @@ -147,9 +147,9 @@ class Command(BaseCommand): def process_contacts( self, debug_on, - skipped_contacts, - eligible_users, - processed_users, + skipped_contacts=[], + eligible_users=[], + processed_users=[], ): for contact in Contact.objects.all(): # DEBUG: @@ -207,15 +207,6 @@ class Command(BaseCommand): self.print_debug_mode_statements(debug_on) - # users we SKIPPED - skipped_contacts = [] - - # users we found that are linked to contacts - eligible_users = [] - - # users we PROCESSED - processed_users = [] - logger.info( f"""{TerminalColors.OKCYAN} ========================== @@ -235,9 +226,6 @@ class Command(BaseCommand): processed_users, ) = self.process_contacts( debug_on, - skipped_contacts, - eligible_users, - processed_users, ) self.print_summary_of_findings( diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py index 87bad0dfb..443c05ee3 100644 --- a/src/registrar/tests/common.py +++ b/src/registrar/tests/common.py @@ -162,7 +162,7 @@ class AuditedAdminMockData: user = User.objects.get_or_create( first_name="{} first_name:{}".format(item_name, short_hand), last_name="{} last_name:{}".format(item_name, short_hand), - username="{} username:{}".format(item_name, str(uuid.uuid4())[:8]), + username="{} username:{}".format(item_name + str(uuid.uuid4())[:8], short_hand), )[0] return user