Merge branch 'master' into fix/view-v1-data

This commit is contained in:
Adria Navarro 2025-01-07 16:55:53 +01:00 committed by GitHub
commit 12b75b6fcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 32 deletions

View File

@ -87,6 +87,7 @@
let popover let popover
let user, tenantOwner let user, tenantOwner
let loaded = false let loaded = false
let userFieldsToUpdate = {}
$: internalGroups = $groups?.filter(g => !g?.scimInfo?.isSync) $: internalGroups = $groups?.filter(g => !g?.scimInfo?.isSync)
@ -164,40 +165,45 @@
return label return label
} }
async function updateUserFirstName(evt) { async function saveUser() {
try { try {
await users.save({ ...user, firstName: evt.target.value }) await users.save({ ...user, ...userFieldsToUpdate })
userFieldsToUpdate = {}
await fetchUser() await fetchUser()
} catch (error) { } catch (error) {
notifications.error("Error updating user") notifications.error("Error updating user")
} }
} }
async function updateUserFirstName(evt) {
userFieldsToUpdate.firstName = evt.target.value
}
async function updateUserLastName(evt) { async function updateUserLastName(evt) {
try { userFieldsToUpdate.lastName = evt.target.value
await users.save({ ...user, lastName: evt.target.value })
await fetchUser()
} catch (error) {
notifications.error("Error updating user")
}
} }
async function updateUserRole({ detail }) { async function updateUserRole({ detail }) {
let flags = {}
if (detail === Constants.BudibaseRoles.Developer) { if (detail === Constants.BudibaseRoles.Developer) {
toggleFlags({ admin: { global: false }, builder: { global: true } }) flags = { admin: { global: false }, builder: { global: true } }
} else if (detail === Constants.BudibaseRoles.Admin) { } else if (detail === Constants.BudibaseRoles.Admin) {
toggleFlags({ admin: { global: true }, builder: { global: true } }) flags = { admin: { global: true }, builder: { global: true } }
} else if (detail === Constants.BudibaseRoles.AppUser) { } else if (detail === Constants.BudibaseRoles.AppUser) {
toggleFlags({ admin: { global: false }, builder: { global: false } }) flags = { admin: { global: false }, builder: { global: false } }
} else if (detail === Constants.BudibaseRoles.Creator) { } else if (detail === Constants.BudibaseRoles.Creator) {
toggleFlags({ flags = {
admin: { global: false }, admin: { global: false },
builder: { builder: {
global: false, global: false,
creator: true, creator: true,
apps: user?.builder?.apps || [], apps: user?.builder?.apps || [],
}, },
}) }
}
userFieldsToUpdate = {
...userFieldsToUpdate,
...flags,
} }
} }
@ -209,15 +215,6 @@
tenantOwner = await users.getAccountHolder() tenantOwner = await users.getAccountHolder()
} }
async function toggleFlags(detail) {
try {
await users.save({ ...user, ...detail })
await fetchUser()
} catch (error) {
notifications.error("Error updating user")
}
}
const addGroup = async groupId => { const addGroup = async groupId => {
await groups.addUser(groupId, userId) await groups.addUser(groupId, userId)
await fetchUser() await fetchUser()
@ -296,7 +293,7 @@
<Input <Input
disabled={readonly} disabled={readonly}
value={user?.firstName} value={user?.firstName}
on:blur={updateUserFirstName} on:input={updateUserFirstName}
/> />
</div> </div>
<div class="field"> <div class="field">
@ -304,7 +301,7 @@
<Input <Input
disabled={readonly} disabled={readonly}
value={user?.lastName} value={user?.lastName}
on:blur={updateUserLastName} on:input={updateUserLastName}
/> />
</div> </div>
<!-- don't let a user remove the privileges that let them be here --> <!-- don't let a user remove the privileges that let them be here -->
@ -325,6 +322,13 @@
{/if} {/if}
</div> </div>
</Layout> </Layout>
<div>
<Button
cta
disabled={Object.keys(userFieldsToUpdate).length === 0}
on:click={saveUser}>Save</Button
>
</div>
{#if $licensing.groupsEnabled} {#if $licensing.groupsEnabled}
<!-- User groups --> <!-- User groups -->

View File

@ -72,12 +72,14 @@ export const save = async (ctx: UserCtx<User, SaveUserResponse>) => {
const requestUser = ctx.request.body const requestUser = ctx.request.body
// Do not allow the account holder role to be changed // Do not allow the account holder role to be changed
const accountMetadata = await users.getExistingAccounts([requestUser.email]) if (
if (accountMetadata?.length > 0) { requestUser.admin?.global !== true ||
if ( requestUser.builder?.global !== true
requestUser.admin?.global !== true || ) {
requestUser.builder?.global !== true const accountMetadata = await users.getExistingAccounts([
) { requestUser.email,
])
if (accountMetadata?.length > 0) {
throw Error("Cannot set role of account holder") throw Error("Cannot set role of account holder")
} }
} }
@ -441,7 +443,6 @@ export const checkInvite = async (ctx: UserCtx<void, CheckInviteResponse>) => {
} catch (e) { } catch (e) {
console.warn("Error getting invite from code", e) console.warn("Error getting invite from code", e)
ctx.throw(400, "There was a problem with the invite") ctx.throw(400, "There was a problem with the invite")
return
} }
ctx.body = { ctx.body = {
email: invite.email, email: invite.email,
@ -472,7 +473,6 @@ export const updateInvite = async (
invite = await cache.invite.getCode(code) invite = await cache.invite.getCode(code)
} catch (e) { } catch (e) {
ctx.throw(400, "There was a problem with the invite") ctx.throw(400, "There was a problem with the invite")
return
} }
let updated = { let updated = {