diff --git a/hasura.planx.uk/metadata/tables.yaml b/hasura.planx.uk/metadata/tables.yaml index cd5f0e6376..d96ec6375d 100644 --- a/hasura.planx.uk/metadata/tables.yaml +++ b/hasura.planx.uk/metadata/tables.yaml @@ -1649,6 +1649,122 @@ - role: platformAdmin permission: filter: {} +- table: + name: team_settings + schema: public + object_relationships: + - name: team + using: + foreign_key_constraint_on: team_id + select_permissions: + - role: api + permission: + columns: + - has_planning_data + - id + - team_id + - boundary_json + - boundary_url + - email_reply_to_id + - external_planning_site_name + - external_planning_site_url + - help_email + - help_opening_hours + - help_phone + - homepage + - reference_code + filter: {} + comment: "" + - role: platformAdmin + permission: + columns: + - has_planning_data + - id + - team_id + - boundary_json + - boundary_url + - email_reply_to_id + - external_planning_site_name + - external_planning_site_url + - help_email + - help_opening_hours + - help_phone + - homepage + - reference_code + filter: {} + comment: "" + - role: public + permission: + columns: + - boundary_json + - boundary_url + - external_planning_site_name + - external_planning_site_url + - has_planning_data + - homepage + - id + - reference_code + - team_id + filter: {} + comment: "" + - role: teamEditor + permission: + columns: + - has_planning_data + - id + - team_id + - boundary_json + - boundary_url + - email_reply_to_id + - external_planning_site_name + - external_planning_site_url + - help_email + - help_opening_hours + - help_phone + - homepage + - reference_code + filter: {} + comment: "" + update_permissions: + - role: platformAdmin + permission: + columns: + - boundary_url + - email_reply_to_id + - external_planning_site_name + - external_planning_site_url + - has_planning_data + - help_email + - help_opening_hours + - help_phone + - homepage + - reference_code + filter: {} + check: null + comment: "" + - role: teamEditor + permission: + columns: + - boundary_url + - email_reply_to_id + - external_planning_site_name + - external_planning_site_url + - has_planning_data + - help_email + - help_opening_hours + - help_phone + - homepage + - reference_code + filter: + team: + members: + _and: + - user_id: + _eq: x-hasura-user-id + - role: + _eq: teamEditor + check: null + comment: "" - table: name: team_themes schema: public diff --git a/hasura.planx.uk/migrations/1718719894002_create_table_public_team_settings/down.sql b/hasura.planx.uk/migrations/1718719894002_create_table_public_team_settings/down.sql new file mode 100644 index 0000000000..29fc26cbc2 --- /dev/null +++ b/hasura.planx.uk/migrations/1718719894002_create_table_public_team_settings/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."team_settings"; diff --git a/hasura.planx.uk/migrations/1718719894002_create_table_public_team_settings/up.sql b/hasura.planx.uk/migrations/1718719894002_create_table_public_team_settings/up.sql new file mode 100644 index 0000000000..50faf5931a --- /dev/null +++ b/hasura.planx.uk/migrations/1718719894002_create_table_public_team_settings/up.sql @@ -0,0 +1,26 @@ +CREATE TABLE "public"."team_settings" ("id" serial NOT NULL, +"team_id" integer NOT NULL, +"reference_code" text, +"homepage" text, +"help_email" text NOT NULL DEFAULT 'example@council.gov.uk', +"help_phone" text NOT NULL DEFAULT '(01234) 567890', +"help_opening_hours" text NOT NULL DEFAULT 'Monday - Friday, 9am - 5pm', +"email_reply_to_id" text NOT NULL DEFAULT '727d48fa-cb8a-42f9-b8b2-55032f3bb451', +"has_planning_data" boolean NOT NULL DEFAULT False, +"external_planning_site_url" text DEFAULT 'https://www.planningportal.co.uk/', +"external_planning_site_name" text DEFAULT 'Planning Portal', +"boundary_url" text, +"boundary_json" jsonb NOT NULL DEFAULT '{"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[1.9134116, 49.528423], [1.9134116, 61.331151], [1.9134116, 61.331151], [-10.76418, 61.331151], [-10.76418, 49.528423]]]}, "properties": {}}'::jsonb, +PRIMARY KEY ("id") , +FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON UPDATE cascade ON DELETE cascade, +UNIQUE ("id"), UNIQUE ("team_id"), UNIQUE ("reference_code")); +COMMENT ON TABLE "public"."team_settings" IS E'Global settings for boundary and contact details'; + +comment on column "public"."team_settings"."reference_code" is E'Team name in three letter short form'; +comment on column "public"."team_settings"."team_id" is E'Linked ID to Teams table'; +comment on column "public"."team_settings"."help_phone" is E'For use in gov notify emails'; +comment on column "public"."team_settings"."help_email" is E'For use in gov notify emails'; +comment on column "public"."team_settings"."help_opening_hours" is E'For use in gov notify emails'; +comment on column "public"."team_settings"."email_reply_to_id" is E'Generate by gov notify and relates to the "reply to" address in notifications'; +comment on column "public"."team_settings"."boundary_url" is E'User entered boundary linked to https://www.planning.data.gov.uk/'; +comment on column "public"."team_settings"."boundary_json" is E'Long form boundary geojson - used to compute boundary_bbox'; diff --git a/hasura.planx.uk/migrations/1718728257637_populate_team_settings_table/down.sql b/hasura.planx.uk/migrations/1718728257637_populate_team_settings_table/down.sql new file mode 100644 index 0000000000..62c33be674 --- /dev/null +++ b/hasura.planx.uk/migrations/1718728257637_populate_team_settings_table/down.sql @@ -0,0 +1 @@ +TRUNCATE TABLE "public"."team_settings"; \ No newline at end of file diff --git a/hasura.planx.uk/migrations/1718728257637_populate_team_settings_table/up.sql b/hasura.planx.uk/migrations/1718728257637_populate_team_settings_table/up.sql new file mode 100644 index 0000000000..fb867822dd --- /dev/null +++ b/hasura.planx.uk/migrations/1718728257637_populate_team_settings_table/up.sql @@ -0,0 +1,15 @@ +INSERT INTO team_settings (team_id, reference_code, homepage, help_email, help_phone,help_opening_hours ,email_reply_to_id,has_planning_data , external_planning_site_url,external_planning_site_name,boundary_url,boundary_json) +SELECT +id as team_id, +reference_code, +settings ->> 'homepage' as homepage, +COALESCE(notify_personalisation ->> 'helpEmail', 'example@council.co.uk') as help_email, +COALESCE(notify_personalisation ->> 'helpPhone', '(01234) 567890') as help_phone, +COALESCE(notify_personalisation ->> 'helpOpeningHours', 'Monday - Friday, 9am - 5pm') as help_opening_hours, +COALESCE(notify_personalisation ->> 'emailReplyToId', '727d48fa-cb8a-42f9-b8b2-55032f3bb451') as email_reply_to_id, +CAST(COALESCE(settings ->> 'hasPlanningData', 'false' ) as boolean) as has_planning_data, +COALESCE(settings #>> '{externalPlanningSite,url}', 'https://www.planningportal.co.uk/' ) as external_planning_site_url, +COALESCE(settings #>> '{externalPlanningSite,name}', 'Planning Portal') as external_planning_site_name, +settings ->> 'boundary' as boundary_url, +boundary as boundary_json +FROM teams;