From 24abd91600d4bf963874f3de62cb98de0e265421 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 4 Sep 2023 09:37:10 +0100 Subject: [PATCH] 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