fixes for perr app builder and refactoring based on comments

This commit is contained in:
Peter Clement 2023-09-05 09:25:06 +01:00
parent 24abd91600
commit 6d3a7727eb
3 changed files with 32 additions and 45 deletions

View File

@ -150,13 +150,10 @@
} }
const sortInviteRoles = (a, b) => { const sortInviteRoles = (a, b) => {
const aEmpty = const aAppsEmpty = !a.info?.apps?.length && !a.info?.builder?.apps?.length
!a.info?.appBuilders?.length && Object.keys(a.info.apps).length === 0 const bAppsEmpty = !b.info?.apps?.length && !b.info?.builder?.apps?.length
const bEmpty =
!b.info?.appBuilders?.length && Object.keys(b.info.apps).length === 0
if (aEmpty && !bEmpty) return 1 return aAppsEmpty && !bAppsEmpty ? 1 : !aAppsEmpty && bAppsEmpty ? -1 : 0
if (!aEmpty && bEmpty) return -1
} }
const sortRoles = (a, b) => { const sortRoles = (a, b) => {
@ -366,14 +363,14 @@
const payload = [ const payload = [
{ {
email: newUserEmail, email: newUserEmail,
builder: creationRoleType === Constants.BudibaseRoles.Admin, builder: { global: creationRoleType === Constants.BudibaseRoles.Admin },
admin: creationRoleType === Constants.BudibaseRoles.Admin, admin: { global: creationRoleType === Constants.BudibaseRoles.Admin },
}, },
] ]
if (creationRoleType !== Constants.BudibaseRoles.Admin) { if (creationRoleType !== Constants.BudibaseRoles.Admin) {
if (creationAccessType === Constants.Roles.CREATOR) { if (creationAccessType === Constants.Roles.CREATOR) {
payload[0].appBuilders = [prodAppId] payload[0].builder.apps = [prodAppId]
} else { } else {
payload[0].apps = { payload[0].apps = {
[prodAppId]: creationAccessType, [prodAppId]: creationAccessType,
@ -441,10 +438,11 @@
} }
if (role === Constants.Roles.CREATOR) { 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] delete updateBody?.apps?.[prodAppId]
} else if (role !== Constants.Roles.CREATOR && invite?.appBuilders) { } else if (role !== Constants.Roles.CREATOR && invite?.builder?.apps) {
invite.appBuilders = [] invite.builder.apps = []
} }
await users.updateInvite(updateBody) await users.updateInvite(updateBody)
await filterInvites(query) await filterInvites(query)
@ -502,7 +500,7 @@
return Constants.Roles.ADMIN return Constants.Roles.ADMIN
} }
if (invite.info?.appBuilders?.includes(prodAppId)) { if (invite.info?.builder?.apps?.includes(prodAppId)) {
return Constants.Roles.CREATOR return Constants.Roles.CREATOR
} }
@ -546,7 +544,9 @@
<Heading size="S">{invitingFlow ? "Invite new user" : "Users"}</Heading> <Heading size="S">{invitingFlow ? "Invite new user" : "Users"}</Heading>
</div> </div>
<div class="header"> <div class="header">
<Button on:click={openInviteFlow} size="S" cta>Invite user</Button> {#if !invitingFlow}
<Button on:click={openInviteFlow} size="S" cta>Invite user</Button>
{/if}
<Icon <Icon
color="var(--spectrum-global-color-gray-600)" color="var(--spectrum-global-color-gray-600)"
name="RailRightClose" name="RailRightClose"

View File

@ -144,8 +144,8 @@ export const buildUserEndpoints = API => ({
body: { body: {
email, email,
userInfo: { userInfo: {
admin: admin ? { global: true } : undefined, admin: admin?.global ? { global: true } : undefined,
builder: builder ? { global: true } : undefined, builder: builder?.global ? { global: true } : undefined,
apps: apps ? apps : undefined, apps: apps ? apps : undefined,
}, },
}, },
@ -153,20 +153,16 @@ export const buildUserEndpoints = API => ({
}, },
onboardUsers: async payload => { onboardUsers: async payload => {
console.log(payload)
return await API.post({ return await API.post({
url: "/api/global/users/onboard", url: "/api/global/users/onboard",
body: payload.map(invite => { body: payload.map(invite => {
const { email, admin, builder, apps, appBuilders } = invite const { email, admin, builder, apps } = invite
console.log(admin)
console.log(builder)
return { return {
email, email,
userInfo: { userInfo: {
admin: admin ? { global: true } : undefined, admin,
builder: builder ? { global: true } : undefined, builder,
apps: apps ? apps : undefined, apps: apps ? apps : undefined,
appBuilders,
}, },
} }
}), }),
@ -179,12 +175,11 @@ export const buildUserEndpoints = API => ({
* @param invite the invite code sent in the email * @param invite the invite code sent in the email
*/ */
updateUserInvite: async invite => { updateUserInvite: async invite => {
console.log(invite)
await API.post({ await API.post({
url: `/api/global/users/invite/update/${invite.code}`, url: `/api/global/users/invite/update/${invite.code}`,
body: { body: {
apps: invite.apps, apps: invite.apps,
appBuilders: invite.appBuilders, builder: invite.builder,
}, },
}) })
}, },

View File

@ -266,19 +266,14 @@ export const onboardUsers = async (ctx: Ctx<InviteUsersRequest>) => {
// Temp password to be passed to the user. // Temp password to be passed to the user.
createdPasswords[invite.email] = password 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 { return {
email: invite.email, email: invite.email,
password, password,
forceResetPassword: true, forceResetPassword: true,
roles: invite.userInfo.apps, roles: invite.userInfo.apps,
admin: { global: invite.userInfo.admin || false }, admin: invite.userInfo.admin,
builder, builder: invite.userInfo.builder,
tenantId: tenancy.getTenantId(), tenantId: tenancy.getTenantId(),
} }
}) })
@ -373,13 +368,10 @@ export const updateInvite = async (ctx: any) => {
...invite, ...invite,
} }
if (!updateBody?.appBuilders || !updateBody.appBuilders?.length) { if (!updateBody?.builder?.apps && updated.info?.builder?.apps) {
updated.info.appBuilders = [] updated.info.builder.apps = []
} else { } else if (updateBody?.builder) {
updated.info.appBuilders = [ updated.info.builder = updateBody.builder
...(invite.info.appBuilders ?? []),
...updateBody.appBuilders,
]
} }
if (!updateBody?.apps || !Object.keys(updateBody?.apps).length) { if (!updateBody?.apps || !Object.keys(updateBody?.apps).length) {
@ -411,18 +403,18 @@ export const inviteAccept = async (
lastName, lastName,
password, password,
email, email,
admin: { global: info.admin || false }, admin: { global: info.admin.global || false },
roles: info.apps, roles: info.apps,
tenantId: info.tenantId, tenantId: info.tenantId,
} }
let builder: { global: boolean; apps?: string[] } = { let builder: { global: boolean; apps?: string[] } = {
global: info.builder || false, global: info.builder.global || false,
} }
if (info.appBuilders) { if (info.builder.apps) {
builder.apps = info.appBuilders builder.apps = info.builder.apps
request.builder = builder request.builder = builder
delete info.appBuilders delete info.builder.apps
} }
delete info.apps delete info.apps
request = { request = {