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..7c4d3db7ce 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, @@ -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,18 +363,19 @@ 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 (creationAccessType === Constants.Roles.CREATOR) { - payload[0].appBuilders = [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 try { userInviteResponse = await users.onboard(payload) @@ -438,10 +436,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) @@ -494,6 +493,18 @@ } } + const getInviteRoleValue = invite => { + if (invite.info?.admin?.global && invite.info?.builder?.global) { + return Constants.Roles.ADMIN + } + + if (invite.info?.builder?.apps?.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) @@ -531,7 +542,9 @@ {invitingFlow ? "Invite new user" : "Users"}
- + {#if !invitingFlow} + + {/if} Access
{#each filteredInvites as invite} + {@const user = { + isAdminOrGlobalBuilder: + invite.info?.admin?.global && invite.info?.builder?.global, + }} +
@@ -608,10 +626,9 @@
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..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 @@ -5,7 +5,6 @@ export let value export let row - $: console.log(row) $: priviliged = sdk.users.isAdminOrBuilder(row) $: count = getCount(row) @@ -14,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 } } 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/api/user.js b/packages/frontend-core/src/api/user.js index 329e9cc499..6c616d7baf 100644 --- a/packages/frontend-core/src/api/user.js +++ b/packages/frontend-core/src/api/user.js @@ -144,8 +144,8 @@ export const buildUserEndpoints = API => ({ 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, }, }, @@ -156,14 +156,13 @@ export const buildUserEndpoints = API => ({ return await API.post({ url: "/api/global/users/onboard", body: payload.map(invite => { - const { email, admin, builder, apps, appBuilders } = invite + 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, }, } }), @@ -176,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/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 0ccf9a356f..6d3a13aa4e 100644 --- a/packages/worker/src/api/controllers/global/users.ts +++ b/packages/worker/src/api/controllers/global/users.ts @@ -266,17 +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: false } - if (invite.userInfo.appBuilders) { - builder.apps = invite.userInfo.appBuilders - } + return { email: invite.email, password, forceResetPassword: true, roles: invite.userInfo.apps, - admin: { global: false }, - builder, + admin: invite.userInfo.admin, + builder: invite.userInfo.builder, tenantId: tenancy.getTenantId(), } }) @@ -371,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) { @@ -409,15 +403,17 @@ export const inviteAccept = async ( lastName, password, email, + admin: { global: info?.admin?.global || false }, roles: info.apps, tenantId: info.tenantId, } - let builder: { global: boolean; apps?: string[] } = { global: false } + let builder: { global: boolean; apps?: string[] } = { + 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.apps request = {