Skip to content

Commit

Permalink
feat: add demoUser role to Hasura with permissions (#3852)
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 authored Oct 28, 2024
1 parent 4f7c9c6 commit 23d05a0
Show file tree
Hide file tree
Showing 27 changed files with 1,138 additions and 365 deletions.
338 changes: 303 additions & 35 deletions hasura.planx.uk/metadata/tables.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM "public"."user_roles" WHERE "value" = 'demoUser';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO "public"."user_roles"("value") VALUES (E'demoUser');
15 changes: 15 additions & 0 deletions hasura.planx.uk/tests/analytics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ describe("analytics and analytics_logs", () => {
});
});

describe("demoUser", () => {
let i;
beforeAll(async () => {
i = await introspectAs("demoUser");
});

test("cannot query analytics_logs", () => {
expect(i.queries).not.toContain("analytics_logs");
});

test("cannot create, update, or delete analytics_logs", () => {
expect(i).toHaveNoMutationsFor("analytics_logs");
});
});

describe("api", () => {
beforeAll(async () => {
i = await introspectAs("api");
Expand Down
15 changes: 15 additions & 0 deletions hasura.planx.uk/tests/blpu_codes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ describe("blpu_codes", () => {
});
});

describe("demoUser", () => {
let i;
beforeAll(async () => {
i = await introspectAs("demoUser");
});

test("can query blpu_codes", () => {
expect(i.queries).not.toContain("blpu_codes");
});

test("cannot create, update, or delete blpu_codes", () => {
expect(i).toHaveNoMutationsFor("blpu_codes");
});
});

describe("api", () => {
let i;
beforeAll(async () => {
Expand Down
15 changes: 15 additions & 0 deletions hasura.planx.uk/tests/bops_applications.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ describe("bops_applications", () => {
});
});

describe("demoUser", () => {
let i;
beforeAll(async () => {
i = await introspectAs("demoUser");
});

test("cannot query bops applications", () => {
expect(i.queries).not.toContain("bops_applications");
});

test("cannot create, update, or delete bops applications", () => {
expect(i).toHaveNoMutationsFor("bops_applications");
});
});

describe("api", () => {
let i;
beforeAll(async () => {
Expand Down
15 changes: 15 additions & 0 deletions hasura.planx.uk/tests/email_applications.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ describe("email_applications", () => {
expect(i).toHaveNoMutationsFor("email_applications");
});
});

describe("demoUser", () => {
let i;
beforeAll(async () => {
i = await introspectAs("demoUser");
});

test("cannot query email_applications", () => {
expect(i.queries).not.toContain("email_applications");
});

test("cannot create, update, or delete email_applications", () => {
expect(i).toHaveNoMutationsFor("email_applications");
});
});

describe("api", () => {
let i;
Expand Down
65 changes: 39 additions & 26 deletions hasura.planx.uk/tests/feedback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ describe("feedback", () => {
});

test("cannot query feedback", () => {
expect(i.queries).not.toContain("feedback");
});
test("cannot update feedback", () => {
expect(i.mutations).not.toContain("update_feedback");
expect(i.mutations).not.toContain("update_feedback_by_pk");
});
test("cannot delete feedback", async () => {
expect(i.mutations).not.toContain("delete_feedback");
});
test("can insert feedback", async () => {
expect(i.mutations).toContain("insert_feedback");
});
expect(i.queries).not.toContain("feedback");
});

test("cannot update feedback", () => {
expect(i.mutations).not.toContain("update_feedback");
expect(i.mutations).not.toContain("update_feedback_by_pk");
});

test("cannot delete feedback", async () => {
expect(i.mutations).not.toContain("delete_feedback");
});

test("can insert feedback", async () => {
expect(i.mutations).toContain("insert_feedback");
});
});

describe("admin", () => {
Expand All @@ -32,13 +32,13 @@ describe("feedback", () => {
});

test("has full access to query and mutate feedback", () => {
expect(i.mutations).toContain("insert_feedback");
expect(i.mutations).toContain("insert_feedback_one");
expect(i.mutations).toContain("update_feedback");
expect(i.mutations).toContain("update_feedback_by_pk");
expect(i.mutations).toContain("update_feedback_many");
expect(i.mutations).toContain("delete_feedback");
expect(i.mutations).toContain("delete_feedback_by_pk");
expect(i.mutations).toContain("insert_feedback");
expect(i.mutations).toContain("insert_feedback_one");
expect(i.mutations).toContain("update_feedback");
expect(i.mutations).toContain("update_feedback_by_pk");
expect(i.mutations).toContain("update_feedback_many");
expect(i.mutations).toContain("delete_feedback");
expect(i.mutations).toContain("delete_feedback_by_pk");
});
});

Expand All @@ -50,11 +50,10 @@ describe("feedback", () => {

test("cannot query feedback", () => {
expect(i.queries).not.toContain("feedback");

});

test("cannot mutate feedback", async () => {
expect(i).toHaveNoMutationsFor("feedback")
expect(i).toHaveNoMutationsFor("feedback");
});
});

Expand All @@ -66,11 +65,25 @@ describe("feedback", () => {

test("cannot query feedback", () => {
expect(i.queries).not.toContain("feedback");
});

test("cannot mutate feedback", async () => {
expect(i).toHaveNoMutationsFor("feedback");
});
});

describe("demoUser", () => {
let i;
beforeAll(async () => {
i = await introspectAs("demoUser");
});

test("cannot query feedback", () => {
expect(i.queries).not.toContain("feedback");
});

test("cannot mutate feedback", async () => {
expect(i).toHaveNoMutationsFor("feedback")
expect(i).toHaveNoMutationsFor("feedback");
});
});

Expand All @@ -92,7 +105,7 @@ describe("feedback", () => {
test("can delete feedback", async () => {
expect(i.mutations).toContain("delete_feedback");
});

test("cannot insert feedback", async () => {
expect(i.mutations).not.toContain("insert_feedback");
});
Expand Down
193 changes: 104 additions & 89 deletions hasura.planx.uk/tests/feedback_status.test.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,107 @@
const { introspectAs } = require("./utils");

describe("feedback_status_enum", () => {
describe("public", () => {
let i;
beforeAll(async () => {
i = await introspectAs("public");
});

test("cannot INSERT records", () => {
expect(i.mutations).not.toContain("insert_feedback_status_enum");
});

test("cannot QUERY records", () => {
expect(i.queries).not.toContain("feedback_status_enum");
});

test("cannot DELETE records", () => {
expect(i.mutations).not.toContain("delete_feedback_status_enum");
});

test("cannot UPDATE records", () => {
expect(i.mutations).not.toContain("update_feedback_status_enum");
});
});

describe("admin", () => {
let i;
beforeAll(async () => {
i = await introspectAs("admin");
});

test("has full access to query and mutate feedback_status_enum", async () => {
expect(i.queries).toContain("feedback_status_enum");
expect(i.mutations).toContain("insert_feedback_status_enum");
expect(i.mutations).toContain("delete_feedback_status_enum");
});
});

describe("platformAdmin", () => {
let i;
beforeAll(async () => {
i = await introspectAs("platformAdmin");
});

test("cannot query feedback_status_enum", () => {
expect(i.queries).not.toContain("feedback_status_enum");
});

test("cannot create, update, or delete feedback_status_enum", () => {
expect(i).toHaveNoMutationsFor("feedback_status_enum");
});
});

describe("teamEditor", () => {
let i;
beforeAll(async () => {
i = await introspectAs("teamEditor");
});

test("cannot query feedback_status_enum", () => {
expect(i.queries).not.toContain("feedback_status_enum");
});

test("cannot create, update, or delete feedback_status_enum", () => {
expect(i).toHaveNoMutationsFor("feedback_status_enum");
});
});

describe("api", () => {
let i;
beforeAll(async () => {
i = await introspectAs("api");
});

test("cannot INSERT records", () => {
expect(i.mutations).not.toContain("insert_feedback_status_enum");
});

test("cannot QUERY records", () => {
expect(i.queries).not.toContain("feedback_status_enum");
});

test("cannot DELETE records", () => {
expect(i.mutations).not.toContain("delete_feedback_status_enum");
});

test("cannot UPDATE records", () => {
expect(i.mutations).not.toContain("update_feedback_status_enum");
});
});
});
describe("public", () => {
let i;
beforeAll(async () => {
i = await introspectAs("public");
});

test("cannot INSERT records", () => {
expect(i.mutations).not.toContain("insert_feedback_status_enum");
});

test("cannot QUERY records", () => {
expect(i.queries).not.toContain("feedback_status_enum");
});

test("cannot DELETE records", () => {
expect(i.mutations).not.toContain("delete_feedback_status_enum");
});

test("cannot UPDATE records", () => {
expect(i.mutations).not.toContain("update_feedback_status_enum");
});
});

describe("admin", () => {
let i;
beforeAll(async () => {
i = await introspectAs("admin");
});

test("has full access to query and mutate feedback_status_enum", async () => {
expect(i.queries).toContain("feedback_status_enum");
expect(i.mutations).toContain("insert_feedback_status_enum");
expect(i.mutations).toContain("delete_feedback_status_enum");
});
});

describe("platformAdmin", () => {
let i;
beforeAll(async () => {
i = await introspectAs("platformAdmin");
});

test("cannot query feedback_status_enum", () => {
expect(i.queries).not.toContain("feedback_status_enum");
});

test("cannot create, update, or delete feedback_status_enum", () => {
expect(i).toHaveNoMutationsFor("feedback_status_enum");
});
});

describe("teamEditor", () => {
let i;
beforeAll(async () => {
i = await introspectAs("teamEditor");
});

test("cannot query feedback_status_enum", () => {
expect(i.queries).not.toContain("feedback_status_enum");
});

test("cannot create, update, or delete feedback_status_enum", () => {
expect(i).toHaveNoMutationsFor("feedback_status_enum");
});
});

describe("demoUser", () => {
let i;
beforeAll(async () => {
i = await introspectAs("demoUser");
});

test("cannot query feedback_status_enum", () => {
expect(i.queries).not.toContain("feedback_status_enum");
});

test("cannot create, update, or delete feedback_status_enum", () => {
expect(i).toHaveNoMutationsFor("feedback_status_enum");
});
});

describe("api", () => {
let i;
beforeAll(async () => {
i = await introspectAs("api");
});

test("cannot INSERT records", () => {
expect(i.mutations).not.toContain("insert_feedback_status_enum");
});

test("cannot QUERY records", () => {
expect(i.queries).not.toContain("feedback_status_enum");
});

test("cannot DELETE records", () => {
expect(i.mutations).not.toContain("delete_feedback_status_enum");
});

test("cannot UPDATE records", () => {
expect(i.mutations).not.toContain("update_feedback_status_enum");
});
});
});
Loading

0 comments on commit 23d05a0

Please sign in to comment.