From 190e29e043f36dbcc11a3b4d357a2ca4f350612a Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 4 Sep 2023 09:36:48 +0100 Subject: [PATCH 1/8] fix issue with counting of groups and apps --- .../src/pages/builder/portal/users/groups/[groupId].svelte | 4 ++-- .../portal/users/users/_components/AppsTableRenderer.svelte | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/users/groups/[groupId].svelte b/packages/builder/src/pages/builder/portal/users/groups/[groupId].svelte index 793ba5c09f..4c1bb661fd 100644 --- a/packages/builder/src/pages/builder/portal/users/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/users/groups/[groupId].svelte @@ -46,7 +46,7 @@ let loaded = false let editModal, deleteModal - $: console.log(group) + $: scimEnabled = $features.isScimEnabled $: readonly = !sdk.users.isAdmin($auth.user) || scimEnabled $: group = $groups.find(x => x._id === groupId) @@ -62,7 +62,7 @@ ? Constants.Roles.CREATOR : group?.roles?.[apps.getProdAppID(app.devId)], })) - $: console.log(groupApps) + $: { if (loaded && !group?._id) { $goto("./") diff --git a/packages/builder/src/pages/builder/portal/users/users/_components/AppsTableRenderer.svelte b/packages/builder/src/pages/builder/portal/users/users/_components/AppsTableRenderer.svelte index b7bb810aba..9dda0dbab2 100644 --- a/packages/builder/src/pages/builder/portal/users/users/_components/AppsTableRenderer.svelte +++ b/packages/builder/src/pages/builder/portal/users/users/_components/AppsTableRenderer.svelte @@ -5,7 +5,6 @@ export let value export let row - $: console.log(row) $: priviliged = sdk.users.isAdminOrBuilder(row) $: count = getCount(row) From 24abd91600d4bf963874f3de62cb98de0e265421 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 4 Sep 2023 09:37:10 +0100 Subject: [PATCH 2/8] Fix issue around adding of admin users --- .../_components/BuilderSidePanel.svelte | 42 ++++++++++++++----- packages/frontend-core/src/api/user.js | 3 ++ .../src/api/controllers/global/users.ts | 11 +++-- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index 3e6741e920..477083f822 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -366,18 +366,21 @@ const payload = [ { email: newUserEmail, - builder: !!creationRoleType === Constants.BudibaseRoles.Admin, - admin: !!creationRoleType === Constants.BudibaseRoles.Admin, + builder: creationRoleType === Constants.BudibaseRoles.Admin, + admin: creationRoleType === Constants.BudibaseRoles.Admin, }, ] - if (creationAccessType === Constants.Roles.CREATOR) { - payload[0].appBuilders = [prodAppId] - } else { - payload[0].apps = { - [prodAppId]: creationAccessType, + if (creationRoleType !== Constants.BudibaseRoles.Admin) { + if (creationAccessType === Constants.Roles.CREATOR) { + payload[0].appBuilders = [prodAppId] + } else { + payload[0].apps = { + [prodAppId]: creationAccessType, + } } } + let userInviteResponse try { userInviteResponse = await users.onboard(payload) @@ -494,6 +497,18 @@ } } + const getInviteRoleValue = invite => { + if (invite.info?.admin?.global && invite.info?.builder?.global) { + return Constants.Roles.ADMIN + } + + if (invite.info?.appBuilders?.includes(prodAppId)) { + return Constants.Roles.CREATOR + } + + return invite.info.apps?.[prodAppId] + } + const getRoleFooter = user => { if (user.group) { const role = $roles.find(role => role._id === user.role) @@ -600,6 +615,11 @@
Access
{#each filteredInvites as invite} + {@const user = { + isAdminOrGlobalBuilder: + invite.info?.admin?.global && invite.info?.builder?.global, + }} +
@@ -608,10 +628,9 @@
diff --git a/packages/frontend-core/src/api/user.js b/packages/frontend-core/src/api/user.js index 329e9cc499..98c2bc598a 100644 --- a/packages/frontend-core/src/api/user.js +++ b/packages/frontend-core/src/api/user.js @@ -153,10 +153,13 @@ export const buildUserEndpoints = API => ({ }, onboardUsers: async payload => { + console.log(payload) return await API.post({ url: "/api/global/users/onboard", body: payload.map(invite => { const { email, admin, builder, apps, appBuilders } = invite + console.log(admin) + console.log(builder) return { email, userInfo: { diff --git a/packages/worker/src/api/controllers/global/users.ts b/packages/worker/src/api/controllers/global/users.ts index 0ccf9a356f..eb14c13119 100644 --- a/packages/worker/src/api/controllers/global/users.ts +++ b/packages/worker/src/api/controllers/global/users.ts @@ -266,7 +266,9 @@ export const onboardUsers = async (ctx: Ctx) => { // Temp password to be passed to the user. createdPasswords[invite.email] = password - let builder: { global: boolean; apps?: string[] } = { global: false } + let builder: { global: boolean; apps?: string[] } = { + global: invite.userInfo.builder || false, + } if (invite.userInfo.appBuilders) { builder.apps = invite.userInfo.appBuilders } @@ -275,7 +277,7 @@ export const onboardUsers = async (ctx: Ctx) => { password, forceResetPassword: true, roles: invite.userInfo.apps, - admin: { global: false }, + admin: { global: invite.userInfo.admin || false }, builder, tenantId: tenancy.getTenantId(), } @@ -409,10 +411,13 @@ export const inviteAccept = async ( lastName, password, email, + admin: { global: info.admin || false }, roles: info.apps, tenantId: info.tenantId, } - let builder: { global: boolean; apps?: string[] } = { global: false } + let builder: { global: boolean; apps?: string[] } = { + global: info.builder || false, + } if (info.appBuilders) { builder.apps = info.appBuilders From 6d3a7727ebb5ca18024d07fd6892d7ecbd58e029 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 5 Sep 2023 09:25:06 +0100 Subject: [PATCH 3/8] fixes for perr app builder and refactoring based on comments --- .../_components/BuilderSidePanel.svelte | 28 ++++++++-------- packages/frontend-core/src/api/user.js | 17 ++++------ .../src/api/controllers/global/users.ts | 32 +++++++------------ 3 files changed, 32 insertions(+), 45 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index 477083f822..b0ab9edd04 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -150,13 +150,10 @@ } const sortInviteRoles = (a, b) => { - const aEmpty = - !a.info?.appBuilders?.length && Object.keys(a.info.apps).length === 0 - const bEmpty = - !b.info?.appBuilders?.length && Object.keys(b.info.apps).length === 0 + const aAppsEmpty = !a.info?.apps?.length && !a.info?.builder?.apps?.length + const bAppsEmpty = !b.info?.apps?.length && !b.info?.builder?.apps?.length - if (aEmpty && !bEmpty) return 1 - if (!aEmpty && bEmpty) return -1 + return aAppsEmpty && !bAppsEmpty ? 1 : !aAppsEmpty && bAppsEmpty ? -1 : 0 } const sortRoles = (a, b) => { @@ -366,14 +363,14 @@ const payload = [ { email: newUserEmail, - builder: creationRoleType === Constants.BudibaseRoles.Admin, - admin: creationRoleType === Constants.BudibaseRoles.Admin, + builder: { global: creationRoleType === Constants.BudibaseRoles.Admin }, + admin: { global: creationRoleType === Constants.BudibaseRoles.Admin }, }, ] if (creationRoleType !== Constants.BudibaseRoles.Admin) { if (creationAccessType === Constants.Roles.CREATOR) { - payload[0].appBuilders = [prodAppId] + payload[0].builder.apps = [prodAppId] } else { payload[0].apps = { [prodAppId]: creationAccessType, @@ -441,10 +438,11 @@ } if (role === Constants.Roles.CREATOR) { - updateBody.appBuilders = [...(updateBody.appBuilders ?? []), prodAppId] + updateBody.builder = updateBody.builder || {} + updateBody.builder.apps = [...(updateBody.builder.apps ?? []), prodAppId] delete updateBody?.apps?.[prodAppId] - } else if (role !== Constants.Roles.CREATOR && invite?.appBuilders) { - invite.appBuilders = [] + } else if (role !== Constants.Roles.CREATOR && invite?.builder?.apps) { + invite.builder.apps = [] } await users.updateInvite(updateBody) await filterInvites(query) @@ -502,7 +500,7 @@ return Constants.Roles.ADMIN } - if (invite.info?.appBuilders?.includes(prodAppId)) { + if (invite.info?.builder?.apps?.includes(prodAppId)) { return Constants.Roles.CREATOR } @@ -546,7 +544,9 @@ {invitingFlow ? "Invite new user" : "Users"}
- + {#if !invitingFlow} + + {/if} ({ body: { email, userInfo: { - admin: admin ? { global: true } : undefined, - builder: builder ? { global: true } : undefined, + admin: admin?.global ? { global: true } : undefined, + builder: builder?.global ? { global: true } : undefined, apps: apps ? apps : undefined, }, }, @@ -153,20 +153,16 @@ export const buildUserEndpoints = API => ({ }, onboardUsers: async payload => { - console.log(payload) return await API.post({ url: "/api/global/users/onboard", body: payload.map(invite => { - const { email, admin, builder, apps, appBuilders } = invite - console.log(admin) - console.log(builder) + const { email, admin, builder, apps } = invite return { email, userInfo: { - admin: admin ? { global: true } : undefined, - builder: builder ? { global: true } : undefined, + admin, + builder, apps: apps ? apps : undefined, - appBuilders, }, } }), @@ -179,12 +175,11 @@ export const buildUserEndpoints = API => ({ * @param invite the invite code sent in the email */ updateUserInvite: async invite => { - console.log(invite) await API.post({ url: `/api/global/users/invite/update/${invite.code}`, body: { apps: invite.apps, - appBuilders: invite.appBuilders, + builder: invite.builder, }, }) }, diff --git a/packages/worker/src/api/controllers/global/users.ts b/packages/worker/src/api/controllers/global/users.ts index eb14c13119..a084685dd3 100644 --- a/packages/worker/src/api/controllers/global/users.ts +++ b/packages/worker/src/api/controllers/global/users.ts @@ -266,19 +266,14 @@ export const onboardUsers = async (ctx: Ctx) => { // Temp password to be passed to the user. createdPasswords[invite.email] = password - let builder: { global: boolean; apps?: string[] } = { - global: invite.userInfo.builder || false, - } - if (invite.userInfo.appBuilders) { - builder.apps = invite.userInfo.appBuilders - } + return { email: invite.email, password, forceResetPassword: true, roles: invite.userInfo.apps, - admin: { global: invite.userInfo.admin || false }, - builder, + admin: invite.userInfo.admin, + builder: invite.userInfo.builder, tenantId: tenancy.getTenantId(), } }) @@ -373,13 +368,10 @@ export const updateInvite = async (ctx: any) => { ...invite, } - if (!updateBody?.appBuilders || !updateBody.appBuilders?.length) { - updated.info.appBuilders = [] - } else { - updated.info.appBuilders = [ - ...(invite.info.appBuilders ?? []), - ...updateBody.appBuilders, - ] + if (!updateBody?.builder?.apps && updated.info?.builder?.apps) { + updated.info.builder.apps = [] + } else if (updateBody?.builder) { + updated.info.builder = updateBody.builder } if (!updateBody?.apps || !Object.keys(updateBody?.apps).length) { @@ -411,18 +403,18 @@ export const inviteAccept = async ( lastName, password, email, - admin: { global: info.admin || false }, + admin: { global: info.admin.global || false }, roles: info.apps, tenantId: info.tenantId, } let builder: { global: boolean; apps?: string[] } = { - global: info.builder || false, + global: info.builder.global || false, } - if (info.appBuilders) { - builder.apps = info.appBuilders + if (info.builder.apps) { + builder.apps = info.builder.apps request.builder = builder - delete info.appBuilders + delete info.builder.apps } delete info.apps request = { From c16fd53b0a954f8d08d74fb8464f68c02fcb302b Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 5 Sep 2023 09:58:05 +0100 Subject: [PATCH 4/8] add developer label back and improve invite flow --- .../app/[application]/_components/BuilderSidePanel.svelte | 2 +- .../users/users/_components/RoleTableRenderer.svelte | 2 +- packages/builder/src/stores/portal/users.js | 7 +++++-- packages/frontend-core/src/constants.js | 5 +++++ packages/worker/src/api/controllers/global/users.ts | 6 +++--- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index b0ab9edd04..5f89762eac 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -120,7 +120,7 @@ await usersFetch.refresh() filteredUsers = $usersFetch.rows - .filter(user => !user?.admin?.global) // filter out global admins + .filter(user => user.email !== $auth.user.email) .map(user => { const isAdminOrGlobalBuilder = sdk.users.isAdminOrGlobalBuilder( user, diff --git a/packages/builder/src/pages/builder/portal/users/users/_components/RoleTableRenderer.svelte b/packages/builder/src/pages/builder/portal/users/users/_components/RoleTableRenderer.svelte index 8217c85c5e..43fe8cc1cc 100644 --- a/packages/builder/src/pages/builder/portal/users/users/_components/RoleTableRenderer.svelte +++ b/packages/builder/src/pages/builder/portal/users/users/_components/RoleTableRenderer.svelte @@ -10,7 +10,7 @@ admin: "Full access", } - $: role = Constants.BudibaseRoleOptions.find( + $: role = Constants.BudibaseRoleOptionsOld.find( x => x.value === users.getUserRole(row) ) $: value = role?.label || "Not available" diff --git a/packages/builder/src/stores/portal/users.js b/packages/builder/src/stores/portal/users.js index 996a94013b..3ee0516544 100644 --- a/packages/builder/src/stores/portal/users.js +++ b/packages/builder/src/stores/portal/users.js @@ -121,8 +121,11 @@ export function createUsersStore() { } const getUserRole = user => - sdk.users.isAdminOrGlobalBuilder(user) ? "admin" : "appUser" - + sdk.users.isAdmin(user) + ? "admin" + : sdk.users.isBuilder(user) + ? "developer" + : "appUser" const refreshUsage = fn => async (...args) => { diff --git a/packages/frontend-core/src/constants.js b/packages/frontend-core/src/constants.js index 198d88196b..cfaaaea81b 100644 --- a/packages/frontend-core/src/constants.js +++ b/packages/frontend-core/src/constants.js @@ -23,6 +23,11 @@ export const BudibaseRoles = { Admin: "admin", } +export const BudibaseRoleOptionsOld = [ + { label: "Developer", value: BudibaseRoles.Developer }, + { label: "Member", value: BudibaseRoles.AppUser }, + { label: "Admin", value: BudibaseRoles.Admin }, +] export const BudibaseRoleOptions = [ { label: "Member", value: BudibaseRoles.AppUser }, { label: "Admin", value: BudibaseRoles.Admin }, diff --git a/packages/worker/src/api/controllers/global/users.ts b/packages/worker/src/api/controllers/global/users.ts index a084685dd3..a73c4de8e7 100644 --- a/packages/worker/src/api/controllers/global/users.ts +++ b/packages/worker/src/api/controllers/global/users.ts @@ -403,15 +403,15 @@ export const inviteAccept = async ( lastName, password, email, - admin: { global: info.admin.global || false }, + admin: { global: info?.admin?.global || false }, roles: info.apps, tenantId: info.tenantId, } let builder: { global: boolean; apps?: string[] } = { - global: info.builder.global || false, + global: info?.builder?.global || false, } - if (info.builder.apps) { + if (info?.builder?.apps) { builder.apps = info.builder.apps request.builder = builder delete info.builder.apps From 9c30d79093c4094bcd18ebd938260d40a6f1d72e Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 5 Sep 2023 10:13:23 +0100 Subject: [PATCH 5/8] formatting --- .../users/users/_components/AppsTableRenderer.svelte | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/users/users/_components/AppsTableRenderer.svelte b/packages/builder/src/pages/builder/portal/users/users/_components/AppsTableRenderer.svelte index 9dda0dbab2..32e50ef05f 100644 --- a/packages/builder/src/pages/builder/portal/users/users/_components/AppsTableRenderer.svelte +++ b/packages/builder/src/pages/builder/portal/users/users/_components/AppsTableRenderer.svelte @@ -13,10 +13,10 @@ return $apps.length } else { return sdk.users.hasAppBuilderPermissions(row) - ? row.builder.apps.length + - Object.keys(row.roles || {}).filter(appId => - row.builder.apps.includes(appId) - ).length + ? row?.builder?.apps?.length + + Object.keys(row.roles || {}).filter(appId => { + row?.builder?.apps?.includes(appId) + }).length : value?.length || 0 } } From 70c71c13bf07eb70e08c5c88db299f80492e8a0a Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 5 Sep 2023 12:20:39 +0100 Subject: [PATCH 6/8] remove redudant delete --- packages/worker/src/api/controllers/global/users.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/worker/src/api/controllers/global/users.ts b/packages/worker/src/api/controllers/global/users.ts index a73c4de8e7..6d3a13aa4e 100644 --- a/packages/worker/src/api/controllers/global/users.ts +++ b/packages/worker/src/api/controllers/global/users.ts @@ -414,7 +414,6 @@ export const inviteAccept = async ( if (info?.builder?.apps) { builder.apps = info.builder.apps request.builder = builder - delete info.builder.apps } delete info.apps request = { From 1997cb5d6bdcddf695d0ebc6f091e8c3243db0c1 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 5 Sep 2023 12:28:03 +0100 Subject: [PATCH 7/8] readibility update --- .../_components/BuilderSidePanel.svelte | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index 5f89762eac..7c4d3db7ce 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -368,14 +368,12 @@ }, ] - if (creationRoleType !== Constants.BudibaseRoles.Admin) { - if (creationAccessType === Constants.Roles.CREATOR) { - payload[0].builder.apps = [prodAppId] - } else { - payload[0].apps = { - [prodAppId]: creationAccessType, - } - } + const notCreatingAdmin = creationRoleType !== Constants.BudibaseRoles.Admin + const isCreator = creationAccessType === Constants.Roles.CREATOR + if (notCreatingAdmin && isCreator) { + payload[0].builder.apps = [prodAppId] + } else if (notCreatingAdmin && !isCreator) { + payload[0].apps = { [prodAppId]: creationAccessType } } let userInviteResponse From e2e20276cb71fd0d6fb71ae70d7a70a4ee91cb6b Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Tue, 5 Sep 2023 11:35:53 +0000 Subject: [PATCH 8/8] Bump version to 2.9.33-alpha.16 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index 5653cfedf1..383371820b 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.9.33-alpha.15", + "version": "2.9.33-alpha.16", "npmClient": "yarn", "packages": [ "packages/*"