fix: sync user removal with external auth provider#46
fix: sync user removal with external auth provider#46abhizipstack wants to merge 3 commits intomainfrom
Conversation
When removing users from an organization, the controller now calls the auth service to delete the membership from the external provider (e.g., Scalekit) after the local DB record is deleted. Uses the Scalekit user_id instead of Django PK. Also aligns OSS stub signature with the cloud ScalekitService interface. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
| Filename | Overview |
|---|---|
| backend/backend/account/authentication_controller.py | Adds auth provider sync after DB removal, with correct guard on user_id and partial-failure reporting |
| backend/backend/account/authentication_service.py | Updates OSS stub signature to match new 3-arg interface (org_id, user, user_id) returning bool no-op |
Sequence Diagram
sequenceDiagram
participant Caller
participant Controller as AuthController
participant DB
participant AuthService as auth_service
Caller->>Controller: remove_users_from_organization(admin, org_id, emails)
loop for each email
Controller->>DB: User.objects.get(email)
alt User not found
DB-->>Controller: DoesNotExist
Controller->>Controller: append failed("User not found"), continue
else User found
DB-->>Controller: user
Controller->>DB: OrganizationMember.filter(...).delete()
alt No membership
DB-->>Controller: deleted_count=0
Controller->>Controller: append failed("No membership found"), continue
else Membership deleted
DB-->>Controller: deleted_count>0
Controller->>Controller: user_id = getattr(user, "user_id", None)
alt user_id is falsy
Controller->>Controller: skip provider sync
else user_id is truthy
Controller->>AuthService: remove_users_from_organization(org_id, user, user_id)
alt Success
AuthService-->>Controller: True
else Exception
AuthService-->>Controller: raises
Controller->>Controller: append partial("auth provider sync failed")
end
end
end
end
end
Controller-->>Caller: failed_removals list
Reviews (3): Last reviewed commit: "fix: address Greptile review — report pa..." | Re-trigger Greptile
When removing users from an organization, the controller now calls the auth service to delete the membership from the external auth provider after the local DB record is deleted. Uses the provider's user_id instead of Django PK. Also aligns OSS stub signature with the cloud service interface. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…hout provider ID - Append to failed_removals when auth provider sync fails (prevents silent split-brain state) - Skip provider sync entirely when user has no provider user_id (avoids guaranteed-to-fail API call in OSS mode) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Both Greptile comments addressed in 8c7e316: P1 (split-brain): Partial failures now appended to P2 (fallback to Django PK): Now guards with |
Summary
OrganizationMemberDB record, the controller now callsauth_service.remove_users_from_organization()to sync the removal with the external auth provideruser_idinstead of Django integer PKAuthenticationServicestub signature with the cloud service interfacecontinueafter "No membership found" to skip provider sync on failed DB deletionsTest plan
🤖 Generated with Claude Code