Skip to content

Commit

Permalink
Make sure we apply no updates unless we are in update mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarson committed Jan 25, 2024
1 parent 7e8711a commit 98512df
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
48 changes: 26 additions & 22 deletions primed/users/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def audit_drupal_users(study_sites, json_api, apply_changes=False):
# potential blocked user, but will no longer have a drupal uid
# so we cover these below
continue
sa = None
try:
sa = SocialAccount.objects.get(
uid=user.attributes["drupal_internal__uid"],
Expand All @@ -218,30 +219,33 @@ def audit_drupal_users(study_sites, json_api, apply_changes=False):
drupal_user.username = drupal_username
drupal_user.name = drupal_full_name
drupal_user.email = drupal_email
drupal_user.save()
if apply_changes is True:
drupal_user.save()
is_new_user = True
sa = SocialAccount.objects.create(
user=drupal_user,
uid=user.attributes["drupal_internal__uid"],
provider=CustomProvider.id,
)
if apply_changes is True:
sa = SocialAccount.objects.create(
user=drupal_user,
uid=user.attributes["drupal_internal__uid"],
provider=CustomProvider.id,
)
audit_results.add_new(data=user)

user_changed = drupal_adapter.update_user_info(
user=sa.user,
extra_data={
"preferred_username": drupal_username,
"first_name": drupal_firstname,
"last_name": drupal_lastname,
"email": drupal_email,
},
apply_update=apply_changes,
)

user_sites_changed = drupal_adapter.update_user_study_sites(
user=sa.user,
extra_data={"study_site_or_center": drupal_user_study_site_shortnames},
)
if sa:
user_changed = drupal_adapter.update_user_info(
user=sa.user,
extra_data={
"preferred_username": drupal_username,
"first_name": drupal_firstname,
"last_name": drupal_lastname,
"email": drupal_email,
},
apply_update=apply_changes,
)
if sa:
user_sites_changed = drupal_adapter.update_user_study_sites(
user=sa.user,
extra_data={"study_site_or_center": drupal_user_study_site_shortnames},
apply_update=apply_changes
)
if user_changed or user_sites_changed and not is_new_user:
audit_results.add_update(data=user)

Expand Down
18 changes: 17 additions & 1 deletion primed/users/management/commands/sync-drupal-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from django.core.management.base import BaseCommand

from primed.users.audit import drupal_data_study_site_audit, drupal_data_user_audit
from primed.users.audit import (
AuditResults,
drupal_data_study_site_audit,
drupal_data_user_audit,
)

logger = logging.getLogger(__name__)

Expand All @@ -23,6 +27,18 @@ def handle(self, *args, **options):

user_audit_results = drupal_data_user_audit(apply_changes=should_update)
print(f"User Audit Results {user_audit_results}")
if user_audit_results.encountered_issues():
print(
user_audit_results.rows_by_result_type(
result_type=AuditResults.RESULT_TYPE_ISSUE
)
)

site_audit_results = drupal_data_study_site_audit(apply_changes=should_update)
print(f"Site Audit Results {site_audit_results}")
if site_audit_results.encountered_issues():
print(
site_audit_results.rows_by_result_type(
result_type=AuditResults.RESULT_TYPE_ISSUE
)
)

0 comments on commit 98512df

Please sign in to comment.