Fix issue around adding of admin users

This commit is contained in:
Peter Clement 2023-09-04 09:37:10 +01:00
parent 190e29e043
commit 24abd91600
3 changed files with 43 additions and 13 deletions

View File

@ -366,11 +366,12 @@
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 (creationRoleType !== Constants.BudibaseRoles.Admin) {
if (creationAccessType === Constants.Roles.CREATOR) {
payload[0].appBuilders = [prodAppId]
} else {
@ -378,6 +379,8 @@
[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 @@
<div class="auth-entity-access-title">Access</div>
</div>
{#each filteredInvites as invite}
{@const user = {
isAdminOrGlobalBuilder:
invite.info?.admin?.global && invite.info?.builder?.global,
}}
<div class="auth-entity">
<div class="details">
<div class="user-email" title={invite.email}>
@ -608,10 +628,9 @@
</div>
<div class="auth-entity-access">
<RoleSelect
footer={getRoleFooter(user)}
placeholder={false}
value={invite.info?.appBuilders?.includes(prodAppId)
? Constants.Roles.CREATOR
: invite.info.apps?.[prodAppId]}
value={getInviteRoleValue(invite)}
allowRemove={invite.info.apps?.[prodAppId]}
allowPublic={false}
allowCreator={true}
@ -624,6 +643,9 @@
}}
autoWidth
align="right"
allowedRoles={user.isAdminOrGlobalBuilder
? [Constants.Roles.ADMIN]
: null}
/>
</div>
</div>

View File

@ -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: {

View File

@ -266,7 +266,9 @@ export const onboardUsers = async (ctx: Ctx<InviteUsersRequest>) => {
// 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<InviteUsersRequest>) => {
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