Skip to content

Conversation

@Mohamed-Hacene
Copy link
Collaborator

@Mohamed-Hacene Mohamed-Hacene commented Jan 20, 2026

Previously, we defined keep_local_login=True too late, which caused the wrong email to be sent for Representatives when SSO was forced.

Summary by CodeRabbit

  • Bug Fixes
    • Ensured third-party-related account flags are reliably set during new account creation and also applied when falling back to existing accounts after creation errors.
    • Improved error handling to surface a clear validation warning when account creation fails but recovery attempts proceed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

Refactored RepresentativeWriteSerializer._create_or_update_user to pass is_third_party=True and keep_local_login=True into User.objects.create_user(...). On creation failure when an existing user is found and mailing is attempted, the code now sets those flags on the existing user and raises a ValidationError with a warning.

Changes

Cohort / File(s) Summary
User creation & error-path adjustments
backend/tprm/serializers.py
Pass is_third_party and keep_local_login into User.objects.create_user(...) instead of assigning them after creation. On creation failure with an existing user and mailing attempted, set these attributes on the existing user and raise a ValidationError with a warning.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I hopped through changes, neat and spry,
Flags set at birth—no post-fix sigh,
If creation trips and an old friend appears,
I nudge their bits and calm the fears,
Code trimmed and tidy, carrot cheers! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main fix: ensuring registration email is sent when SSO is forced for representatives, which aligns with the code changes that adjust when is_third_party and keep_local_login flags are set.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/registration-mail-representative

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Mohamed-Hacene Mohamed-Hacene changed the title fix: send registration email instead of SSO email when SSO is forced … fix: send registration email when SSO is forced for representatives Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants