Skip to content

feat: add OIDC send email api endpoint [RIGSE-334]#1472

Open
dougmartin wants to merge 2 commits intomasterfrom
RIGSE-334-add-send-email-api
Open

feat: add OIDC send email api endpoint [RIGSE-334]#1472
dougmartin wants to merge 2 commits intomasterfrom
RIGSE-334-add-send-email-api

Conversation

@dougmartin
Copy link
Member

Add a new API endpoint that allows OIDC-authenticated services (Cloud Functions) to send plain-text email notifications to the invoking user. This supports the AI4VS button interactive (QI-116) notifying teachers when students complete actions like joining a class.

  • OidcMailer with plain-text template in app/models/ (matches codebase convention)
  • Pundit policy enforcing OIDC-only authorization (defense in depth)
  • Controller with dual-layer OIDC auth, input validation, type checking, subject newline sanitization, error handling (502), and audit logging
  • Route: POST /api/v1/emails/oidc_send
  • 16 specs covering auth enforcement, validation, delivery, and error paths

Add a new API endpoint that allows OIDC-authenticated services (Cloud
Functions) to send plain-text email notifications to the invoking user.
This supports the AI4VS button interactive (QI-116) notifying teachers
when students complete actions like joining a class.

- OidcMailer with plain-text template in app/models/ (matches codebase convention)
- Pundit policy enforcing OIDC-only authorization (defense in depth)
- Controller with dual-layer OIDC auth, input validation, type checking,
  subject newline sanitization, error handling (502), and audit logging
- Route: POST /api/v1/emails/oidc_send
- 16 specs covering auth enforcement, validation, delivery, and error paths
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new OIDC-restricted Portal API endpoint for sending plain-text email notifications to the invoking (OIDC-mapped) user, intended for server-to-server callers like Cloud Functions.

Changes:

  • Introduces POST /api/v1/emails/oidc_send with OIDC-only enforcement (controller guard + Pundit policy), validation, logging, and delivery error handling.
  • Adds OidcMailer with a plain-text template for sending the message.
  • Adds specs covering policy authorization, controller behavior, and mailer formatting.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
specs/RIGSE-334-send-email-api.md Functional/technical spec for the new OIDC send-email endpoint.
rails/app/controllers/api/v1/emails_controller.rb Implements oidc_send endpoint with OIDC-only guard, validation, logging, and SMTP error handling.
rails/app/policies/api/v1/email_policy.rb Pundit policy enforcing OIDC-only access for oidc_send?.
rails/app/models/oidc_mailer.rb Adds mailer for sending plain-text messages.
rails/app/views/oidc_mailer/send_message.text.erb Plain-text mailer template rendering the message body.
rails/config/routes.rb Adds the new /api/v1/emails/oidc_send route.
rails/spec/controllers/api/v1/emails_controller_spec.rb Controller specs for auth/validation/delivery/error paths (needs isolation fix).
rails/spec/models/oidc_mailer_spec.rb Mailer spec verifying headers/body/content type.
rails/spec/policies/api/v1/email_policy_spec.rb Policy spec verifying OIDC-only authorization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Prevents flaky test failures from delivery state leaking across
examples (e.g., "does not send email" assertion failing because a
prior test sent one).
@dougmartin dougmartin requested a review from scytacki March 13, 2026 12:55
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.

2 participants