Revisions and clean up based on PR comments

This commit is contained in:
Rachid Mrad 2023-12-13 15:13:04 -05:00
parent ed5d4fc4c3
commit 4adeb6722b
No known key found for this signature in database
GPG key ID: EF38E4CEC4A8F3CF
3 changed files with 12 additions and 23 deletions

View file

@ -65,8 +65,9 @@ class OpenIdConnectBackend(ModelBackend):
return user return user
def update_existing_user(self, user, kwargs): def update_existing_user(self, user, kwargs):
# Update other fields without overwriting first_name and last_name. """Update other fields without overwriting first_name and last_name.
# Overwrite first_name and last_name if not empty string Overwrite first_name and last_name if not empty string"""
for key, value in kwargs.items(): for key, value in kwargs.items():
# Check if the key is not first_name or last_name or value is not empty string # 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: if key not in ["first_name", "last_name"] or value:

View file

@ -17,7 +17,7 @@ logger = logging.getLogger(__name__)
class Command(BaseCommand): class Command(BaseCommand):
help = """Copy first and last names from a contact to help = """Copy first and last names from a contact to
a related user if it exists and if its first and last name a related user if it exists and if its first and last name
properties are null""" properties are null or blank strings."""
# ====================================================== # ======================================================
# ===================== ARGUMENTS ===================== # ===================== ARGUMENTS =====================
@ -112,12 +112,12 @@ class Command(BaseCommand):
# ---- UPDATE THE USER IF IT DOES NOT HAVE A FIRST AND LAST NAMES # ---- UPDATE THE USER IF IT DOES NOT HAVE A FIRST AND LAST NAMES
# ---- LET'S KEEP A LIGHT TOUCH # ---- LET'S KEEP A LIGHT TOUCH
if not eligible_user.first_name and not eligible_user.last_name: 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") # (expression has type "str | None", variable has type "str | int | Combinable")
# so we'll ignore type # so we'll ignore type
processed_user.first_name = contact.first_name # type: ignore eligible_user.first_name = contact.first_name # type: ignore
processed_user.last_name = contact.last_name # type: ignore eligible_user.last_name = contact.last_name # type: ignore
processed_user.save() eligible_user.save()
processed_user = eligible_user
return ( return (
eligible_user, eligible_user,
@ -147,9 +147,9 @@ class Command(BaseCommand):
def process_contacts( def process_contacts(
self, self,
debug_on, debug_on,
skipped_contacts, skipped_contacts=[],
eligible_users, eligible_users=[],
processed_users, processed_users=[],
): ):
for contact in Contact.objects.all(): for contact in Contact.objects.all():
# DEBUG: # DEBUG:
@ -207,15 +207,6 @@ class Command(BaseCommand):
self.print_debug_mode_statements(debug_on) 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( logger.info(
f"""{TerminalColors.OKCYAN} f"""{TerminalColors.OKCYAN}
========================== ==========================
@ -235,9 +226,6 @@ class Command(BaseCommand):
processed_users, processed_users,
) = self.process_contacts( ) = self.process_contacts(
debug_on, debug_on,
skipped_contacts,
eligible_users,
processed_users,
) )
self.print_summary_of_findings( self.print_summary_of_findings(

View file

@ -162,7 +162,7 @@ class AuditedAdminMockData:
user = User.objects.get_or_create( user = User.objects.get_or_create(
first_name="{} first_name:{}".format(item_name, short_hand), first_name="{} first_name:{}".format(item_name, short_hand),
last_name="{} last_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] )[0]
return user return user