Merge branch 'develop' of github.com:Budibase/budibase into merge-master-develop

This commit is contained in:
mike12345567 2023-09-05 15:25:51 +01:00
commit 5a1b67b830
8 changed files with 78 additions and 57 deletions

View File

@ -120,7 +120,7 @@
await usersFetch.refresh() await usersFetch.refresh()
filteredUsers = $usersFetch.rows filteredUsers = $usersFetch.rows
.filter(user => !user?.admin?.global) // filter out global admins .filter(user => user.email !== $auth.user.email)
.map(user => { .map(user => {
const isAdminOrGlobalBuilder = sdk.users.isAdminOrGlobalBuilder( const isAdminOrGlobalBuilder = sdk.users.isAdminOrGlobalBuilder(
user, user,
@ -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,18 +363,19 @@
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 (creationAccessType === Constants.Roles.CREATOR) { const notCreatingAdmin = creationRoleType !== Constants.BudibaseRoles.Admin
payload[0].appBuilders = [prodAppId] const isCreator = creationAccessType === Constants.Roles.CREATOR
} else { if (notCreatingAdmin && isCreator) {
payload[0].apps = { payload[0].builder.apps = [prodAppId]
[prodAppId]: creationAccessType, } else if (notCreatingAdmin && !isCreator) {
} payload[0].apps = { [prodAppId]: creationAccessType }
} }
let userInviteResponse let userInviteResponse
try { try {
userInviteResponse = await users.onboard(payload) userInviteResponse = await users.onboard(payload)
@ -438,10 +436,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)
@ -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 => { const getRoleFooter = user => {
if (user.group) { if (user.group) {
const role = $roles.find(role => role._id === user.role) const role = $roles.find(role => role._id === user.role)
@ -531,7 +542,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"
@ -600,6 +613,11 @@
<div class="auth-entity-access-title">Access</div> <div class="auth-entity-access-title">Access</div>
</div> </div>
{#each filteredInvites as invite} {#each filteredInvites as invite}
{@const user = {
isAdminOrGlobalBuilder:
invite.info?.admin?.global && invite.info?.builder?.global,
}}
<div class="auth-entity"> <div class="auth-entity">
<div class="details"> <div class="details">
<div class="user-email" title={invite.email}> <div class="user-email" title={invite.email}>
@ -608,10 +626,9 @@
</div> </div>
<div class="auth-entity-access"> <div class="auth-entity-access">
<RoleSelect <RoleSelect
footer={getRoleFooter(user)}
placeholder={false} placeholder={false}
value={invite.info?.appBuilders?.includes(prodAppId) value={getInviteRoleValue(invite)}
? Constants.Roles.CREATOR
: invite.info.apps?.[prodAppId]}
allowRemove={invite.info.apps?.[prodAppId]} allowRemove={invite.info.apps?.[prodAppId]}
allowPublic={false} allowPublic={false}
allowCreator={true} allowCreator={true}
@ -624,6 +641,9 @@
}} }}
autoWidth autoWidth
align="right" align="right"
allowedRoles={user.isAdminOrGlobalBuilder
? [Constants.Roles.ADMIN]
: null}
/> />
</div> </div>
</div> </div>

View File

@ -46,7 +46,7 @@
let loaded = false let loaded = false
let editModal, deleteModal let editModal, deleteModal
$: console.log(group)
$: scimEnabled = $features.isScimEnabled $: scimEnabled = $features.isScimEnabled
$: readonly = !sdk.users.isAdmin($auth.user) || scimEnabled $: readonly = !sdk.users.isAdmin($auth.user) || scimEnabled
$: group = $groups.find(x => x._id === groupId) $: group = $groups.find(x => x._id === groupId)
@ -62,7 +62,7 @@
? Constants.Roles.CREATOR ? Constants.Roles.CREATOR
: group?.roles?.[apps.getProdAppID(app.devId)], : group?.roles?.[apps.getProdAppID(app.devId)],
})) }))
$: console.log(groupApps)
$: { $: {
if (loaded && !group?._id) { if (loaded && !group?._id) {
$goto("./") $goto("./")

View File

@ -5,7 +5,6 @@
export let value export let value
export let row export let row
$: console.log(row)
$: priviliged = sdk.users.isAdminOrBuilder(row) $: priviliged = sdk.users.isAdminOrBuilder(row)
$: count = getCount(row) $: count = getCount(row)
@ -14,10 +13,10 @@
return $apps.length return $apps.length
} else { } else {
return sdk.users.hasAppBuilderPermissions(row) return sdk.users.hasAppBuilderPermissions(row)
? row.builder.apps.length + ? row?.builder?.apps?.length +
Object.keys(row.roles || {}).filter(appId => Object.keys(row.roles || {}).filter(appId => {
row.builder.apps.includes(appId) row?.builder?.apps?.includes(appId)
).length }).length
: value?.length || 0 : value?.length || 0
} }
} }

View File

@ -10,7 +10,7 @@
admin: "Full access", admin: "Full access",
} }
$: role = Constants.BudibaseRoleOptions.find( $: role = Constants.BudibaseRoleOptionsOld.find(
x => x.value === users.getUserRole(row) x => x.value === users.getUserRole(row)
) )
$: value = role?.label || "Not available" $: value = role?.label || "Not available"

View File

@ -121,8 +121,11 @@ export function createUsersStore() {
} }
const getUserRole = user => const getUserRole = user =>
sdk.users.isAdminOrGlobalBuilder(user) ? "admin" : "appUser" sdk.users.isAdmin(user)
? "admin"
: sdk.users.isBuilder(user)
? "developer"
: "appUser"
const refreshUsage = const refreshUsage =
fn => fn =>
async (...args) => { async (...args) => {

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,
}, },
}, },
@ -156,14 +156,13 @@ export const buildUserEndpoints = API => ({
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
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,
}, },
} }
}), }),
@ -176,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

@ -23,6 +23,11 @@ export const BudibaseRoles = {
Admin: "admin", Admin: "admin",
} }
export const BudibaseRoleOptionsOld = [
{ label: "Developer", value: BudibaseRoles.Developer },
{ label: "Member", value: BudibaseRoles.AppUser },
{ label: "Admin", value: BudibaseRoles.Admin },
]
export const BudibaseRoleOptions = [ export const BudibaseRoleOptions = [
{ label: "Member", value: BudibaseRoles.AppUser }, { label: "Member", value: BudibaseRoles.AppUser },
{ label: "Admin", value: BudibaseRoles.Admin }, { label: "Admin", value: BudibaseRoles.Admin },

View File

@ -266,17 +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: 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: false }, admin: invite.userInfo.admin,
builder, builder: invite.userInfo.builder,
tenantId: tenancy.getTenantId(), tenantId: tenancy.getTenantId(),
} }
}) })
@ -371,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) {
@ -409,15 +403,17 @@ export const inviteAccept = async (
lastName, lastName,
password, password,
email, email,
admin: { global: info?.admin?.global || false },
roles: info.apps, roles: info.apps,
tenantId: info.tenantId, 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) { if (info?.builder?.apps) {
builder.apps = info.appBuilders builder.apps = info.builder.apps
request.builder = builder request.builder = builder
delete info.appBuilders
} }
delete info.apps delete info.apps
request = { request = {