Skip to content

fix(api): send invite email when creating Portal user (#145)#149

Open
b3lz3but wants to merge 2 commits intocaptainpragmatic:masterfrom
b3lz3but:fix/invite-email-on-user-create
Open

fix(api): send invite email when creating Portal user (#145)#149
b3lz3but wants to merge 2 commits intocaptainpragmatic:masterfrom
b3lz3but:fix/invite-email-on-user-create

Conversation

@b3lz3but
Copy link
Copy Markdown
Contributor

Summary

  • New users created via Portal invite or staff "Create User" were left with unusable passwords and no email sent — permanently locked out
  • Both customer_users_create (API) and customer_create_user (staff view) now call the existing _send_welcome_email_secure() to send a password-reset invite
  • Email failure is non-blocking: user is still created, staff gets a warning, API response includes invite_email_sent: false
  • Added bilingual (RO/EN) welcome email templates (customers/emails/welcome_email.html + .txt)

Closes #145

Test plan

  • test_create_user_success — verifies invite email is called and invite_email_sent: true in response
  • test_create_user_invite_email_failure_still_succeeds — user created even if email fails
  • test_create_user_sends_invite_email — staff view triggers email
  • test_create_user_warns_on_email_failure — staff view shows warning on failure
  • Full lint suite (7 phases) passing
  • MyPy clean (468 source files)
  • All pre-commit hooks passing

🤖 Generated with Claude Code

@b3lz3but b3lz3but force-pushed the fix/invite-email-on-user-create branch from ca9db81 to 42a30bd Compare March 24, 2026 20:00
@b3lz3but
Copy link
Copy Markdown
Contributor Author

@mostlyvirtual — this PR is ready for review.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a Portal onboarding gap where newly created customer users were left with unusable passwords and no invite/reset email, by triggering the existing secure welcome-email flow from both the API endpoint and the staff “Create User” view.

Changes:

  • Send password-reset invite email after creating a customer user in customer_users_create (API) and customer_create_user (staff view).
  • Return invite_email_sent in the API response and show a staff warning message if email sending fails.
  • Add new customer welcome email templates (HTML + text) and tests covering success/failure scenarios.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
services/platform/apps/api/customers/views.py Calls secure welcome-email sender and returns invite_email_sent in response.
services/platform/apps/customers/user_management_views.py Calls secure welcome-email sender; warns staff when email fails.
services/platform/templates/customers/emails/welcome_email.txt Adds plaintext welcome/invite template with reset link.
services/platform/templates/customers/emails/welcome_email.html Adds HTML welcome/invite template with reset link/button.
services/platform/tests/api/test_customer_api.py Adds API tests verifying email call + invite_email_sent behavior.
services/platform/tests/customers/test_user_management_views.py Adds staff-view tests verifying email call + warning-on-failure behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…ic#145)

New users created via the customer_users_create API and the staff
customer_create_user view were left with unusable passwords and no
email — permanently locked out. Call the existing
_send_welcome_email_secure() to send a password-reset invite on
creation. Email failure is non-blocking (user still created).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ciprian Radulescu <craps2003@gmail.com>
@b3lz3but b3lz3but force-pushed the fix/invite-email-on-user-create branch from 42a30bd to 3c010c4 Compare March 27, 2026 14:59
b3lz3but added a commit to b3lz3but/PRAHO that referenced this pull request Mar 27, 2026
… request_ip audit logging

- Fix welcome email templates: "3 days" → "2 hours" to match
  PASSWORD_RESET_TIMEOUT=7200s setting
- Pass request_ip via get_safe_client_ip(request) to
  _send_welcome_email_secure for audit trail on both call sites
- Update test assertions to verify request_ip is passed

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@b3lz3but
Copy link
Copy Markdown
Contributor Author

Review feedback addressed (68129f2)

  1. Email expiry text — changed "3 days" → "2 hours" in both HTML and TXT templates to match PASSWORD_RESET_TIMEOUT=7200s.
  2. request_ip audit logging — both call sites (API view + management view) now pass request_ip=get_safe_client_ip(request) to _send_welcome_email_secure. Tests updated.

… request_ip audit logging

- Fix welcome email templates: "3 days" → "2 hours" to match
  PASSWORD_RESET_TIMEOUT=7200s setting
- Pass request_ip via get_safe_client_ip(request) to
  _send_welcome_email_secure for audit trail on both call sites
- Update test assertions to verify request_ip is passed

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ciprian Radulescu <craps2003@gmail.com>
@b3lz3but b3lz3but force-pushed the fix/invite-email-on-user-create branch from 68129f2 to 3658348 Compare March 27, 2026 16:19
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.

fix(api/customers): new Portal user created with no invite email — account permanently locked out

2 participants