From fef5c2a003125830a9e183666122f829afbcf86e Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 5 Sep 2023 15:37:18 +0100 Subject: [PATCH 1/4] Quick fix for relationship toast. --- .../backend/Datasources/CreateEditRelationship.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte index 36c6a32801..9c98bdc2e5 100644 --- a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte @@ -290,11 +290,11 @@ datasource.entities[getTable(toId).name].schema[toRelationship.name] = toRelationship - await save() + await save({ action: "saved" }) } async function deleteRelationship() { removeExistingRelationship() - await save() + await save({ action: "deleted" }) await tables.fetch() close() } From ad46ff6f8c7cc3cac93b4f00818d81a96e1b0afb Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 5 Sep 2023 19:33:43 +0100 Subject: [PATCH 2/4] Updating to accept action as an object specifier. --- .../backend/Datasources/CreateEditRelationshipModal.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/backend/Datasources/CreateEditRelationshipModal.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationshipModal.svelte index 03683bcfc9..0dfb4ca796 100644 --- a/packages/builder/src/components/backend/Datasources/CreateEditRelationshipModal.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationshipModal.svelte @@ -33,7 +33,7 @@ } // action is one of 'created', 'updated' or 'deleted' - async function saveRelationship(action) { + async function saveRelationship({ action }) { try { await beforeSave({ action, datasource }) From 0cd05a4adf1bcf1e44afd8393c32e67a3cad28e8 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 5 Sep 2023 19:58:03 +0100 Subject: [PATCH 3/4] Quick fix issue integration tests have displayed, retrieving users through the public API was broken due to a lack of app ID in context. --- .../backend-core/src/context/mainContext.ts | 5 +++++ .../server/src/sdk/app/permissions/index.ts | 20 ++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/backend-core/src/context/mainContext.ts b/packages/backend-core/src/context/mainContext.ts index 61d96bb4b0..f85b757e83 100644 --- a/packages/backend-core/src/context/mainContext.ts +++ b/packages/backend-core/src/context/mainContext.ts @@ -208,6 +208,11 @@ export function getAutomationId(): string | undefined { return context?.automationId } +export function hasAppId(): boolean { + const appId = getAppId() + return !!appId +} + export function getAppId(): string | undefined { const context = Context.get() const foundId = context?.appId diff --git a/packages/server/src/sdk/app/permissions/index.ts b/packages/server/src/sdk/app/permissions/index.ts index 53f6756ae1..1c3f4f0fbd 100644 --- a/packages/server/src/sdk/app/permissions/index.ts +++ b/packages/server/src/sdk/app/permissions/index.ts @@ -84,13 +84,16 @@ export async function allowsExplicitPermissions(resourceId: string) { export async function getResourcePerms( resourceId: string ): Promise { - const db = context.getAppDB() - const body = await db.allDocs( - getRoleParams(null, { - include_docs: true, - }) - ) - const rolesList = body.rows.map(row => row.doc) + let rolesList: Role[] = [] + if (context.hasAppId()) { + const db = context.getAppDB() + const body = await db.allDocs( + getRoleParams(null, { + include_docs: true, + }) + ) + rolesList = body.rows.map(row => row.doc) + } let permissions: ResourcePermissions = {} const permsToInherit = await getInheritablePermissions(resourceId) @@ -128,8 +131,7 @@ export async function getResourcePerms( p[level] = { role, type: PermissionSource.BASE } return p }, {}) - const result = Object.assign(basePermissions, permissions) - return result + return Object.assign(basePermissions, permissions) } export async function getDependantResources( From 9c32f278b7671cdaba51bc1e52f293d7d2829235 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 6 Sep 2023 10:09:45 +0100 Subject: [PATCH 4/4] Revert "Quick fix issue integration tests have displayed, retrieving users through the public API was broken due to a lack of app ID in context." This reverts commit 0cd05a4adf1bcf1e44afd8393c32e67a3cad28e8. --- .../backend-core/src/context/mainContext.ts | 5 ----- .../server/src/sdk/app/permissions/index.ts | 20 +++++++++---------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/packages/backend-core/src/context/mainContext.ts b/packages/backend-core/src/context/mainContext.ts index f85b757e83..61d96bb4b0 100644 --- a/packages/backend-core/src/context/mainContext.ts +++ b/packages/backend-core/src/context/mainContext.ts @@ -208,11 +208,6 @@ export function getAutomationId(): string | undefined { return context?.automationId } -export function hasAppId(): boolean { - const appId = getAppId() - return !!appId -} - export function getAppId(): string | undefined { const context = Context.get() const foundId = context?.appId diff --git a/packages/server/src/sdk/app/permissions/index.ts b/packages/server/src/sdk/app/permissions/index.ts index 1c3f4f0fbd..53f6756ae1 100644 --- a/packages/server/src/sdk/app/permissions/index.ts +++ b/packages/server/src/sdk/app/permissions/index.ts @@ -84,16 +84,13 @@ export async function allowsExplicitPermissions(resourceId: string) { export async function getResourcePerms( resourceId: string ): Promise { - let rolesList: Role[] = [] - if (context.hasAppId()) { - const db = context.getAppDB() - const body = await db.allDocs( - getRoleParams(null, { - include_docs: true, - }) - ) - rolesList = body.rows.map(row => row.doc) - } + const db = context.getAppDB() + const body = await db.allDocs( + getRoleParams(null, { + include_docs: true, + }) + ) + const rolesList = body.rows.map(row => row.doc) let permissions: ResourcePermissions = {} const permsToInherit = await getInheritablePermissions(resourceId) @@ -131,7 +128,8 @@ export async function getResourcePerms( p[level] = { role, type: PermissionSource.BASE } return p }, {}) - return Object.assign(basePermissions, permissions) + const result = Object.assign(basePermissions, permissions) + return result } export async function getDependantResources(