From a012c0a458f9f0cb17e582ef4881b92e747e13a5 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 4 Sep 2023 12:00:58 +0200 Subject: [PATCH 1/5] Add back base default legacy views permissions --- packages/backend-core/src/security/permissions.ts | 3 +++ packages/server/src/utilities/security.ts | 3 +++ packages/types/src/sdk/permissions.ts | 1 + 3 files changed, 7 insertions(+) diff --git a/packages/backend-core/src/security/permissions.ts b/packages/backend-core/src/security/permissions.ts index aa0b20a30c..13083534b1 100644 --- a/packages/backend-core/src/security/permissions.ts +++ b/packages/backend-core/src/security/permissions.ts @@ -87,6 +87,7 @@ export const BUILTIN_PERMISSIONS = { new Permission(PermissionType.QUERY, PermissionLevel.WRITE), new Permission(PermissionType.TABLE, PermissionLevel.WRITE), new Permission(PermissionType.AUTOMATION, PermissionLevel.EXECUTE), + new Permission(PermissionType.LEGACY_VIEW, PermissionLevel.READ), ], }, POWER: { @@ -97,6 +98,7 @@ export const BUILTIN_PERMISSIONS = { new Permission(PermissionType.USER, PermissionLevel.READ), new Permission(PermissionType.AUTOMATION, PermissionLevel.EXECUTE), new Permission(PermissionType.WEBHOOK, PermissionLevel.READ), + new Permission(PermissionType.LEGACY_VIEW, PermissionLevel.READ), ], }, ADMIN: { @@ -108,6 +110,7 @@ export const BUILTIN_PERMISSIONS = { new Permission(PermissionType.AUTOMATION, PermissionLevel.ADMIN), new Permission(PermissionType.WEBHOOK, PermissionLevel.READ), new Permission(PermissionType.QUERY, PermissionLevel.ADMIN), + new Permission(PermissionType.LEGACY_VIEW, PermissionLevel.READ), ], }, } diff --git a/packages/server/src/utilities/security.ts b/packages/server/src/utilities/security.ts index 0da7621773..01a3468c9c 100644 --- a/packages/server/src/utilities/security.ts +++ b/packages/server/src/utilities/security.ts @@ -23,6 +23,9 @@ export function getPermissionType(resourceId: string) { case DocumentType.QUERY: case DocumentType.DATASOURCE: return permissions.PermissionType.QUERY + default: + // legacy views don't have an ID, will end up here + return permissions.PermissionType.LEGACY_VIEW } } diff --git a/packages/types/src/sdk/permissions.ts b/packages/types/src/sdk/permissions.ts index a33d4985ee..a3bbaa1b48 100644 --- a/packages/types/src/sdk/permissions.ts +++ b/packages/types/src/sdk/permissions.ts @@ -16,4 +16,5 @@ export enum PermissionType { GLOBAL_BUILDER = "globalBuilder", QUERY = "query", VIEW = "view", + LEGACY_VIEW = "legacy_view", } From 8b5700774b635066e79aa1129f4cfdab503bf731 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 4 Sep 2023 12:16:44 +0200 Subject: [PATCH 2/5] Add test --- .../server/src/api/routes/tests/permissions.spec.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/server/src/api/routes/tests/permissions.spec.ts b/packages/server/src/api/routes/tests/permissions.spec.ts index 3fa21cb677..f03f84f466 100644 --- a/packages/server/src/api/routes/tests/permissions.spec.ts +++ b/packages/server/src/api/routes/tests/permissions.spec.ts @@ -260,4 +260,16 @@ describe("/permission", () => { expect(publicPerm.name).toBeDefined() }) }) + + describe("default permissions", () => { + it("legacy views", async () => { + const legacyView = await config.createView() + + const res = await config.api.permission.get(legacyView.name) + + expect(res.body).toBe({ + read: "BASIC", + }) + }) + }) }) From 900c773ce91fdf6e1e2b0a7df8426c84ce22f61d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 4 Sep 2023 12:17:37 +0200 Subject: [PATCH 3/5] Renamings --- packages/server/src/api/routes/tests/permissions.spec.ts | 4 ++-- packages/server/src/api/routes/tests/row.spec.ts | 2 +- packages/server/src/api/routes/tests/table.spec.ts | 4 ++-- packages/server/src/api/routes/tests/viewV2.spec.ts | 2 +- packages/server/src/migrations/tests/index.spec.ts | 4 ++-- packages/server/src/tests/utilities/TestConfiguration.ts | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/server/src/api/routes/tests/permissions.spec.ts b/packages/server/src/api/routes/tests/permissions.spec.ts index f03f84f466..e0ec27949f 100644 --- a/packages/server/src/api/routes/tests/permissions.spec.ts +++ b/packages/server/src/api/routes/tests/permissions.spec.ts @@ -263,11 +263,11 @@ describe("/permission", () => { describe("default permissions", () => { it("legacy views", async () => { - const legacyView = await config.createView() + const legacyView = await config.createLegacyView() const res = await config.api.permission.get(legacyView.name) - expect(res.body).toBe({ + expect(res.body).toEqual({ read: "BASIC", }) }) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index f28b96b9d8..f7878b2182 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -670,7 +670,7 @@ describe("/rows", () => { }) it("should be able to run on a view", async () => { - const view = await config.createView() + const view = await config.createLegacyView() const row = await config.createRow() const rowUsage = await getRowUsage() const queryUsage = await getQueryUsage() diff --git a/packages/server/src/api/routes/tests/table.spec.ts b/packages/server/src/api/routes/tests/table.spec.ts index 04911e5505..9914e6d66f 100644 --- a/packages/server/src/api/routes/tests/table.spec.ts +++ b/packages/server/src/api/routes/tests/table.spec.ts @@ -87,7 +87,7 @@ describe("/tables", () => { it("updates all the row fields for a table when a schema key is renamed", async () => { const testTable = await config.createTable() - await config.createView({ + await config.createLegacyView({ name: "TestView", field: "Price", calculation: "stats", @@ -254,7 +254,7 @@ describe("/tables", () => { })) await config.api.viewV2.create({ tableId }) - await config.createView({ tableId, name: generator.guid() }) + await config.createLegacyView({ tableId, name: generator.guid() }) const res = await config.api.table.fetch() diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index a9c9f3a320..5e8ae09e55 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -296,7 +296,7 @@ describe.each([ }) it("cannot update views v1", async () => { - const viewV1 = await config.createView() + const viewV1 = await config.createLegacyView() await config.api.viewV2.update( { ...viewV1, diff --git a/packages/server/src/migrations/tests/index.spec.ts b/packages/server/src/migrations/tests/index.spec.ts index 2465c930b4..b64cad26c1 100644 --- a/packages/server/src/migrations/tests/index.spec.ts +++ b/packages/server/src/migrations/tests/index.spec.ts @@ -50,9 +50,9 @@ describe("migrations", () => { await config.createRole() await config.createRole() await config.createTable() - await config.createView() + await config.createLegacyView() await config.createTable() - await config.createView(structures.view(config.table!._id!)) + await config.createLegacyView(structures.view(config.table!._id!)) await config.createScreen() await config.createScreen() diff --git a/packages/server/src/tests/utilities/TestConfiguration.ts b/packages/server/src/tests/utilities/TestConfiguration.ts index c1db54fe60..81bfa0abbd 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.ts +++ b/packages/server/src/tests/utilities/TestConfiguration.ts @@ -622,7 +622,7 @@ class TestConfiguration { // VIEW - async createView(config?: any) { + async createLegacyView(config?: any) { if (!this.table) { throw "Test requires table to be configured." } From 5429c0374192a4a6635e06c9da0ba42079a7eb91 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 4 Sep 2023 12:28:10 +0200 Subject: [PATCH 4/5] Fix renamings --- packages/server/src/api/routes/tests/view.spec.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/server/src/api/routes/tests/view.spec.js b/packages/server/src/api/routes/tests/view.spec.js index df07ffa4af..e633279058 100644 --- a/packages/server/src/api/routes/tests/view.spec.js +++ b/packages/server/src/api/routes/tests/view.spec.js @@ -249,7 +249,7 @@ describe("/views", () => { }) it("returns only custom views", async () => { - await config.createView({ + await config.createLegacyView({ name: "TestView", field: "Price", calculation: "stats", @@ -267,7 +267,7 @@ describe("/views", () => { describe("query", () => { it("returns data for the created view", async () => { - await config.createView({ + await config.createLegacyView({ name: "TestView", field: "Price", calculation: "stats", @@ -295,7 +295,7 @@ describe("/views", () => { }) it("returns data for the created view using a group by", async () => { - await config.createView({ + await config.createLegacyView({ calculation: "stats", name: "TestView", field: "Price", @@ -331,7 +331,7 @@ describe("/views", () => { describe("destroy", () => { it("should be able to delete a view", async () => { const table = await config.createTable(priceTable()) - const view = await config.createView() + const view = await config.createLegacyView() const res = await request .delete(`/api/views/${view.name}`) .set(config.defaultHeaders()) @@ -395,7 +395,7 @@ describe("/views", () => { it("should be able to export a view as JSON", async () => { let table = await setupExport() - const view = await config.createView() + const view = await config.createLegacyView() table = await config.getTable(table._id) let res = await exportView(view.name, "json") @@ -407,7 +407,7 @@ describe("/views", () => { it("should be able to export a view as CSV", async () => { let table = await setupExport() - const view = await config.createView() + const view = await config.createLegacyView() table = await config.getTable(table._id) let res = await exportView(view.name, "csv") From f6e5e9ad6b56675f32270c224814ccc866a8f45a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 4 Sep 2023 12:35:35 +0200 Subject: [PATCH 5/5] Fix test after rebase --- packages/server/src/api/routes/tests/permissions.spec.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/routes/tests/permissions.spec.ts b/packages/server/src/api/routes/tests/permissions.spec.ts index 36b27cd87d..129bc00b44 100644 --- a/packages/server/src/api/routes/tests/permissions.spec.ts +++ b/packages/server/src/api/routes/tests/permissions.spec.ts @@ -278,7 +278,12 @@ describe("/permission", () => { const res = await config.api.permission.get(legacyView.name) expect(res.body).toEqual({ - read: "BASIC", + permissions: { + read: { + permissionType: "BASE", + role: "BASIC", + }, + }, }) }) })