Merge branch 'develop' of github.com:Budibase/budibase into plugins-dev-experience
This commit is contained in:
commit
27be6507a8
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "1.2.58-alpha.4",
|
||||
"version": "1.2.58-alpha.5",
|
||||
"npmClient": "yarn",
|
||||
"packages": [
|
||||
"packages/*"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/backend-core",
|
||||
"version": "1.2.58-alpha.4",
|
||||
"version": "1.2.58-alpha.5",
|
||||
"description": "Budibase backend core libraries used in server and worker",
|
||||
"main": "dist/src/index.js",
|
||||
"types": "dist/src/index.d.ts",
|
||||
|
@ -20,7 +20,7 @@
|
|||
"test:watch": "jest --watchAll"
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/types": "1.2.58-alpha.4",
|
||||
"@budibase/types": "1.2.58-alpha.5",
|
||||
"@techpass/passport-openidconnect": "0.3.2",
|
||||
"aws-sdk": "2.1030.0",
|
||||
"bcrypt": "5.0.1",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/bbui",
|
||||
"description": "A UI solution used in the different Budibase projects.",
|
||||
"version": "1.2.58-alpha.4",
|
||||
"version": "1.2.58-alpha.5",
|
||||
"license": "MPL-2.0",
|
||||
"svelte": "src/index.js",
|
||||
"module": "dist/bbui.es.js",
|
||||
|
@ -38,7 +38,7 @@
|
|||
],
|
||||
"dependencies": {
|
||||
"@adobe/spectrum-css-workflow-icons": "^1.2.1",
|
||||
"@budibase/string-templates": "1.2.58-alpha.4",
|
||||
"@budibase/string-templates": "1.2.58-alpha.5",
|
||||
"@spectrum-css/actionbutton": "^1.0.1",
|
||||
"@spectrum-css/actiongroup": "^1.0.1",
|
||||
"@spectrum-css/avatar": "^3.0.2",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/builder",
|
||||
"version": "1.2.58-alpha.4",
|
||||
"version": "1.2.58-alpha.5",
|
||||
"license": "GPL-3.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
@ -69,10 +69,10 @@
|
|||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/bbui": "1.2.58-alpha.4",
|
||||
"@budibase/client": "1.2.58-alpha.4",
|
||||
"@budibase/frontend-core": "1.2.58-alpha.4",
|
||||
"@budibase/string-templates": "1.2.58-alpha.4",
|
||||
"@budibase/bbui": "1.2.58-alpha.5",
|
||||
"@budibase/client": "1.2.58-alpha.5",
|
||||
"@budibase/frontend-core": "1.2.58-alpha.5",
|
||||
"@budibase/string-templates": "1.2.58-alpha.5",
|
||||
"@sentry/browser": "5.19.1",
|
||||
"@spectrum-css/page": "^3.0.1",
|
||||
"@spectrum-css/vars": "^3.0.1",
|
||||
|
|
|
@ -44,7 +44,11 @@
|
|||
]
|
||||
}
|
||||
|
||||
function validateInput(email, index) {
|
||||
function validateInput(input, index) {
|
||||
if (input.email) {
|
||||
input.email = input.email.trim()
|
||||
}
|
||||
const email = input.email
|
||||
if (email) {
|
||||
const res = emailValidator(email)
|
||||
if (res === true) {
|
||||
|
@ -95,7 +99,7 @@
|
|||
bind:dropdownValue={input.role}
|
||||
options={Constants.BudibaseRoleOptions}
|
||||
error={input.error}
|
||||
on:blur={() => validateInput(input.email, index)}
|
||||
on:blur={() => validateInput(input, index)}
|
||||
/>
|
||||
</div>
|
||||
<div class="icon">
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<script>
|
||||
import { Body, ModalContent, Table } from "@budibase/bbui"
|
||||
import { onMount } from "svelte"
|
||||
|
||||
export let inviteUsersResponse
|
||||
|
||||
let hasSuccess
|
||||
let hasFailure
|
||||
let title
|
||||
let failureMessage
|
||||
|
||||
let unsuccessfulUsers
|
||||
|
||||
const setTitle = () => {
|
||||
if (hasSuccess) {
|
||||
title = "Users invited!"
|
||||
} else if (hasFailure) {
|
||||
title = "Oops!"
|
||||
}
|
||||
}
|
||||
|
||||
const setFailureMessage = () => {
|
||||
if (hasSuccess) {
|
||||
failureMessage = "However there was a problem inviting some users."
|
||||
} else {
|
||||
failureMessage = "There was a problem inviting users."
|
||||
}
|
||||
}
|
||||
|
||||
const setUsers = () => {
|
||||
unsuccessfulUsers = inviteUsersResponse.unsuccessful.map(user => {
|
||||
return {
|
||||
email: user.email,
|
||||
reason: user.reason,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
hasSuccess = inviteUsersResponse.successful.length
|
||||
hasFailure = inviteUsersResponse.unsuccessful.length
|
||||
setTitle()
|
||||
setFailureMessage()
|
||||
setUsers()
|
||||
})
|
||||
|
||||
const failedSchema = {
|
||||
email: {},
|
||||
reason: {},
|
||||
}
|
||||
</script>
|
||||
|
||||
<ModalContent showCancelButton={false} {title} confirmText="Done">
|
||||
{#if hasSuccess}
|
||||
<Body size="XS">
|
||||
Your users should now receive an email invite to get access to their
|
||||
Budibase account
|
||||
</Body>
|
||||
{/if}
|
||||
{#if hasFailure}
|
||||
<Body size="XS">
|
||||
{failureMessage}
|
||||
</Body>
|
||||
<Table
|
||||
schema={failedSchema}
|
||||
data={unsuccessfulUsers}
|
||||
allowEditColumns={false}
|
||||
allowEditRows={false}
|
||||
allowSelectRows={false}
|
||||
/>
|
||||
{/if}
|
||||
</ModalContent>
|
||||
|
||||
<style>
|
||||
</style>
|
|
@ -7,7 +7,6 @@
|
|||
Table,
|
||||
Layout,
|
||||
Modal,
|
||||
ModalContent,
|
||||
Search,
|
||||
notifications,
|
||||
Pagination,
|
||||
|
@ -23,6 +22,7 @@
|
|||
import { goto } from "@roxi/routify"
|
||||
import OnboardingTypeModal from "./_components/OnboardingTypeModal.svelte"
|
||||
import PasswordModal from "./_components/PasswordModal.svelte"
|
||||
import InvitedModal from "./_components/InvitedModal.svelte"
|
||||
import DeletionFailureModal from "./_components/DeletionFailureModal.svelte"
|
||||
import ImportUsersModal from "./_components/ImportUsersModal.svelte"
|
||||
import { createPaginationStore } from "helpers/pagination"
|
||||
|
@ -59,6 +59,7 @@
|
|||
$: userData = []
|
||||
$: createUsersResponse = { successful: [], unsuccessful: [] }
|
||||
$: deleteUsersResponse = { successful: [], unsuccessful: [] }
|
||||
$: inviteUsersResponse = { successful: [], unsuccessful: [] }
|
||||
$: page = $pageInfo.page
|
||||
$: fetchUsers(page, searchEmail)
|
||||
$: {
|
||||
|
@ -96,8 +97,7 @@
|
|||
admin: user.role === Constants.BudibaseRoles.Admin,
|
||||
}))
|
||||
try {
|
||||
const res = await users.invite(payload)
|
||||
notifications.success(res.message)
|
||||
inviteUsersResponse = await users.invite(payload)
|
||||
inviteConfirmationModal.show()
|
||||
} catch (error) {
|
||||
notifications.error("Error inviting user")
|
||||
|
@ -144,10 +144,10 @@
|
|||
userData = await removingDuplicities({ groups, users })
|
||||
if (!userData.users.length) return
|
||||
|
||||
return createUser()
|
||||
return createUsers()
|
||||
}
|
||||
|
||||
async function createUser() {
|
||||
async function createUsers() {
|
||||
try {
|
||||
createUsersResponse = await users.create(
|
||||
await removingDuplicities(userData)
|
||||
|
@ -164,7 +164,7 @@
|
|||
if (onboardingType === "emailOnboarding") {
|
||||
createUserFlow()
|
||||
} else {
|
||||
await createUser()
|
||||
await createUsers()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,16 +281,7 @@
|
|||
</Modal>
|
||||
|
||||
<Modal bind:this={inviteConfirmationModal}>
|
||||
<ModalContent
|
||||
showCancelButton={false}
|
||||
title="Invites sent!"
|
||||
confirmText="Done"
|
||||
>
|
||||
<Body size="S"
|
||||
>Your users should now recieve an email invite to get access to their
|
||||
Budibase account</Body
|
||||
></ModalContent
|
||||
>
|
||||
<InvitedModal {inviteUsersResponse} />
|
||||
</Modal>
|
||||
|
||||
<Modal bind:this={onboardingTypeModal}>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/cli",
|
||||
"version": "1.2.58-alpha.4",
|
||||
"version": "1.2.58-alpha.5",
|
||||
"description": "Budibase CLI, for developers, self hosting and migrations.",
|
||||
"main": "src/index.js",
|
||||
"bin": {
|
||||
|
@ -26,9 +26,9 @@
|
|||
"outputPath": "build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/backend-core": "1.2.58-alpha.4",
|
||||
"@budibase/string-templates": "1.2.58-alpha.4",
|
||||
"@budibase/types": "1.2.58-alpha.4",
|
||||
"@budibase/backend-core": "1.2.58-alpha.5",
|
||||
"@budibase/string-templates": "1.2.58-alpha.5",
|
||||
"@budibase/types": "1.2.58-alpha.5",
|
||||
"axios": "0.21.2",
|
||||
"chalk": "4.1.0",
|
||||
"cli-progress": "3.11.2",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/client",
|
||||
"version": "1.2.58-alpha.4",
|
||||
"version": "1.2.58-alpha.5",
|
||||
"license": "MPL-2.0",
|
||||
"module": "dist/budibase-client.js",
|
||||
"main": "dist/budibase-client.js",
|
||||
|
@ -19,9 +19,9 @@
|
|||
"dev:builder": "rollup -cw"
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/bbui": "1.2.58-alpha.4",
|
||||
"@budibase/frontend-core": "1.2.58-alpha.4",
|
||||
"@budibase/string-templates": "1.2.58-alpha.4",
|
||||
"@budibase/bbui": "1.2.58-alpha.5",
|
||||
"@budibase/frontend-core": "1.2.58-alpha.5",
|
||||
"@budibase/string-templates": "1.2.58-alpha.5",
|
||||
"@spectrum-css/button": "^3.0.3",
|
||||
"@spectrum-css/card": "^3.0.3",
|
||||
"@spectrum-css/divider": "^1.0.3",
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@budibase/frontend-core",
|
||||
"version": "1.2.58-alpha.4",
|
||||
"version": "1.2.58-alpha.5",
|
||||
"description": "Budibase frontend core libraries used in builder and client",
|
||||
"author": "Budibase",
|
||||
"license": "MPL-2.0",
|
||||
"svelte": "src/index.js",
|
||||
"dependencies": {
|
||||
"@budibase/bbui": "1.2.58-alpha.4",
|
||||
"@budibase/bbui": "1.2.58-alpha.5",
|
||||
"lodash": "^4.17.21",
|
||||
"svelte": "^3.46.2"
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/server",
|
||||
"email": "hi@budibase.com",
|
||||
"version": "1.2.58-alpha.4",
|
||||
"version": "1.2.58-alpha.5",
|
||||
"description": "Budibase Web Server",
|
||||
"main": "src/index.ts",
|
||||
"repository": {
|
||||
|
@ -77,11 +77,11 @@
|
|||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"@apidevtools/swagger-parser": "10.0.3",
|
||||
"@budibase/backend-core": "1.2.58-alpha.4",
|
||||
"@budibase/client": "1.2.58-alpha.4",
|
||||
"@budibase/pro": "1.2.58-alpha.4",
|
||||
"@budibase/string-templates": "1.2.58-alpha.4",
|
||||
"@budibase/types": "1.2.58-alpha.4",
|
||||
"@budibase/backend-core": "1.2.58-alpha.5",
|
||||
"@budibase/client": "1.2.58-alpha.5",
|
||||
"@budibase/pro": "1.2.58-alpha.5",
|
||||
"@budibase/string-templates": "1.2.58-alpha.5",
|
||||
"@budibase/types": "1.2.58-alpha.5",
|
||||
"@bull-board/api": "3.7.0",
|
||||
"@bull-board/koa": "3.9.4",
|
||||
"@elastic/elasticsearch": "7.10.0",
|
||||
|
|
|
@ -1094,12 +1094,12 @@
|
|||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||
|
||||
"@budibase/backend-core@1.2.58-alpha.4":
|
||||
version "1.2.58-alpha.4"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.2.58-alpha.4.tgz#3c45ab2161b8da445edcbee009b4a80ee4da9dad"
|
||||
integrity sha512-gLNxqy44PoSZWxsuJeOYxkwsDPKO0Xz5Iuz0ZNiKRDgIw0A5AavqregwmuVUHIRiWes08RY4lFjOSdozQtI15A==
|
||||
"@budibase/backend-core@1.2.58-alpha.5":
|
||||
version "1.2.58-alpha.5"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.2.58-alpha.5.tgz#430699334629b3bd05a5066aa6660c1f68f047b2"
|
||||
integrity sha512-Z926rAp0eskXUr5UXGwh0S1OMDA3qzIi8o0GHLlO7KZAzk49RYzhRT/yo1fIst8Eq/9ZCaXLFxIeRkDmCJgILg==
|
||||
dependencies:
|
||||
"@budibase/types" "1.2.58-alpha.4"
|
||||
"@budibase/types" "1.2.58-alpha.5"
|
||||
"@techpass/passport-openidconnect" "0.3.2"
|
||||
aws-sdk "2.1030.0"
|
||||
bcrypt "5.0.1"
|
||||
|
@ -1178,13 +1178,13 @@
|
|||
svelte-flatpickr "^3.2.3"
|
||||
svelte-portal "^1.0.0"
|
||||
|
||||
"@budibase/pro@1.2.58-alpha.4":
|
||||
version "1.2.58-alpha.4"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.2.58-alpha.4.tgz#08c1d7c08522986c7a94f8e532374d7c39a83297"
|
||||
integrity sha512-Byvg/sXW9ZwAxd31Ps1ObG/D3vwtttPWr4e55O5ci7XBHDF0soenjwQlNT5FeW8T3RqMORCDUA4jqX6OMpzF0w==
|
||||
"@budibase/pro@1.2.58-alpha.5":
|
||||
version "1.2.58-alpha.5"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.2.58-alpha.5.tgz#1f739653e641ac32d20818517d35bef489ec2ae6"
|
||||
integrity sha512-owT7ipgZ588KAz6aHPJie5bLJX6EkhTRUvUQlyOJuLWt/hdXXnvbu+agxBQNaXE4gVzn916JJP0L0tbiMctjNA==
|
||||
dependencies:
|
||||
"@budibase/backend-core" "1.2.58-alpha.4"
|
||||
"@budibase/types" "1.2.58-alpha.4"
|
||||
"@budibase/backend-core" "1.2.58-alpha.5"
|
||||
"@budibase/types" "1.2.58-alpha.5"
|
||||
"@koa/router" "8.0.8"
|
||||
joi "17.6.0"
|
||||
node-fetch "^2.6.1"
|
||||
|
@ -1207,10 +1207,10 @@
|
|||
svelte-apexcharts "^1.0.2"
|
||||
svelte-flatpickr "^3.1.0"
|
||||
|
||||
"@budibase/types@1.2.58-alpha.4":
|
||||
version "1.2.58-alpha.4"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.2.58-alpha.4.tgz#21695d674f23f032311fb441d6a4e156b5008e0f"
|
||||
integrity sha512-OsJ6neUWhjok5480M2usOoYX1s3VyAnB+5N0E0Enb4N4XG/oVRbQQbxSlPFwrmTRpIXxgW/DufL52rVGCw8wcg==
|
||||
"@budibase/types@1.2.58-alpha.5":
|
||||
version "1.2.58-alpha.5"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.2.58-alpha.5.tgz#8ea99745f296a1076f878a06b7c228bc60886cd3"
|
||||
integrity sha512-0JhHDGvfcMcjhBckP3RqbKCDsMhx7ZVTV8wvaqsOaG7PnBSst9dxyX7ETVVzfvYolIK1eV11itsgx0FpbYID2w==
|
||||
|
||||
"@bull-board/api@3.7.0":
|
||||
version "3.7.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/string-templates",
|
||||
"version": "1.2.58-alpha.4",
|
||||
"version": "1.2.58-alpha.5",
|
||||
"description": "Handlebars wrapper for Budibase templating.",
|
||||
"main": "src/index.cjs",
|
||||
"module": "dist/bundle.mjs",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/types",
|
||||
"version": "1.2.58-alpha.4",
|
||||
"version": "1.2.58-alpha.5",
|
||||
"description": "Budibase types",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
|
|
@ -29,3 +29,15 @@ export interface BulkDeleteUsersResponse {
|
|||
successful: UserDetails[]
|
||||
unsuccessful: { _id: string; email: string; reason: string }[]
|
||||
}
|
||||
|
||||
export interface InviteUserRequest {
|
||||
email: string
|
||||
userInfo: any
|
||||
}
|
||||
|
||||
export type InviteUsersRequest = InviteUserRequest[]
|
||||
|
||||
export interface InviteUsersResponse {
|
||||
successful: { email: string }[]
|
||||
unsuccessful: { email: string; reason: string }[]
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/worker",
|
||||
"email": "hi@budibase.com",
|
||||
"version": "1.2.58-alpha.4",
|
||||
"version": "1.2.58-alpha.5",
|
||||
"description": "Budibase background service",
|
||||
"main": "src/index.ts",
|
||||
"repository": {
|
||||
|
@ -35,10 +35,10 @@
|
|||
"author": "Budibase",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"@budibase/backend-core": "1.2.58-alpha.4",
|
||||
"@budibase/pro": "1.2.58-alpha.4",
|
||||
"@budibase/string-templates": "1.2.58-alpha.4",
|
||||
"@budibase/types": "1.2.58-alpha.4",
|
||||
"@budibase/backend-core": "1.2.58-alpha.5",
|
||||
"@budibase/pro": "1.2.58-alpha.5",
|
||||
"@budibase/string-templates": "1.2.58-alpha.5",
|
||||
"@budibase/types": "1.2.58-alpha.5",
|
||||
"@koa/router": "8.0.8",
|
||||
"@sentry/node": "6.17.7",
|
||||
"@techpass/passport-openidconnect": "0.3.2",
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import { EmailTemplatePurpose } from "../../../constants"
|
||||
import { checkInviteCode } from "../../../utilities/redis"
|
||||
import { sendEmail } from "../../../utilities/email"
|
||||
import { users } from "../../../sdk"
|
||||
import env from "../../../environment"
|
||||
import { BulkDeleteUsersRequest, CloudAccount, User } from "@budibase/types"
|
||||
import {
|
||||
BulkDeleteUsersRequest,
|
||||
CloudAccount,
|
||||
InviteUserRequest,
|
||||
InviteUsersRequest,
|
||||
User,
|
||||
} from "@budibase/types"
|
||||
import {
|
||||
accounts,
|
||||
cache,
|
||||
|
@ -191,58 +195,27 @@ export const tenantUserLookup = async (ctx: any) => {
|
|||
}
|
||||
|
||||
export const invite = async (ctx: any) => {
|
||||
let { email, userInfo } = ctx.request.body
|
||||
const existing = await usersCore.getGlobalUserByEmail(email)
|
||||
if (existing) {
|
||||
ctx.throw(400, "Email address already in use.")
|
||||
const request = ctx.request.body as InviteUserRequest
|
||||
const response = await users.invite([request])
|
||||
|
||||
// explicitly throw for single user invite
|
||||
if (response.unsuccessful.length) {
|
||||
const reason = response.unsuccessful[0].reason
|
||||
if (reason === "Unavailable") {
|
||||
ctx.throw(400, reason)
|
||||
} else {
|
||||
ctx.throw(500, reason)
|
||||
}
|
||||
if (!userInfo) {
|
||||
userInfo = {}
|
||||
}
|
||||
userInfo.tenantId = tenancy.getTenantId()
|
||||
const opts: any = {
|
||||
subject: "{{ company }} platform invitation",
|
||||
info: userInfo,
|
||||
}
|
||||
await sendEmail(email, EmailTemplatePurpose.INVITATION, opts)
|
||||
|
||||
ctx.body = {
|
||||
message: "Invitation has been sent.",
|
||||
}
|
||||
await events.user.invited()
|
||||
}
|
||||
|
||||
export const inviteMultiple = async (ctx: any) => {
|
||||
let users = ctx.request.body
|
||||
let existing = false
|
||||
let existingEmail
|
||||
for (let user of users) {
|
||||
if (await usersCore.getGlobalUserByEmail(user.email)) {
|
||||
existing = true
|
||||
existingEmail = user.email
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (existing) {
|
||||
ctx.throw(400, `${existingEmail} already exists`)
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
await sendEmail(users[i].email, EmailTemplatePurpose.INVITATION, opts)
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
message: "Invitations have been sent.",
|
||||
}
|
||||
const request = ctx.request.body as InviteUsersRequest
|
||||
ctx.body = await users.invite(request)
|
||||
}
|
||||
|
||||
export const inviteAccept = async (ctx: any) => {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { InviteUsersResponse } from "@budibase/types"
|
||||
|
||||
jest.mock("nodemailer")
|
||||
import {
|
||||
TestConfiguration,
|
||||
|
@ -27,7 +29,8 @@ describe("/api/global/users", () => {
|
|||
|
||||
describe("invite", () => {
|
||||
it("should be able to generate an invitation", async () => {
|
||||
const { code, res } = await api.users.sendUserInvite(sendMailMock)
|
||||
const email = structures.users.newEmail()
|
||||
const { code, res } = await api.users.sendUserInvite(sendMailMock, email)
|
||||
|
||||
expect(res.body).toEqual({ message: "Invitation has been sent." })
|
||||
expect(sendMailMock).toHaveBeenCalled()
|
||||
|
@ -35,13 +38,27 @@ describe("/api/global/users", () => {
|
|||
expect(events.user.invited).toBeCalledTimes(1)
|
||||
})
|
||||
|
||||
it("should not be able to generate an invitation for existing user", async () => {
|
||||
const { code, res } = await api.users.sendUserInvite(
|
||||
sendMailMock,
|
||||
config.defaultUser!.email,
|
||||
400
|
||||
)
|
||||
|
||||
expect(res.body.message).toBe("Unavailable")
|
||||
expect(sendMailMock).toHaveBeenCalledTimes(0)
|
||||
expect(code).toBeUndefined()
|
||||
expect(events.user.invited).toBeCalledTimes(0)
|
||||
})
|
||||
|
||||
it("should be able to create new user from invite", async () => {
|
||||
const { code } = await api.users.sendUserInvite(sendMailMock)
|
||||
const email = structures.users.newEmail()
|
||||
const { code } = await api.users.sendUserInvite(sendMailMock, email)
|
||||
|
||||
const res = await api.users.acceptInvite(code)
|
||||
|
||||
expect(res.body._id).toBeDefined()
|
||||
const user = await config.getUser("invite@test.com")
|
||||
const user = await config.getUser(email)
|
||||
expect(user).toBeDefined()
|
||||
expect(user._id).toEqual(res.body._id)
|
||||
expect(events.user.inviteAccepted).toBeCalledTimes(1)
|
||||
|
@ -49,6 +66,37 @@ describe("/api/global/users", () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe("inviteMultiple", () => {
|
||||
it("should be able to generate an invitation", async () => {
|
||||
const newUserInvite = () => ({
|
||||
email: structures.users.newEmail(),
|
||||
userInfo: {},
|
||||
})
|
||||
const request = [newUserInvite(), newUserInvite()]
|
||||
|
||||
const res = await api.users.sendMultiUserInvite(request)
|
||||
|
||||
const body = res.body as InviteUsersResponse
|
||||
expect(body.successful.length).toBe(2)
|
||||
expect(body.unsuccessful.length).toBe(0)
|
||||
expect(sendMailMock).toHaveBeenCalledTimes(2)
|
||||
expect(events.user.invited).toBeCalledTimes(2)
|
||||
})
|
||||
|
||||
it("should not be able to generate an invitation for existing user", async () => {
|
||||
const request = [{ email: config.defaultUser!.email, userInfo: {} }]
|
||||
|
||||
const res = await api.users.sendMultiUserInvite(request)
|
||||
|
||||
const body = res.body as InviteUsersResponse
|
||||
expect(body.successful.length).toBe(0)
|
||||
expect(body.unsuccessful.length).toBe(1)
|
||||
expect(body.unsuccessful[0].reason).toBe("Unavailable")
|
||||
expect(sendMailMock).toHaveBeenCalledTimes(0)
|
||||
expect(events.user.invited).toBeCalledTimes(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("bulkCreate", () => {
|
||||
it("should ignore users existing in the same tenant", async () => {
|
||||
const user = await config.createUser()
|
||||
|
|
|
@ -16,12 +16,12 @@ import {
|
|||
migrations,
|
||||
StaticDatabases,
|
||||
ViewName,
|
||||
events,
|
||||
} from "@budibase/backend-core"
|
||||
import {
|
||||
MigrationType,
|
||||
PlatformUserByEmail,
|
||||
User,
|
||||
Account,
|
||||
BulkCreateUsersResponse,
|
||||
CreateUserResponse,
|
||||
BulkDeleteUsersResponse,
|
||||
|
@ -30,8 +30,12 @@ import {
|
|||
RowResponse,
|
||||
BulkDocsResponse,
|
||||
AccountMetadata,
|
||||
InviteUsersRequest,
|
||||
InviteUsersResponse,
|
||||
} from "@budibase/types"
|
||||
import { groups as groupUtils } from "@budibase/pro"
|
||||
import { sendEmail } from "../../utilities/email"
|
||||
import { EmailTemplatePurpose } from "../../constants"
|
||||
|
||||
const PAGE_LIMIT = 8
|
||||
|
||||
|
@ -551,3 +555,53 @@ const bulkDeleteProcessing = async (dbUser: User) => {
|
|||
// let server know to sync user
|
||||
await apps.syncUserInApps(userId)
|
||||
}
|
||||
|
||||
export const invite = async (
|
||||
users: InviteUsersRequest
|
||||
): Promise<InviteUsersResponse> => {
|
||||
const response: InviteUsersResponse = {
|
||||
successful: [],
|
||||
unsuccessful: [],
|
||||
}
|
||||
|
||||
const matchedEmails = await searchExistingEmails(users.map(u => u.email))
|
||||
const newUsers = []
|
||||
|
||||
// separate duplicates from new users
|
||||
for (let user of users) {
|
||||
if (matchedEmails.includes(user.email)) {
|
||||
response.unsuccessful.push({ email: user.email, reason: "Unavailable" })
|
||||
} else {
|
||||
newUsers.push(user)
|
||||
}
|
||||
}
|
||||
// overwrite users with new only
|
||||
users = newUsers
|
||||
|
||||
// send the emails for new users
|
||||
const tenantId = tenancy.getTenantId()
|
||||
for (let user of users) {
|
||||
try {
|
||||
let userInfo = user.userInfo
|
||||
if (!userInfo) {
|
||||
userInfo = {}
|
||||
}
|
||||
userInfo.tenantId = tenantId
|
||||
const opts: any = {
|
||||
subject: "{{ company }} platform invitation",
|
||||
info: userInfo,
|
||||
}
|
||||
await sendEmail(user.email, EmailTemplatePurpose.INVITATION, opts)
|
||||
response.successful.push({ email: user.email })
|
||||
await events.user.invited()
|
||||
} catch (e) {
|
||||
console.error(`Failed to send email invitation email=${user.email}`, e)
|
||||
response.unsuccessful.push({
|
||||
email: user.email,
|
||||
reason: "Failed to send email",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import {
|
|||
BulkCreateUsersResponse,
|
||||
BulkDeleteUsersRequest,
|
||||
CreateUserResponse,
|
||||
InviteUsersRequest,
|
||||
User,
|
||||
UserDetails,
|
||||
} from "@budibase/types"
|
||||
|
@ -19,17 +20,21 @@ export class UserAPI {
|
|||
|
||||
// INVITE
|
||||
|
||||
sendUserInvite = async (sendMailMock: any) => {
|
||||
sendUserInvite = async (sendMailMock: any, email: string, status = 200) => {
|
||||
await this.config.saveSmtpConfig()
|
||||
await this.config.saveSettingsConfig()
|
||||
const res = await this.request
|
||||
.post(`/api/global/users/invite`)
|
||||
.send({
|
||||
email: "invite@test.com",
|
||||
email,
|
||||
})
|
||||
.set(this.config.defaultHeaders())
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(200)
|
||||
.expect(status)
|
||||
|
||||
if (status !== 200) {
|
||||
return { code: undefined, res }
|
||||
}
|
||||
|
||||
const emailCall = sendMailMock.mock.calls[0][0]
|
||||
// after this URL there should be a code
|
||||
|
@ -51,6 +56,17 @@ export class UserAPI {
|
|||
.expect(200)
|
||||
}
|
||||
|
||||
sendMultiUserInvite = async (request: InviteUsersRequest, status = 200) => {
|
||||
await this.config.saveSmtpConfig()
|
||||
await this.config.saveSettingsConfig()
|
||||
return this.request
|
||||
.post(`/api/global/users/multi/invite`)
|
||||
.send(request)
|
||||
.set(this.config.defaultHeaders())
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(status)
|
||||
}
|
||||
|
||||
// BULK
|
||||
|
||||
bulkCreateUsers = async (users: User[], groups: any[] = []) => {
|
||||
|
|
|
@ -291,12 +291,12 @@
|
|||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||
|
||||
"@budibase/backend-core@1.2.58-alpha.4":
|
||||
version "1.2.58-alpha.4"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.2.58-alpha.4.tgz#3c45ab2161b8da445edcbee009b4a80ee4da9dad"
|
||||
integrity sha512-gLNxqy44PoSZWxsuJeOYxkwsDPKO0Xz5Iuz0ZNiKRDgIw0A5AavqregwmuVUHIRiWes08RY4lFjOSdozQtI15A==
|
||||
"@budibase/backend-core@1.2.58-alpha.5":
|
||||
version "1.2.58-alpha.5"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.2.58-alpha.5.tgz#430699334629b3bd05a5066aa6660c1f68f047b2"
|
||||
integrity sha512-Z926rAp0eskXUr5UXGwh0S1OMDA3qzIi8o0GHLlO7KZAzk49RYzhRT/yo1fIst8Eq/9ZCaXLFxIeRkDmCJgILg==
|
||||
dependencies:
|
||||
"@budibase/types" "1.2.58-alpha.4"
|
||||
"@budibase/types" "1.2.58-alpha.5"
|
||||
"@techpass/passport-openidconnect" "0.3.2"
|
||||
aws-sdk "2.1030.0"
|
||||
bcrypt "5.0.1"
|
||||
|
@ -325,21 +325,21 @@
|
|||
uuid "8.3.2"
|
||||
zlib "1.0.5"
|
||||
|
||||
"@budibase/pro@1.2.58-alpha.4":
|
||||
version "1.2.58-alpha.4"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.2.58-alpha.4.tgz#08c1d7c08522986c7a94f8e532374d7c39a83297"
|
||||
integrity sha512-Byvg/sXW9ZwAxd31Ps1ObG/D3vwtttPWr4e55O5ci7XBHDF0soenjwQlNT5FeW8T3RqMORCDUA4jqX6OMpzF0w==
|
||||
"@budibase/pro@1.2.58-alpha.5":
|
||||
version "1.2.58-alpha.5"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.2.58-alpha.5.tgz#1f739653e641ac32d20818517d35bef489ec2ae6"
|
||||
integrity sha512-owT7ipgZ588KAz6aHPJie5bLJX6EkhTRUvUQlyOJuLWt/hdXXnvbu+agxBQNaXE4gVzn916JJP0L0tbiMctjNA==
|
||||
dependencies:
|
||||
"@budibase/backend-core" "1.2.58-alpha.4"
|
||||
"@budibase/types" "1.2.58-alpha.4"
|
||||
"@budibase/backend-core" "1.2.58-alpha.5"
|
||||
"@budibase/types" "1.2.58-alpha.5"
|
||||
"@koa/router" "8.0.8"
|
||||
joi "17.6.0"
|
||||
node-fetch "^2.6.1"
|
||||
|
||||
"@budibase/types@1.2.58-alpha.4":
|
||||
version "1.2.58-alpha.4"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.2.58-alpha.4.tgz#21695d674f23f032311fb441d6a4e156b5008e0f"
|
||||
integrity sha512-OsJ6neUWhjok5480M2usOoYX1s3VyAnB+5N0E0Enb4N4XG/oVRbQQbxSlPFwrmTRpIXxgW/DufL52rVGCw8wcg==
|
||||
"@budibase/types@1.2.58-alpha.5":
|
||||
version "1.2.58-alpha.5"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.2.58-alpha.5.tgz#8ea99745f296a1076f878a06b7c228bc60886cd3"
|
||||
integrity sha512-0JhHDGvfcMcjhBckP3RqbKCDsMhx7ZVTV8wvaqsOaG7PnBSst9dxyX7ETVVzfvYolIK1eV11itsgx0FpbYID2w==
|
||||
|
||||
"@cspotcode/source-map-consumer@0.8.0":
|
||||
version "0.8.0"
|
||||
|
|
Loading…
Reference in New Issue