From 418cd821de0d4a42afe2b0f0da9a7ca4967cc45d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 17 May 2024 08:29:19 +0100 Subject: [PATCH] chore: Setup feeback_summary relationships and permissions - Rename team -> team_slug - Add team relationship - Add permissions --- hasura.planx.uk/metadata/tables.yaml | 70 +++++++++++++++++++ .../1715929881942_run_sql_migration/down.sql | 40 +++++++++++ .../1715929881942_run_sql_migration/up.sql | 40 +++++++++++ 3 files changed, 150 insertions(+) create mode 100644 hasura.planx.uk/migrations/1715929881942_run_sql_migration/down.sql create mode 100644 hasura.planx.uk/migrations/1715929881942_run_sql_migration/up.sql diff --git a/hasura.planx.uk/metadata/tables.yaml b/hasura.planx.uk/metadata/tables.yaml index d4ac73921d..d66aacabf7 100644 --- a/hasura.planx.uk/metadata/tables.yaml +++ b/hasura.planx.uk/metadata/tables.yaml @@ -268,6 +268,76 @@ - table: name: feedback_summary schema: public + object_relationships: + - name: team + using: + manual_configuration: + column_mapping: + team_slug: slug + insertion_order: null + remote_table: + name: teams + schema: public + select_permissions: + - role: platformAdmin + permission: + columns: + - feedback_id + - device + - node_data + - address + - feedback_type + - help_definition + - help_sources + - help_text + - intersecting_constraints + - node_id + - node_text + - node_title + - node_type + - project_type + - service_slug + - status + - team_slug + - uprn + - user_comment + - user_context + - created_at + filter: {} + comment: "" + - role: teamEditor + permission: + columns: + - feedback_id + - device + - node_data + - address + - feedback_type + - help_definition + - help_sources + - help_text + - intersecting_constraints + - node_id + - node_text + - node_title + - node_type + - project_type + - service_slug + - status + - team_slug + - uprn + - user_comment + - user_context + - created_at + filter: + team: + members: + _and: + - user_id: + _eq: x-hasura-user-id + - role: + _eq: teamEditor + comment: "" - table: name: feedback_type_enum schema: public diff --git a/hasura.planx.uk/migrations/1715929881942_run_sql_migration/down.sql b/hasura.planx.uk/migrations/1715929881942_run_sql_migration/down.sql new file mode 100644 index 0000000000..acfa8a9478 --- /dev/null +++ b/hasura.planx.uk/migrations/1715929881942_run_sql_migration/down.sql @@ -0,0 +1,40 @@ +DROP VIEW "public"."feedback_summary"; + +CREATE OR REPLACE VIEW "public"."feedback_summary" AS +SELECT + fb.id AS feedback_id, + t.slug AS team, + f.slug AS service_slug, + fb.created_at, + fb.node_id, + fb.device, + fb.user_context, + fb.user_comment, + fb.feedback_type, + fb.status, + fb.node_type, + fb.node_data, + COALESCE( + fb.node_data ->> 'title', + fb.node_data ->> 'text', + fb.node_data ->> 'flagSet' + ) AS node_title, + fb.node_data ->> 'description' AS node_text, + fb.node_data ->> 'info' AS help_text, + fb.node_data ->> 'policyRef' AS help_sources, + fb.node_data ->> 'howMeasured' AS help_definition, + COALESCE( + fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'single_line_address', + fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'title' + ) AS address, + (fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'uprn') AS uprn, + (fb.user_data -> 'passport' -> 'data' ->> 'proposal.projectType') AS project_type, + (fb.user_data -> 'passport' -> 'data' ->> 'property.constraints.planning') AS intersecting_constraints +FROM + feedback fb +LEFT JOIN + flows f ON f.id = fb.flow_id +LEFT JOIN + teams t ON t.id = fb.team_id; + +GRANT SELECT ON public.feedback_summary TO metabase_read_only; diff --git a/hasura.planx.uk/migrations/1715929881942_run_sql_migration/up.sql b/hasura.planx.uk/migrations/1715929881942_run_sql_migration/up.sql new file mode 100644 index 0000000000..c03d19bf31 --- /dev/null +++ b/hasura.planx.uk/migrations/1715929881942_run_sql_migration/up.sql @@ -0,0 +1,40 @@ +DROP VIEW "public"."feedback_summary"; + +CREATE OR REPLACE VIEW "public"."feedback_summary" AS +SELECT + fb.id AS feedback_id, + t.slug AS team_slug, + f.slug AS service_slug, + fb.created_at, + fb.node_id, + fb.device, + fb.user_context, + fb.user_comment, + fb.feedback_type, + fb.status, + fb.node_type, + fb.node_data, + COALESCE( + fb.node_data ->> 'title', + fb.node_data ->> 'text', + fb.node_data ->> 'flagSet' + ) AS node_title, + fb.node_data ->> 'description' AS node_text, + fb.node_data ->> 'info' AS help_text, + fb.node_data ->> 'policyRef' AS help_sources, + fb.node_data ->> 'howMeasured' AS help_definition, + COALESCE( + fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'single_line_address', + fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'title' + ) AS address, + (fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'uprn') AS uprn, + (fb.user_data -> 'passport' -> 'data' ->> 'proposal.projectType') AS project_type, + (fb.user_data -> 'passport' -> 'data' ->> 'property.constraints.planning') AS intersecting_constraints +FROM + feedback fb +LEFT JOIN + flows f ON f.id = fb.flow_id +LEFT JOIN + teams t ON t.id = fb.team_id; + +GRANT SELECT ON public.feedback_summary TO metabase_read_only;