Skip to content

feat(notifs): move organization notification settings to the user level#12131

Open
maximevast wants to merge 19 commits into
mainfrom
maxime/user-org-notifs-settings-wire
Open

feat(notifs): move organization notification settings to the user level#12131
maximevast wants to merge 19 commits into
mainfrom
maxime/user-org-notifs-settings-wire

Conversation

@maximevast
Copy link
Copy Markdown
Contributor

@maximevast maximevast commented Jun 3, 2026

Summary

**Related Issue: #12101

What

Moves organization notification settings (new_order, new_subscription)
from the org level to the user level, so each member controls their own
emails instead of one shared org-wide toggle.

Why

Adding granularity to the notifications settings; allowing users independently enable or disable notifications for an organisation.

How

  • Backend: new GET/PATCH /users/me/organizations/{id}/notification-settings
    endpoints; dispatch now filters per-member in send_to_org_members.
  • Frontend: settings page reads/writes the authenticated user's preferences.
  • Backfill: script copies each org's current settings down to all its
    members (soft-deleted included).

Rollout (no downtime)

The new column is nullable for now. While it's NULL, both backend dispatch
and the frontend fall back to the org-level value, so behavior is unchanged
until the backfill runs.

Follow-up PR (cleanup): run the backfill, make the column non-null, drop
the org-level fallbacks, and remove the org-level notification_settings
column. Marked in-code with TODO (maxime).

Tests

Service-level filtering + fallback (tests/notifications/test_service.py) and
the endpoint contract incl. 404 on non-member (tests/user/test_endpoints.py).

Checklist

  • This PR addresses a single concern (one bug fix, one feature, one refactor)
  • The diff is reasonably sized and easy to review
  • New functionality is covered by tests
  • Linting and type checking pass (uv run task lint && uv run task lint_types)
  • No unrelated changes or drive-by fixes are included

Summary by cubic

Move organization notification settings to the user level so each member controls emails for new orders and subscriptions. Web and mobile now read/write per-user preferences, and notification delivery filters per member.

  • New Features

    • Web/app “Your notifications” uses per-user settings with optimistic updates and clearer copy (“Receive a notification…”).
    • API: GET/PATCH /v1/users/me/organizations/{organization_id}/notification-settings with 404 for non‑members; OpenAPI operations use “authenticated” naming; endpoints use AuthorizeUser; @polar-sh/client updated; new hooks useUserOrganizationNotificationSettings and useUpdateUserOrganizationNotificationSettings.
    • Delivery filters centrally by each member’s setting; removed org-level gates in order/subscription services; unmapped notification types still notify all members.
  • Migration

    • Run server/scripts/backfill_user_organization_notification_settings.py to copy org-level settings to memberships.
    • Until backfill completes, null user settings fall back to the organization’s values.

Written for commit 1072761. Summary will update on new commits.

Review in cubic

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
polar Ready Ready Preview, Comment Jun 4, 2026 1:48pm
polar-sandbox Ready Ready Preview, Comment Jun 4, 2026 1:48pm
polar-test Ready Ready Preview, Comment Jun 4, 2026 1:48pm

Request Review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

OpenAPI Changes

Operations

  • 🔼 GET /v1/users/me/organizations/{organization_id}/notification-settings (added)
  • 🔼 PATCH /v1/users/me/organizations/{organization_id}/notification-settings (added)

Schemas

  • 🔼 UserOrganizationNotificationSettings (added)
  • 🔼 UserOrganizationNotificationSettingsUpdate (added)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

Preview Environment
URL: https://polar-preview-vm.taildbff7b.ts.net/pr-12131
API: https://polar-preview-vm.taildbff7b.ts.net/pr-12131/v1/
Logs: backend
SHA: 1072761920f7ef25b9c2660b6620803e2dd2a24f

@maximevast maximevast changed the title Maxime/user org notifs settings wire feat(notifs): per-user organization notification settings Jun 3, 2026
@maximevast maximevast changed the title feat(notifs): per-user organization notification settings feat(notifs): move organization notification settings to the user level Jun 3, 2026
@maximevast maximevast marked this pull request as ready for review June 3, 2026 14:06
@maximevast maximevast requested review from a team and frankie567 as code owners June 3, 2026 14:06
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 13 files

Confidence score: 4/5

  • This PR looks safe to merge overall, with moderate confidence issues limited to API typing completeness rather than a clear runtime break.
  • In clients/packages/client/src/v1.ts, both GET and PATCH notification-settings operations are missing documented 404 response types, which can create a client contract mismatch and weaker error handling for non-member access paths.
  • Because both findings are severity 5/10 and focused on typed response coverage, the risk appears manageable but worth addressing soon to keep generated client behavior aligned with the API spec.
  • Pay close attention to clients/packages/client/src/v1.ts - add the missing 404 response typings for notification-settings GET/PATCH to prevent contract drift.

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread clients/packages/client/src/v1.ts
Comment thread clients/packages/client/src/v1.ts
Copy link
Copy Markdown
Member

@frankie567 frankie567 left a comment

Choose a reason for hiding this comment

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

Great job!

Comment thread clients/packages/client/src/v1.ts
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Re-trigger cubic

Comment thread server/polar/user/endpoints.py Outdated
}
},
)
async def update_my_notification_settings(
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.

Big nit-pick, but if GET | PATCH /me methods are called get|update_authenticated, then maybe we should name these methods

update_authenticated_notification_settings?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point, clauding now...

Comment thread server/polar/user/endpoints.py
…er)/settings/SettingsPage.tsx

Co-authored-by: Pieter Beulque <pieterbeulque@gmail.com>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Re-trigger cubic

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Re-trigger cubic

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

🚀 Expo preview is ready!

  • Project → Polar
  • Platforms → android, ios
  • Scheme → polar
Android
(81a249a3bfb9f95d478ceaed4e5c6dbe1cd5a8ea)
More info
iOS
(ef16f9d1e60c398e52c833614ba06cef261621a3)
More info

Learn more about 𝝠 Expo Github Action

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Re-trigger cubic

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Re-trigger cubic

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.

3 participants