Skip to content

feat: add notifications - #364

Merged
uniqueg merged 5 commits into
devfrom
feat/service-notifications
Nov 5, 2026
Merged

uniqueg merged 5 commits into
devfrom
feat/service-notifications

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

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. 404 for what the user can't see.
  • A notification's identifier stands for one episode of the problem, so a dismissed one only comes back if the problem ended and came back, or its reason changed. Updates and renames keep it. Sync state gets reasonSince, so that a reason returning after another one counts.
  • Each item has id, type, reason, and optional serviceId, serviceType and since, so a client can link it.
  • Docs: API, access control, upgrade notes, release notes.

Closes #361
Closes #358

Verification

  • CI on the final commit: all checks passed, including tests on mongomock and MongoDB 7.0, the smoke test, docs and image scan. Two open Trivy notes for libapt-pkg come from dev.
  • Full suite with coverage locally (mongomock, Helm 3.22.1), before the review fixes: 2293 passed, 11 skipped, 100%. After them: tests/test_notifications.py (100% of the module), tests/test_sync.py, ruff 0.17.3, mypy, mkdocs build --strict.
  • The second reviewer ran tests/test_notifications.py against real MongoDB 7.0.34, 23 passed at that point, and compared the query of admins on both databases for odd URLs and environments.
  • Not run: with a real client or UI.

Declined review findings

  • Pagination: not asked for. Only services with problems are read for admins; out-of-sync is computed for services with sync.
  • Per-item handling of malformed documents: these can't be written through the API, and rc2 starts with a fresh database.
  • A TTL on dismissals: they only come from human actions, and expiry could bring back a problem that lasts.
  • Sourcery: bearer security on the two operations (the base specification's default applies, and test_requires_login pins 401).

Known limits

  • For what only admins see, a dismissed problem that ends and returns without any admin listing notifications in between stays dismissed: the registry records neither changes of the pending flag nor of the configuration. Documented; GET /approvals always lists what is pending.

🤖 Generated with Claude Code

uniqueg and others added 3 commits November 5, 2026 03:38
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]>
@sourcery-ai

sourcery-ai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This 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 dismissal

sequenceDiagram
    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
Loading

State diagram for notification episode identity

stateDiagram-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
Loading

Flow diagram for notification visibility and sources

flowchart 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]
Loading

File-Level Changes

Change Details Files
Add computed notification APIs with role- and admin-mode-specific visibility, stable episode identifiers, and audience-wide dismissals.
  • Compute out-of-sync, pending approval, and configuration-violation notifications from current database state.
  • Expose authenticated GET and DELETE endpoints with 404 behavior for invisible or already-dismissed items.
  • Persist dismissals separately for service-role users and administrators.
  • Order active notifications by recency and define linkable service/service-type metadata.
cloud_registry/ga4gh/registry/notifications.py
cloud_registry/api/additions.openapi.yaml
cloud_registry/config.yaml
Make synchronization failures preserve enough lifecycle state to generate stable yet episode-sensitive notification identifiers.
  • Record when the current sync reason began.
  • Reset reason timing when sync succeeds or the failure reason changes.
  • Use stable service database identity so renames retain notification identity.
cloud_registry/ga4gh/registry/sync.py
Document notification behavior and deployment changes.
  • Document schemas, endpoint access, visibility, ordering, dismissal scope, and lifecycle exceptions.
  • Document the new dismissal collection and policy rules required during upgrades.
  • Add the feature to release notes.
docs/api.md
docs/access-control.md
docs/upgrading.md
docs/releases/1.0.0rc2.md
Add comprehensive coverage for notification visibility, lifecycle, dismissal, configuration, and ordering behavior.
  • Test authentication, role/admin filtering, pending and disallowed configuration cases.
  • Test dismissal sharing, 404 handling, recurrence, reason changes, renames, and stable identifiers.
  • Extend mock database configuration with the dismissal collection.
tests/test_notifications.py
tests/mock_data.py

Possibly linked issues

  • feat: add notifications #361: The PR implements the issue’s requested notification API, visibility rules, shared dismissals, lifecycle behavior, and documentation.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (db14ffc) to head (723dbf7).
⚠️ Report is 1 commits behind head on dev.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 5, 2026 02:57

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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]>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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]>
@uniqueg
uniqueg merged commit 31cae10 into dev Nov 5, 2026
28 checks passed
@uniqueg
uniqueg deleted the feat/service-notifications branch November 5, 2026 03:47
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.

feat: add notifications feat: import and sync service info

1 participant