feat: wire notifications into enrollment and session creation events#55
feat: wire notifications into enrollment and session creation events#55ayesha1145 wants to merge 1 commit intoalphaonelabs:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughTwo API endpoints in Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant api_join
participant Database
participant NotificationService
participant Sentry
Client->>api_join: POST /join (user, activity)
api_join->>Database: Insert enrollment
Database-->>api_join: Enrollment confirmed
api_join->>Database: Query activity.host_id, decrypt joiner name
Database-->>api_join: host_id, joiner_name
alt Notification attempt
api_join->>NotificationService: _create_notification(type="new_enrollment", to=host, msg=joiner_name + activity.title)
NotificationService-->>api_join: OK
else Error occurs
NotificationService-->>api_join: Error
api_join->>Sentry: capture_exception(error)
Sentry-->>api_join: Acknowledged
end
api_join-->>Client: 200 OK (join response)
sequenceDiagram
participant Client
participant api_create_session
participant Database
participant NotificationService
participant Sentry
Client->>api_create_session: POST /sessions (creator, activity, title, ...)
api_create_session->>Database: Insert session record
Database-->>api_create_session: Session created
api_create_session->>Database: Query enrolled users (active, non-inactive), exclude creator
Database-->>api_create_session: participant_list
alt Notification attempt
api_create_session->>NotificationService: _create_notification(type="new_session", to=each participant, msg=title)
NotificationService-->>api_create_session: OK
else Error occurs
NotificationService-->>api_create_session: Error
api_create_session->>Sentry: capture_exception(error)
Sentry-->>api_create_session: Acknowledged
end
api_create_session-->>Client: 200 OK (session response)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/worker.py`:
- Around line 1098-1115: The SQL uses "JOIN users u ON u.id = ?" which is
intentional to fetch the joiner's row via a bind param rather than expressing a
relationship to activities, but this is confusing; add a brief clarifying inline
comment immediately above the env.DB.prepare call (in the block that builds
act_detail) stating that the JOIN is used solely to fetch the user row by bind
param (or alternatively split into two queries: one to fetch the activity via
prepare(...).bind(...).first() and another to fetch the user by id) so future
readers won't mistake the JOIN for an activity→user relation; keep the rest of
the logic (decrypt, _create_notification, variable names) unchanged.
- Around line 1229-1246: The current try/except around the entire enrolled loop
causes one failure to abort notifications for all users; change the structure so
the DB query (env.DB.prepare(...).bind(act_id).all()) remains in its own
try/except, then iterate over enrolled.results and wrap each per-row
notification call to _create_notification in its own try/except that calls
capture_exception(exc, env=env, where="api_create_session.notify_enrolled",
extra={"user_id": row.user_id, "activity_id": act_id}) so each user failure is
isolated; keep the outer exception handling just for the DB query and consider
switching to batching later if enrollments grow.
- Around line 1098-1118: Replace the deprecated synchronous shim calls with
their async counterparts: in the join notification block where decrypt(...) is
called (referenced in the api_join notify_host flow, act_detail.joiner_name),
change to await decrypt_aes(...) and await the result; in _create_notification
where encrypt(...) is used for title and message, replace those calls with await
encrypt_aes(...) so the encrypted values are awaited before DB insert; and in
api_list_notifications where decrypt(...) is used to read stored notifications,
replace with await decrypt_aes(...). Ensure the surrounding functions are async
(or already async), import the async helpers if needed, and await the calls so
exceptions surface properly rather than hitting the deprecated stubs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: f83a81cd-dc23-42fb-a453-b3b45d974681
📒 Files selected for processing (1)
src/worker.py
defc01c to
494ef7c
Compare
Connects the merged notifications system (PR #48) to real platform events by calling _create_notification() in two key handlers.
Changes
api_join:
new_enrollmentnotificationapi_create_session:
new_sessionnotificationDesign
new_enrollment,new_sessionTesting
Purpose
Integrate the notifications system into two platform events so hosts and participants receive timely alerts for enrollments and new sessions.
Key Changes
api_join
api_create_session
Implementation details
Impact
Hosts receive a new_enrollment notice when students join; enrolled participants are notified of new sessions via new_session notifications. These additions improve engagement without changing API behaviour or risking operation failures due to notification errors.