Hotfix/external user delete sync error#551
Conversation
When the IDP deletes a user and reassigns its email to a different external id, registration failed with a Member.Email unique-constraint violation. Free the former member's email (the IDP is the source of truth) before assigning it. - MemberService::registerExternalUserByPayload: invalidate the former member's email when the email moved to a new external id - ResourceServerContext::getCurrentUser: same collision guard before setEmail - ScheduleEntity: wrap lifecycle event/cache hooks so a queue/cache failure cannot roll back the Doctrine delete/update - EventServiceProvider: dispatch ScheduleEntityLifeCycleEvent via JobDispatcher::withDbFallback - add reproducing functional test (tests/MemberServiceTest.php)
…inst email collision registerExternalUser created a Member with the IDP email without checking whether a former member (e.g. one whose delete failed) still held it, hitting the Member.Email unique constraint. Apply the same invalidate-former-email guard already used in registerExternalUserByPayload. Add a reproducing test for the create-branch collision (tests/MemberServiceTest.php).
📝 WalkthroughWalkthroughEmail collision handling is added to member registration and OAuth2 contexts to prevent duplicate email ownership. ScheduleEntity lifecycle hooks gain error resilience via try/catch wrapping. Event dispatching for schedule entity lifecycle changes is refactored to use JobDispatcher. Comprehensive tests validate email reassignment behavior. ChangesMember and schedule entity resilience improvements
🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-551/ This page is automatically updated on each push to this PR. |
There was a problem hiding this comment.
Pull request overview
This PR hotfixes external-user email reassignment flows so stale local members do not block IDP-driven registration/update on the unique Member.Email constraint, and hardens schedule lifecycle notifications against queue/cache failures.
Changes:
- Invalidates conflicting member emails before external user registration/update paths reuse an IDP-owned email.
- Dispatches schedule lifecycle processing through
JobDispatcher::withDbFallback. - Adds tests for member-service email reassignment collision scenarios.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
app/Services/Model/Imp/MemberService.php |
Frees conflicting emails during external user registration paths. |
app/Models/OAuth2/ResourceServerContext.php |
Handles email collisions while syncing current user fields from auth context. |
app/Models/Foundation/Summit/ScheduleEntity.php |
Makes schedule lifecycle dispatch/cache failures non-fatal. |
app/Providers/EventServiceProvider.php |
Uses DB fallback dispatch for schedule lifecycle processing jobs. |
tests/MemberServiceTest.php |
Adds regression coverage for external user email reassignment collisions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $member_by_email->setEmail(sprintf("%s-invalid@invalid", $member_by_email->getId())); | ||
| } | ||
| $member->setEmail($user_email); |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
app/Providers/EventServiceProvider.php (1)
351-360: 💤 Low valueConsider using named parameters for consistency.
The existing
JobDispatcher::withDbFallbackcalls in this file (lines 174-182) use named parameters (job:,logContext:), while this call uses positional arguments. Using named parameters here would improve consistency and readability.♻️ Suggested refactor for consistency
- JobDispatcher::withDbFallback( - new ProcessScheduleEntityLifeCycleEvent( - $event->entity_operator, - $event->summit_id, - $event->entity_id, - $event->entity_type, - $event->params - ), - ['entity_type' => $event->entity_type, 'entity_id' => $event->entity_id] + JobDispatcher::withDbFallback( + job: new ProcessScheduleEntityLifeCycleEvent( + $event->entity_operator, + $event->summit_id, + $event->entity_id, + $event->entity_type, + $event->params + ), + logContext: ['entity_type' => $event->entity_type, 'entity_id' => $event->entity_id] );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/Providers/EventServiceProvider.php` around lines 351 - 360, The call to JobDispatcher::withDbFallback uses positional args; change it to use named parameters for consistency with other calls—pass the ProcessScheduleEntityLifeCycleEvent instance as job: and the context array as logContext: (i.e., call JobDispatcher::withDbFallback(job: new ProcessScheduleEntityLifeCycleEvent(...), logContext: ['entity_type' => ..., 'entity_id' => ...])) so it matches the earlier calls and improves readability.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@app/Providers/EventServiceProvider.php`:
- Around line 351-360: The call to JobDispatcher::withDbFallback uses positional
args; change it to use named parameters for consistency with other calls—pass
the ProcessScheduleEntityLifeCycleEvent instance as job: and the context array
as logContext: (i.e., call JobDispatcher::withDbFallback(job: new
ProcessScheduleEntityLifeCycleEvent(...), logContext: ['entity_type' => ...,
'entity_id' => ...])) so it matches the earlier calls and improves readability.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 015e6345-c90e-4f86-9295-b6673214c612
📒 Files selected for processing (5)
app/Models/Foundation/Summit/ScheduleEntity.phpapp/Models/OAuth2/ResourceServerContext.phpapp/Providers/EventServiceProvider.phpapp/Services/Model/Imp/MemberService.phptests/MemberServiceTest.php
ref: https://app.clickup.com/t/86ba4rpw0
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests