1
0
Fork 0
mirror of synced 2024-09-28 23:31:43 +12:00

Fix users invited by email not being able to take priveleged roles

This commit is contained in:
Andrew Kingston 2022-08-03 15:16:26 +01:00
parent 60565abfbf
commit 6701c25fc9
9 changed files with 61 additions and 50 deletions

View file

@ -275,7 +275,7 @@
<Label size="L">Role</Label>
<Select
value={globalRole}
options={Constants.BbRoles}
options={Constants.BudibaseRoleOptions}
on:change={updateUserRole}
/>
</div>

View file

@ -47,7 +47,11 @@
function validateInput(email, index) {
if (email) {
const res = emailValidator(email)
userData[index].error = res === true ? null : res
if (res === true) {
delete userData[index].error
} else {
userData[index].error = res
}
} else {
userData[index].error = "Please enter an email address"
}
@ -89,7 +93,7 @@
inputType="email"
bind:inputValue={input.email}
bind:dropdownValue={input.role}
options={Constants.BbRoles}
options={Constants.BudibaseRoleOptions}
error={input.error}
on:blur={() => validateInput(input.email, index)}
/>

View file

@ -10,7 +10,9 @@
admin: "Full access",
}
$: role = Constants.BbRoles.find(x => x.value === users.getUserRole(row))
$: role = Constants.BudibaseRoleOptions.find(
x => x.value === users.getUserRole(row)
)
$: value = role?.label || "Not available"
$: tooltip = TooltipMap[role?.value] || ""
</script>

View file

@ -26,6 +26,7 @@
import ImportUsersModal from "./_components/ImportUsersModal.svelte"
import { createPaginationStore } from "helpers/pagination"
import { get } from "svelte/store"
import { Constants } from "@budibase/frontend-core"
let enrichedUsers = []
let createUserModal,
@ -85,13 +86,13 @@
}
async function createUserFlow() {
let emails = userData?.users?.map(x => x.email) || []
const payload = userData?.users?.map(user => ({
email: user.email,
builder: user.role === Constants.BudibaseRoles.Developer,
admin: user.role === Constants.BudibaseRoles.Admin,
}))
try {
const res = await users.invite({
emails: emails,
builder: false,
admin: false,
})
const res = await users.invite(payload)
notifications.success(res.message)
inviteConfirmationModal.show()
} catch (error) {

View file

@ -26,12 +26,8 @@ export function createUsersStore() {
return await API.getUsers()
}
async function invite({ emails, builder, admin }) {
return API.inviteUsers({
emails,
builder,
admin,
})
async function invite(payload) {
return API.inviteUsers(payload)
}
async function acceptInvite(inviteCode, password) {
return API.acceptInvite({

View file

@ -141,20 +141,18 @@ export const buildUserEndpoints = API => ({
/**
* Invites multiple users to the current tenant.
* @param email An array of email addresses
* @param builder whether the user should be a global builder
* @param admin whether the user should be a global admin
* @param users An array of users to invite
*/
inviteUsers: async ({ emails, builder, admin }) => {
inviteUsers: async users => {
return await API.post({
url: "/api/global/users/inviteMultiple",
body: {
emails,
body: users.map(user => ({
email: user.email,
userInfo: {
admin: admin ? { global: true } : undefined,
builder: builder ? { global: true } : undefined,
admin: user.admin ? { global: true } : undefined,
builder: user.admin || user.builder ? { global: true } : undefined,
},
},
})),
})
},

View file

@ -60,25 +60,31 @@ export const TableNames = {
USERS: "ta_users",
}
export const BbRoles = [
{ label: "App User", value: "appUser" },
{ label: "Developer", value: "developer" },
{ label: "Admin", value: "admin" },
export const BudibaseRoles = {
AppUser: "appUser",
Developer: "developer",
Admin: "admin",
}
export const BudibaseRoleOptions = [
{ label: "App User", value: BudibaseRoles.AppUser },
{ label: "Developer", value: BudibaseRoles.Developer },
{ label: "Admin", value: BudibaseRoles.Admin },
]
export const BuilderRoleDescriptions = [
{
value: "appUser",
value: BudibaseRoles.AppUser,
icon: "User",
label: "App user - Only has access to published apps",
},
{
value: "developer",
value: BudibaseRoles.Developer,
icon: "Hammer",
label: "Developer - Access to the app builder",
},
{
value: "admin",
value: BudibaseRoles.Admin,
icon: "Draw",
label: "Admin - Full access",
},

View file

@ -214,13 +214,13 @@ export const invite = async (ctx: any) => {
}
export const inviteMultiple = async (ctx: any) => {
let { emails, userInfo } = ctx.request.body
let users = ctx.request.body
let existing = false
let existingEmail
for (let email of emails) {
if (await usersCore.getGlobalUserByEmail(email)) {
for (let user of users) {
if (await usersCore.getGlobalUserByEmail(user.email)) {
existing = true
existingEmail = email
existingEmail = user.email
break
}
}
@ -228,17 +228,19 @@ export const inviteMultiple = async (ctx: any) => {
if (existing) {
ctx.throw(400, `${existingEmail} already exists`)
}
if (!userInfo) {
userInfo = {}
}
userInfo.tenantId = tenancy.getTenantId()
const opts: any = {
subject: "{{ company }} platform invitation",
info: userInfo,
}
for (let i = 0; i < emails.length; i++) {
await sendEmail(emails[i], EmailTemplatePurpose.INVITATION, opts)
for (let i = 0; i < users.length; i++) {
let userInfo = users[i].userInfo
if (!userInfo) {
userInfo = {}
}
userInfo.tenantId = tenancy.getTenantId()
const opts: any = {
subject: "{{ company }} platform invitation",
info: userInfo,
}
console.log(userInfo)
await sendEmail(users[i].email, EmailTemplatePurpose.INVITATION, opts)
}
ctx.body = {

View file

@ -32,10 +32,12 @@ function buildInviteValidation() {
function buildInviteMultipleValidation() {
// prettier-ignore
return joiValidator.body(Joi.object({
emails: Joi.array().required(),
userInfo: Joi.object().optional(),
}).required())
return joiValidator.body(Joi.array().required().items(
Joi.object({
email: Joi.string(),
userInfo: Joi.object().optional(),
})
))
}
function buildInviteAcceptValidation() {