update: upsert email API#1734
Conversation
```
PUT /api/v1/user/{userid}/email
body- {email: "email@example.com"}
```
Users can upsert their email
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (4)
WalkthroughAdds a protected ChangesUser email update
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant HTTPClient
participant UserRoute
participant patch_user
participant UpdateUser
participant Users
HTTPClient->>UserRoute: PATCH /user/{userid}
UserRoute->>patch_user: authorize Action::PatchUser
patch_user->>UpdateUser: deserialize and validate email
UpdateUser->>Users: put_email(email, tenant_id, userid)
Users-->>patch_user: Ok or RBACError
patch_user-->>HTTPClient: HTTP response
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@src/rbac/user.rs`:
- Around line 46-60: Remove the trailing newline inside the regex pattern used
by EMAIL_VALIDATOR_RE, ensuring the expression ends directly after the final `$`
anchor. Keep UserEmail::is_valid unchanged so normal email addresses match
without requiring a newline.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: eb7c2caf-c978-444a-813f-15717006cc12
📒 Files selected for processing (6)
src/handlers/http/modal/query_server.rssrc/handlers/http/modal/server.rssrc/handlers/http/rbac.rssrc/rbac/mod.rssrc/rbac/role.rssrc/rbac/user.rs
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/handlers/http/rbac.rs (1)
186-197: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winReturn a validation error for invalid email payloads.
UpdateUser::updateonly persists valid emails and otherwise returnsOk(()), so an invalid email reaches this handler and produces HTTP 200 without changing the user. Make the update layer return a 4xx-producingRBACErrorfor invalid input instead of silently treating the request as successful. This follows the suppliedsrc/rbac/user.rs:57-74contract.🤖 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 `@src/handlers/http/rbac.rs` around lines 186 - 197, Update UpdateUser::update in the user update layer to validate email payloads and return the established 4xx-producing RBACError for invalid input, matching the contract in the referenced user logic. Preserve successful persistence for valid emails so the handler’s existing update call no longer returns HTTP 200 for rejected payloads.
🤖 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.
Inline comments:
In `@src/rbac/user.rs`:
- Around line 57-66: Update UpdateUser::update so a provided email that fails
is_valid_email() returns the established typed 4xx validation error instead of
skipping persistence and returning Ok(()). Preserve the existing update behavior
for valid emails and absent email values, and add a regression test covering
rejection of an invalid email.
---
Outside diff comments:
In `@src/handlers/http/rbac.rs`:
- Around line 186-197: Update UpdateUser::update in the user update layer to
validate email payloads and return the established 4xx-producing RBACError for
invalid input, matching the contract in the referenced user logic. Preserve
successful persistence for valid emails so the handler’s existing update call no
longer returns HTTP 200 for rejected payloads.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 6a096918-1df2-46fd-b77f-290b72e5ae62
📒 Files selected for processing (5)
src/handlers/http/modal/query_server.rssrc/handlers/http/modal/server.rssrc/handlers/http/rbac.rssrc/rbac/role.rssrc/rbac/user.rs
c42588b to
2998fe5
Compare
```
PATCH /api/v1/user/{userid}
body- {email: "email@example.com"}
```
2998fe5 to
add521d
Compare
Users can upsert their email
Fixes #XXXX.
Description
This PR has:
Summary by CodeRabbit
PATCH /api/v1/user/{userid}endpoint to update a user’s email.