Skip to content

Add notifications API endpoint for external consumers#211

Open
peterdrier wants to merge 2 commits intomainfrom
sprint/2026-04-10/batch-4
Open

Add notifications API endpoint for external consumers#211
peterdrier wants to merge 2 commits intomainfrom
sprint/2026-04-10/batch-4

Conversation

@peterdrier
Copy link
Copy Markdown
Owner

Summary

  • New GET /api/notifications endpoint returning unread notifications and live meter counts
  • Authenticated via X-Api-Key header with NOTIFICATION_API_KEY env var, maps to a specific user via NOTIFICATION_API_USER_ID
  • Reuses existing NotificationInboxService (inbox) and NotificationMeterProvider (meters); supports optional ?since=yyyy-MM-dd filtering

Issues

Test plan

  • Set NOTIFICATION_API_KEY and NOTIFICATION_API_USER_ID env vars, call GET /api/notifications with valid X-Api-Key header — verify 200 with notifications and meters
  • Call without X-Api-Key header — verify 401
  • Call with wrong API key — verify 401
  • Call with no env vars configured — verify 503
  • Call with ?since=2026-04-09 — verify only notifications on or after that date are returned
  • Call with ?since=invalid — verify 400 with error message

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a8a4dbeec

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +13 to +16
[ApiController]
[Route("api/notifications")]
[ServiceFilter(typeof(NotificationApiKeyAuthFilter))]
public class NotificationApiController : ControllerBase
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Mark API-key endpoint as anonymous to avoid membership redirects

This controller is missing [AllowAnonymous], so requests with a valid X-Api-Key can still be redirected by the global MembershipRequiredFilter when the caller also has an authenticated but non-active-member cookie. In Program.cs, that filter is applied globally, and in MembershipRequiredFilter authenticated users are redirected unless the action/controller is anonymous; as written, /api/notifications can return a 302 HTML redirect instead of the JSON API response depending on caller session state.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

peterdrier commented Apr 10, 2026

Release Review — Issue Found

The earlier automated Codex inline comment on this PR is valid, and my later approval comment was too permissive.

  1. NotificationApiController is missing [AllowAnonymous]. The app registers MembershipRequiredFilter globally, and that filter redirects authenticated non-active-members unless the endpoint is anonymous or explicitly exempt. As written, /api/notifications can return a 302 HTML redirect instead of the expected JSON response when the caller happens to send a valid API key along with an authenticated but non-member cookie.

Because of that behavior mismatch, I would not call this ready for production yet. It should be marked anonymous, or otherwise explicitly exempted from the membership filter.

peterdrier and others added 2 commits April 10, 2026 16:34
…ctive#469)

New GET /api/notifications endpoint authenticated via X-Api-Key header,
returning unread notifications and live meter counts for a configured user.
Reuses existing NotificationInboxService and NotificationMeterProvider.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Prevents MembershipRequiredFilter from redirecting API-key-authenticated
requests to HTML membership pages when the caller also has a non-member
cookie session.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@peterdrier peterdrier force-pushed the sprint/2026-04-10/batch-4 branch from 3a8a4db to 8a83696 Compare April 10, 2026 14:38
@peterdrier
Copy link
Copy Markdown
Owner Author

Code Review — Approved ✅

Reviewed against CODING_RULES.md and CODE_REVIEW_RULES.md. Codex finding addressed.

What was checked:

  • [AllowAnonymous] added to bypass MembershipRequiredFilter for API-key-only requests
  • ServiceFilter for NotificationApiKeyAuthFilter still enforces API key authentication
  • API key settings registration and NotificationApiSettings DTO verified correct

Ready to merge.

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.

Add notifications API endpoint for external consumers

1 participant