Skip to content

Endpoints for Email Actions Features#192

Merged
codebestia merged 9 commits intomainfrom
feat/email-actions
Nov 5, 2025
Merged

Endpoints for Email Actions Features#192
codebestia merged 9 commits intomainfrom
feat/email-actions

Conversation

@codebestia
Copy link
Member

@codebestia codebestia commented Nov 5, 2025

Related Issue

Fixes #191

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Other (please describe)

How Has This Been Tested?

  • Unit tests
  • Integration tests
  • Manual tests
  • Other (please describe)

Checklist:

  • I have read the contributing guidelines.
  • I have updated the documentation (if applicable).
  • My changes do not break existing functionality.
  • I have added tests that cover my changes (if applicable).
  • All new and existing tests pass.

Summary by CodeRabbit

  • New Features

    • Added email address management for account members with add and update capabilities
    • Added email notification preference controls allowing members to toggle and view their notification settings
    • New settings endpoints for managing account member email preferences
  • Tests

    • Added comprehensive tests for email settings functionality

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces email settings management capabilities by adding a new NotificationPreference model to persist per-member email notification preferences, creating a /settings API blueprint with four endpoints for managing email addresses and notification preferences, and implementing corresponding serializers and service methods.

Changes

Cohort / File(s) Summary
Model Layer
backend/spherre/app/models/notification.py, backend/spherre/app/models/__init__.py
Added NotificationPreference model with account_id and member_id foreign keys, relationships to Account and Member, and email_enabled boolean flag; exported new model in __init__.py.
Serializers
backend/spherre/app/serializers/account.py, backend/spherre/app/serializers/notifications.py
Added EmailRequestSerializer for email input validation; added MemberSchema and NotificationPreferenceSchema for serializing preference data.
Service Layer
backend/spherre/app/service/notification.py
Added get_notification_preference_for_member() and toggle_member_email_notification_preference() methods to NotificationService.
Settings API Blueprint
backend/spherre/app/views/settings.py
Created new blueprint with four endpoints: add_email, update_email, toggle_email_notification_preference, and get_email_notification_preference for managing member email and notification preferences.
App Bootstrap
backend/spherre/app/__init__.py
Imported and registered settings_blueprint alongside other application blueprints.
Tests
backend/spherre/tests/test_views/test_settings_view.py
Added TestSettingsViews test class with setUp/tearDown and three test methods covering email addition, email updates, and notification preference toggling.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Settings API
    participant AuthService
    participant MemberService
    participant NotificationService
    participant DB

    rect rgb(200, 220, 240)
    note over Settings API: add_email / update_email flow
    Client->>Settings API: POST /settings/email/add (JWT, email)
    Settings API->>AuthService: Validate JWT token
    AuthService-->>Settings API: User identity
    Settings API->>MemberService: Lookup member & account
    MemberService->>DB: Query Member, Account
    DB-->>MemberService: Member, Account records
    Settings API->>Settings API: Validate business rules
    Settings API->>MemberService: Update member email
    MemberService->>DB: Update Member.email
    Settings API->>NotificationService: Toggle preference (create/default)
    NotificationService->>DB: Upsert NotificationPreference
    DB-->>NotificationService: Saved record
    Settings API-->>Client: 201 Created
    end

    rect rgb(220, 240, 220)
    note over Settings API: toggle_email_notification_preference flow
    Client->>Settings API: POST /settings/email/notification/toggle (JWT)
    Settings API->>AuthService: Validate JWT
    AuthService-->>Settings API: User identity
    Settings API->>MemberService: Lookup member with email
    Settings API->>NotificationService: Get current preference
    NotificationService->>DB: Query NotificationPreference
    DB-->>NotificationService: Preference record
    Settings API->>NotificationService: Toggle email_enabled flag
    NotificationService->>DB: Update preference
    DB-->>NotificationService: Updated record
    Settings API-->>Client: 201 Created
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

  • Model relationships and foreign keys: Verify the bidirectional relationships between NotificationPreference, Account, and Member are correctly configured with appropriate backref names.
  • JWT authentication and authorization logic: Ensure all four endpoints properly validate account ownership and member authorization before allowing operations.
  • Email validation and duplicate prevention: Check the business logic in add_email prevents duplicate emails and update_email requires an existing email.
  • Service layer transaction handling: Verify toggle_member_email_notification_preference correctly creates vs. updates preferences and handles edge cases (missing account/member).
  • Test coverage completeness: The test file covers happy paths but may lack error scenario testing (invalid account, unauthorized member, validation failures).

Possibly related PRs

  • PR #167: Both PRs modify notification-related codebase including backend/spherre/app/service/notification.py, backend/spherre/app/serializers/notifications.py, and blueprint registration in backend/spherre/app/__init__.py.

Suggested reviewers

  • DanielEmmanuel1

Poem

🐰 Hops of joy for settings new,
Email preferences, shiny and true,
Toggle and add with graceful ease,
Notification dance to please! 📧✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/email-actions

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7606848 and 4ba313a.

📒 Files selected for processing (8)
  • backend/spherre/app/__init__.py (2 hunks)
  • backend/spherre/app/models/__init__.py (2 hunks)
  • backend/spherre/app/models/notification.py (1 hunks)
  • backend/spherre/app/serializers/account.py (1 hunks)
  • backend/spherre/app/serializers/notifications.py (2 hunks)
  • backend/spherre/app/service/notification.py (2 hunks)
  • backend/spherre/app/views/settings.py (1 hunks)
  • backend/spherre/tests/test_views/test_settings_view.py (1 hunks)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codebestia codebestia merged commit d53d1e7 into main Nov 5, 2025
3 of 4 checks passed
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.

Create API endpoints for email related actions

1 participant