Repository navigation
feat: add notifications - #364
Conversation
GET /notifications tells users what needs attention on the services they have a role on, and admins also about pending approvals and what the configuration no longer allows, computed from the stored data. Dismissals are shared per audience, and stand for one episode of a problem. Refs #361 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Updates and renames no longer bring back what admins dismissed, as the identifiers depend on the pending type or the value that isn't allowed. A reason that returns after another one comes back. Admins' queries only read services with problems, and only a scheme that isn't allowed counts as one. Docs brought up to date. Refs #361 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A service that returns to the same pending type stays dismissed, as the registry doesn't record that change. Refs #361 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThis PR adds computed, authenticated notifications for sync and registry issues, with stable episode-based IDs and audience-scoped dismissals, updates sync state and deployment documentation to support the feature, and provides extensive API and lifecycle test coverage. Sequence diagram for computed notification retrieval and dismissalsequenceDiagram
actor User
participant API
participant Notifications
participant Services
participant Dismissals
User->>API: GET /notifications
API->>Notifications: getNotifications()
Notifications->>Services: _current()
Services-->>Notifications: Current service and approval problems
Notifications->>Dismissals: Find audience-scoped dismissals
Dismissals-->>Notifications: Dismissed notification IDs
Notifications-->>API: Sorted active notifications
API-->>User: 200 notification list
User->>API: DELETE /notifications/{notificationId}
API->>Notifications: deleteNotification(notificationId)
Notifications->>Services: _current()
Services-->>Notifications: Visible notification
Notifications->>Dismissals: Store audience:notificationId
Dismissals-->>Notifications: Dismissal stored
Notifications-->>API: Notification ID
API-->>User: 200 notification ID
State diagram for notification episode identitystateDiagram-v2
[*] --> Healthy
Healthy --> Problem: Problem starts
Problem --> Problem: Same reason continues
Problem --> NewEpisode: Reason changes
Problem --> Healthy: Problem ends
Healthy --> NewEpisode: Problem returns
NewEpisode --> Problem: New notification ID
Problem --> Dismissed: DELETE /notifications/{notificationId}
Dismissed --> Dismissed: Same problem and reason
Dismissed --> Healthy: Problem ends
Dismissed --> NewEpisode: Problem returns or reason changes
Flow diagram for notification visibility and sourcesflowchart TD
Request[Authenticated notification request] --> Audience{Admin mode?}
Audience -->|No| Owned[Services with user's roles]
Audience -->|Yes| All[All services and registry approvals]
Owned --> Sync[Out-of-sync services]
All --> Sync
All --> Pending[Pending service types and services]
All --> Config[Disallowed environments and URL schemes]
Sync --> Current[Compute current notifications]
Pending --> Current
Config --> Current
Current --> Filter[Remove audience-scoped dismissals]
Filter --> Sorted[Sort by since, most recent first]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #364 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 26 27 +1
Lines 3135 3233 +98
=========================================
+ Hits 3135 3233 +98 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cloud_registry/api/additions.openapi.yaml" line_range="1241" />
<code_context>
default:
$ref: '#/components/responses/Error'
+ /notifications:
+ get:
+ summary: List what needs the attention of the current user.
+ description: |
</code_context>
<issue_to_address>
**Anonymous callers can access notifications**
When a request to either new endpoint has no valid bearer token, connexion has no operation-level bearer-token requirement for either endpoint, and the wildcard access-control policies only grant access; they do not authenticate the caller. An unauthenticated request can therefore reach notification listing or dismissal, exposing notification data or changing dismissal state.
Add a bearer-token security requirement to both operations.
Also at `cloud_registry/api/additions.openapi.yaml:1270`.
</issue_to_address>
### Comment 2
<location path="cloud_registry/ga4gh/registry/notifications.py" line_range="340-342" />
<code_context>
+ raise NotFound
+ dismissal = _dismissal_id(audience, notificationId)
+ collection = get_collection(DISMISSALS)
+ if collection.find_one({"_id": dismissal}, {"_id": True}) is not None:
+ raise NotFound
+ collection.update_one(
+ {"_id": dismissal}, {"$setOnInsert": {"dismissedAt": now()}}, upsert=True
+ )
</code_context>
<issue_to_address>
**Concurrent dismissals return errors or success**
When requests dismiss the same notification for the same audience at once, `dismiss_notification` checks for an existing dismissal before its upsert, so overlapping requests can either hit a duplicate-key error or both return success. A valid request then gets a 500 or a 200 instead of the documented 404 for an already-dismissed notification.
Make dismissal creation atomic and return `NotFound` whenever the dismissal already exists, including when a concurrent request inserts it first.
Also at `cloud_registry/ga4gh/registry/notifications.py:343`.
</issue_to_address>Linked issues
#358 feat: import and sync service info · 4 of 4 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Import a service's values from its public service info, with safeguards against server-side request forgery. | ✅ Met | The existing import endpoint fetches and validates service info using the safe-fetch path and configured network restrictions. |
| 2 | Keep service info up to date by periodic sync. | ✅ Met | The existing sync scheduler runs due syncs; this change also tracks reason start times for notification episodes. |
| 3 | Let users see whether an entry is in sync. | ✅ Met | The existing sync status logic supplies the synced/out-of-sync label. |
| 4 | Tell users what needs attention. | ✅ Met | The new notifications endpoint computes notifications for service-role users and admins in admin mode. |
#361 feat: add notifications · 5 of 5 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Logged-in users see notifications for services they have a role on; admins in admin mode see all services' notifications, pending approvals, and other attention items. | ✅ Met | The notification computation filters service problems for role holders and adds all-service, pending, and configuration-related notifications for admins. |
| 2 | Dismissals are shared among service-role users or among admins, but not across those audiences. | ✅ Met | Dismissal records are keyed by audience and notification identifier. |
| 3 | A dismissed notification returns only if the problem ended and came back, or its reason changed. | ✅ Met | Episode-based identifiers distinguish sync reason changes and recoveries; the documented exceptions apply where the registry does not retain the intervening configuration or pending-type changes. |
| 4 | Notifications carry a type, service identifier, and reason so UIs can link to the relevant view. | ✅ Met | Service notifications include serviceId; pending service-type notifications include serviceType instead. |
| 5 | Document the API, access control, and upgrade requirements. | ✅ Met | The API, access-control, and upgrade documentation is updated. |
Sourcery assessment
Needs a human reviewer. 2 findings to address first, and if the role-based filtering exposes notifications to the wrong users, service identifiers and sync or approval details may be disclosed; reverting can stop future access but cannot undo what users have already seen. Dismissals also persist, but they are bounded and can be cleared if needed.
Blocking findings: cloud_registry/api/additions.openapi.yaml:1241, cloud_registry/ga4gh/registry/notifications.py:342
Inserting the dismissal instead of checking first, so that of dismissals at the same time, one succeeds and the other returns 404. Refs #361 Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Linked issues
#358 feat: import and sync service info · 4 of 4 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Import service values from public service info with safeguards against SSRF. | ✅ Met | The existing import endpoint fetches and validates service info, with public-address checks, redirect and size limits, and other safeguards documented in the API docs. |
| 2 | Keep service values up to date by periodic sync. | ✅ Met | The existing sync scheduler applies service info periodically and supports turning sync on and off. |
| 3 | See whether an entry is in sync. | ✅ Met | The existing sync endpoints expose the synced or out-of-sync status. |
| 4 | Tell users and admins what needs their attention. | ✅ Met | The new notifications endpoint reports role-visible sync problems and, in admin mode, pending approvals and values no longer allowed by configuration. |
#361 feat: add notifications · 4 of 5 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Show logged-in users problems on services they have a role on, and show admins all service notifications, pending approvals, and other attention-needed items in admin mode. | ✅ Met | Visibility is filtered by service role for ordinary users; admin mode also includes all sync problems, pending service types and services, and disallowed environments and URL schemes. |
| 2 | Share dismissals among service-role holders and among admins, but not across those audiences. | ✅ Met | Dismissal records are keyed separately for the owners and admins audiences. |
| 3 | Bring a dismissed notification back when its problem ends and returns, or its reason changes. | 🟡 Partly met | Sync failures track reason changes and episodes, but pending and configuration-based notifications can retain the same identifier when the same type or value clears and later recurs. |
| 4 | Include the notification type, service identifier, and reason so UIs can link to the relevant view. | ✅ Met | Service notifications include a serviceId; pending service-type notifications instead include serviceType to identify the approval target. |
| 5 | Document the API, access control, and upgrade requirements. | ✅ Met | The API and access-control docs describe the endpoints and audiences, and the upgrade notes list the new collection and policy rules. |
Pending services and values that aren't allowed have no time of their own, so that the same problem had the same identifier when it came back and stayed dismissed. Listing notifications as an admin now removes the dismissals of admins whose problems are gone. Refs #361 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Last part of #358: users and admins can see what needs their attention.
GET /notifications, for any logged-in user, computed from the stored data when read; there is no inbox, and the registry sends nothing. Users see services they have a role on that are out of sync. Admins in admin mode see those of all services, pending service types and services, and environments and URL schemes that the configuration no longer allows.DELETE /notifications/{notificationId}dismisses one for the audience: any user with a role on the service for the others, any admin for all admins, but not across the two.404for what the user can't see.reasonSince, so that a reason returning after another one counts.id,type,reason, and optionalserviceId,serviceTypeandsince, so a client can link it.Closes #361
Closes #358
Verification
libapt-pkgcome fromdev.tests/test_notifications.py(100% of the module),tests/test_sync.py,ruff0.17.3,mypy,mkdocs build --strict.tests/test_notifications.pyagainst real MongoDB 7.0.34, 23 passed at that point, and compared the query of admins on both databases for odd URLs and environments.Declined review findings
test_requires_loginpins401).Known limits
GET /approvalsalways lists what is pending.🤖 Generated with Claude Code