mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-15 17:17:02 +02:00
Revisions and clean up based on PR comments
This commit is contained in:
parent
ed5d4fc4c3
commit
4adeb6722b
3 changed files with 12 additions and 23 deletions
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue