Lookup Trigger Assignment

Implementation report for assigning specific lookup data triggers to individual enumerators via Manage Form Access

Extends the Manage Form Access feature to allow access providers (Field Supervisors/Admins) to optionally assign specific lookup data trigger values to individual Enumerators.

Key Behaviors

  • Per-value exclusivity: Each trigger VALUE is exclusive per survey
  • Optional assignment: If no triggers assigned, Enumerator sees all lookup data
  • Server-side filtering: survey-service filters lookup_data rows based on user's assigned triggers
  • Edit later: Triggers can be assigned at grant time and modified later via PATCH

Database Schema

New Table: form_access_lookup_triggers

CREATE TABLE form_access_lookup_triggers (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    form_access_id UUID NOT NULL REFERENCES form_access(id) ON DELETE CASCADE,
    survey_id UUID NOT NULL REFERENCES surveys(id) ON DELETE CASCADE,
    tenant_id UUID NOT NULL,
    trigger_question VARCHAR(255) NOT NULL,
    trigger_value VARCHAR(255) NOT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    CONSTRAINT uq_falt_survey_trigger_value UNIQUE (survey_id, trigger_question, trigger_value)
);

API Contract Changes

POST /api/v1/surveys/{survey_id}/access

{
    "user_id": "uuid",
    "access_level": "fill",
    "assigned_triggers": [
        {"trigger_question": "s_state", "trigger_value": "rajasthan"},
        {"trigger_question": "s_state", "trigger_value": "bihar"}
    ]
}

GET /api/v1/lookups/{survey_id}/available-triggers (NEW)

Returns available and assigned trigger values for the picker UI:

{
    "trigger_questions": ["s_state"],
    "available_values": {"s_state": ["rajasthan", "madhya_pradesh"]},
    "assigned_values": {"s_state": {"uttar_pradesh": "user_uuid_1"}}
}

Files Created

FilePurpose
survey-service/alembic/versions/007_create_form_access_lookup_triggers.pyDatabase migration
survey-service/api/domain/entities/form_access_lookup_trigger.pySQLAlchemy entity

Files Modified

FileChanges
survey-service/api/common/dtos/form_access.pyAdded LookupTriggerAssignment DTO, assigned_triggers field
survey-service/api/usecase/form_access.pyAdded trigger assignment/removal/batch methods, TriggerAlreadyAssignedError
survey-service/api/interfaces/api_controllers/form_access.pyHTTP 409 on exclusivity conflict
survey-service/api/interfaces/api_controllers/lookups.pyAdded available-triggers endpoint
form-service/api/usecases/form_renderer_service.pyFiltered lookup data per user
frontend/app/src/components/features/surveys/access-management-modal.tsxTrigger picker UI, badges, edit popover