Service Layer medium complexity mobile
1
Dependencies
1
Dependents
3
Entities
0
Integrations

Description

Service applying role-based visibility rules to the notification feed. Peer mentors see only their own notifications; coordinators additionally see notifications concerning their assigned peer mentors; org admins see all org-wide alerts. Encapsulates role logic so BLoC queries and filters correctly without leaking business rules into the UI layer.

Feature: In-app Notification Centre

role-aware-notification-filter

Summaries

The Role-Aware Notification Filter Service enforces the privacy and operational boundaries that make the notification system trustworthy and compliant. Without it, peer mentors could see coordinator-level alerts, or coordinators might miss notifications about their assigned mentees — both outcomes that undermine programme integrity and user confidence. By centralising role logic in one service rather than scattering it across the UI, the business ensures that any future role or permission change is applied consistently in a single place, dramatically reducing the risk of security gaps or inconsistent data exposure as the platform scales. This component is a key enabler for safely onboarding new user types or expanding the notification scope without regressions.

The Role-Aware Notification Filter Service is a medium-complexity component with a critical dependency on the notification repository for coordinator-scope resolution (fetching the list of peer mentors assigned to a coordinator). This introduces a database query path that must be tested under realistic data volumes to avoid performance regressions. The service must be delivered and stable before the Notification BLoC can be considered complete, since the BLoC delegates all filtering to it. Risk areas include the coordinator multi-peer-mentor scope: if the assignment model changes (e.g., coordinators gain or lose mentees dynamically), this service must be updated in lockstep.

Ensure the acceptance tests explicitly cover all three role scopes — peer mentor, coordinator, and org admin — with edge cases for empty mentor lists and mixed org membership.

Role-Aware Notification Filter Service exposes two complementary paths: buildQueryFilter(userId, UserRole) constructs Supabase PostgREST query predicates applied at fetch time, and filterNotifications(List, UserRole, userId) applies equivalent in-memory logic after Realtime events arrive to maintain consistency between initial loads and live updates. The coordinator scope requires an async getCoordinatorPeerMentorIds(coordinatorId) call to resolve the coordinator-to-mentee mapping, which is fetched from the notification-repository. isOrgWideAlert(NotificationType) is a pure synchronous predicate used by the org admin path. The service must be stateless (no cached role data) to avoid stale access decisions after role changes.

Both paths must produce identical visibility outcomes — divergence between query and in-memory filtering will cause phantom notifications appearing after realtime events that the initial query would have excluded.

Responsibilities

  • Determine notification visibility scope based on user role
  • Build Supabase query predicates for role-appropriate notification set
  • Filter in-memory notification lists after realtime updates
  • Support coordinator multi-peer-mentor scope resolution
  • Ensure org admin receives org-wide alert notifications

Interfaces

buildQueryFilter(String userId, UserRole role)
filterNotifications(List<Notification>, UserRole, String userId)
isVisibleToUser(Notification, UserRole, String userId)
getCoordinatorPeerMentorIds(String coordinatorId)
isOrgWideAlert(NotificationType)

Relationships

Dependencies (1)

Components this component depends on

Dependents (1)

Components that depend on this component

Related Data Entities (3)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/notification-filters 5 endpoints
GET /api/v1/notification-filters List all saved notification filter configurations
GET /api/v1/notification-filters/:id Get a specific notification filter configuration
POST /api/v1/notification-filters Create a role-aware filter configuration for a user
PUT /api/v1/notification-filters/:id Update an existing notification filter configuration
DELETE /api/v1/notification-filters/:id Delete a notification filter configuration