Repository navigation
feat(notifications): a notice per person and a bell for every role, on desktop and phone - #624
Open
privatejoel wants to merge 1 commit into
Open
privatejoel wants to merge 1 commit into
privatejoel wants to merge 1 commit into
Conversation
…n desktop and phone
C-17 (WM-7, R-F5). Migration 253 adds admin_notifications.recipient_user_id.
A null value is a broadcast row, as before. A user id is a row for that
person only.
- notify(svc, tenantId, payload, { users, roles, dedupKey }) writes one row
per recipient. A role expands to the approved members of this tenant.
- notifyAdmins does not change. It writes one broadcast row.
- GET /api/admin/notifications shows the caller their own rows. Admin and
operator also see the broadcast rows, as before.
- mark_read and mark_all_read are open to every role. They touch only the
rows that the caller sees. Resolve stays admin only.
- The bell shows for every role in Shell and in MobileShell.
- Before migration 253 is applied, notify skips and logs. It does not write
a broadcast row. The list shows nothing to a role that is not admin or
operator.
- The header comment in notifications.js said one row per recipient. That
was false. It is correct now.
No new events. C-19 adds them.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
C-17 in docs/SO_EXECUTION_COHESION.md (R-F5, section 6.4). WM-7 in docs/WORK_MANAGEMENT_SCOPE.md. This PR adds no events. C-19 adds them.
admin_notifications.recipient_user_id uuid null, with a foreign key toauth.users(id) on delete cascade. It also adds a partial index for the unread list of one person. A null value is a broadcast row, as before. A user id is a row for that person only. The column decides who sees a row. Thus a deleted user takes their rows with them. "Set null" would change a private notice into a broadcast row that admins can read.notify(svc, tenantId, payload, { users, roles, dedupKey })insrc/api/_lib/notifications.jswrites one row for each recipient. A role expands to the approved members of this tenant. A user id that is not an approved member of this tenant gets no row. The function returns{ notified: <rows written> }.notifyAdminsdoes not change. It writes one broadcast row. The false header comment ("one row per recipient") is now correct: its roles decide only whether to insert, and they do not go with the row.GET /api/admin/notificationsshows the caller the rows addressed to them. Admin and operator also see the broadcast rows. Before this PR, only these two roles saw the bell.mark_readandmark_all_readare now open to every role. They touch only the rows that the caller sees. When a person tries to mark the row of another person, the endpoint answers 404 and changes nothing.resolvestays admin only. Each update now also filters ontenant_id.Shelland inMobileShell. The mobile header puts the bell last, so the menu, which is anchored on the right, stays on the screen.No new endpoint, no new
requireAction. The client methods (AnvilBackend.notifications.*) already existed.Deploy notes
supabase/migrations/253_notification_recipient.sql. It is additive and idempotent. Then reload the PostgREST schema cache.notify()logs a warning and skips. It returns{ notified: 0, skipped: "migration_253_not_applied" }. It does not write the notice as a broadcast row. It does not try again without the column.notifyAdminsand the current admin bell work as before.notify()yet (C-19 will), so before 253 nobody loses a notice.Tests
New tests (behavioural, with PostgREST stand-ins):
src/v3-app/api-notifications.recipient.test.js: a role notify writes one row for each approved member. Pending members, deactivated members and members of another tenant get no row. A person named twice gets one row. When the column is missing, notify skips, writes no row, and makes one insert attempt only.notifyAdminsstill writes one broadcast row.src/v3-app/api-admin-notifications.mark-read.recipient.test.js: a sales engineer lists only their row. An admin lists their rows and the broadcast rows, and never the row of another person. An operator lists the broadcast rows. The recipient marks their row read. The endpoint refusesmark_readof the row of another person (also for an admin). It refusesmark_readof a broadcast row by a sales engineer.mark_all_readmarks only the rows of the caller.resolvestays admin only. With the column missing, a sales engineer sees and marks nothing, and the admin bell works as before.src/v3-app/components/Shell.bell.roles.test.tsx: the bell shows for sales_engineer, viewer, finance and customer_support with the unread count. A click on a row callsmarkReadwith its id.src/v3-app/components/MobileShell.bell.test.tsx: the bell is in the mobile header for sales_engineer, viewer and admin. A tap on a row callsmarkReadwith its id.Mutation check. I broke each rule, ran its test file, saw a failure, and restored the rule. All 13 mutations made the tests fail:
mark_all_readselects rows without the visibility rulemark_readselects the row without the visibility ruleresolveis open to every roleShellshows the bell for admin and operator only (the old gate)MobileShellhas no bellGates:
npm run check: pass.npm run lint: 0 errors (511 warnings, all present before this PR).npm run build: pass.npm run verify: pass. It rewrotedocs/RBAC_AUDIT.mdanddocs/WRITE_PATH_AUDIT.md. These changes are not related to this PR, so I restored the files.npm run eval:golden: pass (aggregate 1.000).NODE_OPTIONS=--no-experimental-webstorage npx vitest run --maxWorkers=2: 630 files, 7396 tests, all pass.migrationsjob applies it.Not covered
@mentioncomes with C-26.user_notification_prefs. WM-7 lists it next to migration 253, but section 6.9 of the cohesion plan gives 253 only the recipient column.read_by.length. This is as before. A row for one person is correct, because only that person can mark it.admin_notifications(migration 042) key on atenant_idJWT claim that no hook sets. Thus they give nothing to a user JWT. All access goes through the service role and this endpoint, which applies the recipient rule. This PR does not change the policies.notify(): it reads all approved members of the tenant and filters in code. This is fine for tens of members. Filter in the query when a tenant has thousands.🤖 Generated with Claude Code