Skip to content

update: upsert email API#1734

Open
parmesant wants to merge 3 commits into
parseablehq:mainfrom
parmesant:optional-user-email
Open

update: upsert email API#1734
parmesant wants to merge 3 commits into
parseablehq:mainfrom
parmesant:optional-user-email

Conversation

@parmesant

@parmesant parmesant commented Jul 23, 2026

Copy link
Copy Markdown
Contributor
PATCH /api/v1/user/{userid}
body- {email: "email@example.com"}

Users can upsert their email

Fixes #XXXX.

Description


This PR has:

  • been tested to ensure log ingestion and log query works.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added documentation for new or modified features or behaviors.

Summary by CodeRabbit

  • New Features
    • Added an authorized PATCH /api/v1/user/{userid} endpoint to update a user’s email.
    • Introduced a user email update privilege and included it in default role permissions.
    • Extended returned profile data so native users’ email is included when available.
  • Bug Fixes
    • Added email validation and return errors for invalid updates.
    • Prevented updates to protected users and unsupported account types.
    • Improved response mapping so native users’ email is now sourced from the user record.

```
PUT /api/v1/user/{userid}/email
body- {email: "email@example.com"}
```
Users can upsert their email
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5cf37c69-f0b4-4129-adbc-38a03c637990

📥 Commits

Reviewing files that changed from the base of the PR and between 2998fe5 and add521d.

📒 Files selected for processing (5)
  • src/handlers/http/modal/query_server.rs
  • src/handlers/http/modal/server.rs
  • src/handlers/http/rbac.rs
  • src/rbac/role.rs
  • src/rbac/user.rs
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/handlers/http/modal/query_server.rs
  • src/rbac/role.rs
  • src/handlers/http/rbac.rs
  • src/rbac/user.rs

Walkthrough

Adds a protected PATCH /user/{userid} endpoint with email validation, tenant-aware persistence for Native and OAuth users, native-user email projection, and a new Action::PatchUser privilege included in default roles.

Changes

User email update

Layer / File(s) Summary
Email model and permissions
src/rbac/user.rs, src/rbac/utils.rs, src/rbac/role.rs
Adds validated email input, optional Native user email storage, insertion behavior for Native and OAuth users, native email projection, and the PatchUser action in default role permissions.
RBAC email mutation
src/rbac/mod.rs
Adds tenant-aware email persistence and returns UserDoesNotExist when the target user is missing.
PATCH handler and route wiring
src/handlers/http/rbac.rs, src/handlers/http/modal/query_server.rs, src/handlers/http/modal/server.rs
Adds protected PATCH handling and registers the PATCH /user/{userid} route in both server configurations.

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
Loading

Suggested reviewers: nikhilsinhaparseable

Poem

A rabbit hops where new emails flow,
Through guarded routes in tidy rows.
Roles grant permission, validators gleam,
Users save addresses like carrots in a dream.
“PATCH!” cries the bunny—“the update is green!”

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is too sparse for the template; it lacks goal, solution/rationale, key changes, issue reference, and checklist details. Add the required Description content, issue reference if applicable, and fill out testing/docs/comment checklist items.
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 (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the main change: adding an email upsert API.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6659e06 and c56e046.

📒 Files selected for processing (6)
  • src/handlers/http/modal/query_server.rs
  • src/handlers/http/modal/server.rs
  • src/handlers/http/rbac.rs
  • src/rbac/mod.rs
  • src/rbac/role.rs
  • src/rbac/user.rs

Comment thread src/rbac/user.rs
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 23, 2026
Samielakkad

This comment was marked as resolved.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 win

Return a validation error for invalid email payloads.

UpdateUser::update only persists valid emails and otherwise returns Ok(()), so an invalid email reaches this handler and produces HTTP 200 without changing the user. Make the update layer return a 4xx-producing RBACError for invalid input instead of silently treating the request as successful. This follows the supplied src/rbac/user.rs:57-74 contract.

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 37c0f47 and c42588b.

📒 Files selected for processing (5)
  • src/handlers/http/modal/query_server.rs
  • src/handlers/http/modal/server.rs
  • src/handlers/http/rbac.rs
  • src/rbac/role.rs
  • src/rbac/user.rs

Comment thread src/rbac/user.rs
@parmesant
parmesant force-pushed the optional-user-email branch from c42588b to 2998fe5 Compare July 23, 2026 10:12
```
PATCH /api/v1/user/{userid}
body- {email: "email@example.com"}
```
@parmesant
parmesant force-pushed the optional-user-email branch from 2998fe5 to add521d Compare July 23, 2026 10:17
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