diff --git a/hasura.planx.uk/metadata/tables.yaml b/hasura.planx.uk/metadata/tables.yaml index 2e6347e32a..eb5be3e98f 100644 --- a/hasura.planx.uk/metadata/tables.yaml +++ b/hasura.planx.uk/metadata/tables.yaml @@ -1220,6 +1220,18 @@ - locked_at: _is_null: true check: null +- table: + schema: public + name: team_integrations + select_permissions: + - role: api + permission: + columns: + - id + - team_id + - staging_bops_submission_url + - production_bops_submission_url + filter: {} - table: schema: public name: team_members @@ -1284,6 +1296,14 @@ - table: schema: public name: teams + object_relationships: + - name: integrations + using: + foreign_key_constraint_on: + column: team_id + table: + schema: public + name: team_integrations array_relationships: - name: flows using: diff --git a/hasura.planx.uk/migrations/1701282718987_create_table_public_team_integrations/down.sql b/hasura.planx.uk/migrations/1701282718987_create_table_public_team_integrations/down.sql new file mode 100644 index 0000000000..f3ab63ba15 --- /dev/null +++ b/hasura.planx.uk/migrations/1701282718987_create_table_public_team_integrations/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."team_integrations"; diff --git a/hasura.planx.uk/migrations/1701282718987_create_table_public_team_integrations/up.sql b/hasura.planx.uk/migrations/1701282718987_create_table_public_team_integrations/up.sql new file mode 100644 index 0000000000..a05efec395 --- /dev/null +++ b/hasura.planx.uk/migrations/1701282718987_create_table_public_team_integrations/up.sql @@ -0,0 +1,11 @@ +CREATE TABLE "public"."team_integrations" ( + "id" serial NOT NULL, + "team_id" integer NOT NULL, + "staging_bops_submission_url" text, + "production_bops_submission_url" text, + PRIMARY KEY ("id"), + FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON UPDATE restrict ON DELETE cascade, + UNIQUE ("team_id") +); + +COMMENT ON TABLE "public"."team_integrations" IS E'Tracks URLs and API keys for integrations'; \ No newline at end of file diff --git a/hasura.planx.uk/tests/team_integrations.test.js b/hasura.planx.uk/tests/team_integrations.test.js new file mode 100644 index 0000000000..612c5a4b8d --- /dev/null +++ b/hasura.planx.uk/tests/team_integrations.test.js @@ -0,0 +1,76 @@ +const { introspectAs } = require("./utils"); + +describe("team_integrations", () => { + describe("public", () => { + let i; + beforeAll(async () => { + i = await introspectAs("public"); + }); + + test("cannot query team_integrations", () => { + expect(i.queries).not.toContain("team_integrations"); + }); + + test("cannot create, update, or delete team_integrations", () => { + expect(i).toHaveNoMutationsFor("team_integrations"); + }); + }); + + describe("admin", () => { + let i; + beforeAll(async () => { + i = await introspectAs("admin"); + }); + + test("has full access to query and mutate team_integrations", () => { + expect(i.queries).toContain("team_integrations"); + expect(i.mutations).toContain("insert_team_integrations"); + expect(i.mutations).toContain("update_team_integrations_by_pk"); + expect(i.mutations).toContain("delete_team_integrations"); + }); + }); + + describe("platformAdmin", () => { + let i; + beforeAll(async () => { + i = await introspectAs("platformAdmin"); + }); + + test("cannot query team_integrations", () => { + expect(i.queries).not.toContain("team_integrations"); + }); + + test("cannot create, update, or delete team_integrations", () => { + expect(i).toHaveNoMutationsFor("team_integrations"); + }); + }); + + describe("teamEditor", () => { + beforeAll(async () => { + i = await introspectAs("teamEditor"); + }); + + test("cannot query team_integrations", () => { + expect(i.queries).not.toContain("team_integrations"); + }); + + test("cannot create, update, or delete team_integrations", () => { + expect(i).toHaveNoMutationsFor("team_integrations"); + }); + }); + + describe("api", () => { + let i; + beforeAll(async () => { + i = await introspectAs("api"); + }); + + test("can query team_integrations", () => { + expect(i.queries).toContain("team_integrations"); + }); + + test("cannot create, update, or delete team_integrations", () => { + expect(i).toHaveNoMutationsFor("team_integrations"); + }); + }); +}); diff --git a/scripts/seed-database/container.sh b/scripts/seed-database/container.sh index 0b6828e113..31523cd953 100755 --- a/scripts/seed-database/container.sh +++ b/scripts/seed-database/container.sh @@ -33,6 +33,11 @@ for table in "${tables[@]}"; do fi done +# Copy subset of team_integrations columns +# Do not copy production values +psql --quiet ${REMOTE_PG} --command="\\copy (SELECT id, team_id, staging_bops_submission_url FROM team_integrations TO '/tmp/team_integrations.csv' (FORMAT csv, DELIMITER ';');" +echo team_integrations downloaded + psql --quiet ${REMOTE_PG} --command="\\copy (SELECT DISTINCT ON (flow_id) id, data, flow_id, summary, publisher_id, created_at FROM published_flows ORDER BY flow_id, created_at DESC) TO '/tmp/published_flows.csv' (FORMAT csv, DELIMITER ';');" echo published_flows downloaded diff --git a/scripts/seed-database/write/main.sql b/scripts/seed-database/write/main.sql index 28c4da61fd..f39a94cb10 100644 --- a/scripts/seed-database/write/main.sql +++ b/scripts/seed-database/write/main.sql @@ -3,4 +3,5 @@ \include write/flows.sql \include write/flow_document_templates.sql \include write/published_flows.sql -\include write/team_members.sql \ No newline at end of file +\include write/team_members.sql +\include write/team_integrations.sql \ No newline at end of file diff --git a/scripts/seed-database/write/team_integrations.sql b/scripts/seed-database/write/team_integrations.sql new file mode 100644 index 0000000000..a8eb62926d --- /dev/null +++ b/scripts/seed-database/write/team_integrations.sql @@ -0,0 +1,23 @@ +-- insert team_integrations overwriting conflicts +CREATE TEMPORARY TABLE sync_team_integrations ( + id serial, + team_id integer, + staging_bops_submission_url text +); + +\ COPY sync_team_integrations +FROM + '/tmp/team_integrations.csv' WITH (FORMAT csv, DELIMITER ';'); + +INSERT INTO + team_integrations (id, team_id, staging_bops_submission_url) +SELECT + id, + team_id, + staging_bops_submission_url +FROM + sync_team_integrations ON CONFLICT (id) DO +UPDATE +SET + team_id = EXCLUDED.team_id, + staging_bops_submission_url = EXCLUDED.staging_bops_submission_url; \ No newline at end of file