"""Canonical DAX mappings: personal and SA requests need resource owners only. The deployable Feishu definitions must match this policy. Updating these mappings does not change published Feishu templates or in-flight instances. Retired Group authoring keeps its historical mapping for compatibility. """ from __future__ import annotations from copy import deepcopy from typing import Any from app.domains.data_access.constants import ( APPROVAL_FLOW_DATA_ACCESS_GROUP_GRANT, APPROVAL_FLOW_DATA_ACCESS_PERSONAL_GRANT, APPROVAL_FLOW_DATA_ACCESS_SERVICE_ACCOUNT_GRANT, ) DATA_ACCESS_GROUP_GRANT_FLOW_LABEL = "Data access group grant" DATA_ACCESS_SERVICE_ACCOUNT_GRANT_FLOW_LABEL = "Data access service account grant" DATA_ACCESS_PERSONAL_GRANT_FLOW_LABEL = "Data access personal grant" DATA_ACCESS_GROUP_GRANT_PAYLOAD_SCHEMA: dict[str, Any] = { "request_summary": { "id": "dax_request_summary", "type": "textarea", }, "requested_access": { "id": "dax_requested_access", "type": "textarea", }, "dataset_list": { "id": "dax_dataset_list", "type": "textarea", }, "business_reason": { "id": "dax_business_reason", "type": "textarea", }, "detail_url": { "id": "dax_detail_url", "type": "input", }, "approval_process": { "sequence": [ { "key": "requester_line_manager_review", "approver_source": "feishu_requester_line_manager", "instance_payload_field": None, }, { "key": "data_owner_review", "approver_source": "helix_resource_owner", "instance_payload_field": "node_approver_open_id_list", }, ], "approver_nodes": { "data_owner_review": { "id": "data_owner_review", "approver_source": "helix_resource_owner", "instance_payload_field": "node_approver_open_id_list", }, }, }, } DATA_ACCESS_SERVICE_ACCOUNT_GRANT_PAYLOAD_SCHEMA: dict[str, Any] = { "request_summary": { "id": "dax_sa_request_summary", "type": "textarea", }, "requested_access": { "id": "dax_sa_requested_access", "type": "textarea", }, "dataset_list": { "id": "dax_sa_dataset_list", "type": "textarea", }, "business_reason": { "id": "dax_sa_business_reason", "type": "textarea", }, "detail_url": { "id": "dax_sa_detail_url", "type": "input", }, "approval_process": { "sequence": [ { "key": "data_owner_review", "approver_source": "helix_resource_owner", "instance_payload_field": "node_approver_open_id_list", }, ], "approver_nodes": { "data_owner_review": { "id": "data_owner_review", "approver_source": "helix_resource_owner", "instance_payload_field": "node_approver_open_id_list", }, }, }, } DATA_ACCESS_PERSONAL_GRANT_PAYLOAD_SCHEMA: dict[str, Any] = { "request_summary": { "id": "dax_personal_request_summary", "type": "textarea", }, "requested_access": { "id": "dax_personal_requested_access", "type": "textarea", }, "dataset_list": { "id": "dax_personal_dataset_list", "type": "textarea", }, "business_reason": { "id": "dax_personal_business_reason", "type": "textarea", }, "detail_url": { "id": "dax_personal_detail_url", "type": "input", }, "approval_process": { "sequence": [ { "key": "data_owner_review", "approver_source": "helix_resource_owner", "instance_payload_field": "node_approver_open_id_list", }, ], "approver_nodes": { "data_owner_review": { "id": "data_owner_review", "approver_source": "helix_resource_owner", "instance_payload_field": "node_approver_open_id_list", }, }, }, } def data_access_group_grant_flow_mapping( *, external_code: str, ) -> dict[str, Any]: return { "flow_key": APPROVAL_FLOW_DATA_ACCESS_GROUP_GRANT, "label": DATA_ACCESS_GROUP_GRANT_FLOW_LABEL, "external_code": external_code, "accept_external_origin": False, "payload_schema": deepcopy(DATA_ACCESS_GROUP_GRANT_PAYLOAD_SCHEMA), } def data_access_service_account_grant_flow_mapping( *, external_code: str, ) -> dict[str, Any]: """Mapping for the manually deployed typed-SA approval template.""" return { "flow_key": APPROVAL_FLOW_DATA_ACCESS_SERVICE_ACCOUNT_GRANT, "label": DATA_ACCESS_SERVICE_ACCOUNT_GRANT_FLOW_LABEL, "external_code": external_code, "accept_external_origin": False, "payload_schema": deepcopy(DATA_ACCESS_SERVICE_ACCOUNT_GRANT_PAYLOAD_SCHEMA), } def data_access_personal_grant_flow_mapping( *, external_code: str, ) -> dict[str, Any]: """Mapping for direct employee BigQuery dataset-read approvals.""" return { "flow_key": APPROVAL_FLOW_DATA_ACCESS_PERSONAL_GRANT, "label": DATA_ACCESS_PERSONAL_GRANT_FLOW_LABEL, "external_code": external_code, "accept_external_origin": False, "payload_schema": deepcopy(DATA_ACCESS_PERSONAL_GRANT_PAYLOAD_SCHEMA), }