Define UserRole-to-RLS filter mapping constants
epic-contact-list-management-foundation-task-001 — Create the ContactRLSQueryBuilder class skeleton and define the mapping table that translates the application-level UserRole enum (coordinator, org_admin, peer_mentor) into the corresponding Supabase filter expressions. Establish the interface contract that downstream query methods will consume.
Acceptance Criteria
Technical Requirements
Implementation Notes
Define the filter descriptor as a simple Dart class or record with fields: columnName (String), operator (enum: eq, in, contains), and value (dynamic). This avoids string concatenation errors later. Place the mapping in a private static const Map inside ContactRLSQueryBuilder — do not expose it publicly to prevent external mutation. For the org_admin role, the filter descriptor may need a 'scope' flag to indicate it queries across multiple organisation units; model this now even if the multi-org logic is implemented in a later task.
Follow Dart naming conventions: snake_case for file names, PascalCase for classes, camelCase for methods.
Testing Requirements
Unit tests (added in task-004) will cover this class, but during this task verify the mapping by writing a simple assertion script or a minimal dart test that iterates all UserRole values and confirms each resolves to a non-null, non-empty filter descriptor. This smoke test should run in under 1 second and guards against typos in enum values. Use flutter_test.
Existing Supabase RLS policies for the contacts and peer_mentors tables may not align with the application-level UserRole model, causing ContactRLSQueryBuilder to construct filter expressions that are redundant, conflicting, or that allow over-fetching. In a multi-chapter context (NHF), this could expose contacts belonging to other chapters.
Mitigation & Contingency
Mitigation: Audit and document the existing RLS policies against the UserRole enum before writing a single line of query builder code. Write integration tests asserting cross-organization data isolation using separate test user tokens for each role.
Contingency: If RLS policies are misaligned at runtime, add an explicit application-level organization_id equality check in ContactRepository as a secondary guard while the database policies are corrected in a coordinated migration.
The Supabase schema for contacts and peer_mentors tables may differ from the expected typed models — missing columns, renamed fields, or type mismatches — causing deserialization failures that surface only at runtime during integration testing.
Mitigation & Contingency
Mitigation: Document expected schema fields upfront and validate against the live Supabase schema at sprint start. Use freezed and json_serializable for compile-time-safe deserialization with explicit required/optional field declarations.
Contingency: Introduce nullable fields with safe defaults for any schema mismatches discovered in testing; log deserialization errors to the monitoring service so schema drift is caught before production deployment.