Fix users not being added to group when invited via email

This commit is contained in:
Andrew Kingston 2022-08-08 16:40:32 +01:00
parent 43b6fd3055
commit b9cc7a83c8
5 changed files with 27 additions and 7 deletions

View File

@ -111,6 +111,7 @@
email: user.email,
builder: user.role === Constants.BudibaseRoles.Developer,
admin: user.role === Constants.BudibaseRoles.Admin,
groups: userData.groups,
}))
try {
const res = await users.invite(payload)

View File

@ -151,6 +151,7 @@ export const buildUserEndpoints = API => ({
userInfo: {
admin: user.admin ? { global: true } : undefined,
builder: user.admin || user.builder ? { global: true } : undefined,
groups: user.groups,
},
})),
})

View File

@ -20,6 +20,12 @@ export default class UserFetch extends DataFetch {
}
}
async getDefinition() {
return {
schema: {},
}
}
async getData() {
const { cursor, query } = get(this.store)
try {

View File

@ -3,7 +3,7 @@ import { checkInviteCode } from "../../../utilities/redis"
import { sendEmail } from "../../../utilities/email"
import { users } from "../../../sdk"
import env from "../../../environment"
import { CloudAccount, User } from "@budibase/types"
import { CloudAccount, groupUser, User, UserGroup } from "@budibase/types"
import {
accounts,
cache,
@ -263,6 +263,24 @@ export const inviteAccept = async (ctx: any) => {
const db = tenancy.getGlobalDB()
const user = await db.get(saved._id)
await events.user.inviteAccepted(user)
// add user to groups if required
if (info.groups?.length) {
let groups: UserGroup[] = []
for (const groupId of info.groups) {
try {
let group: UserGroup = await db.get(groupId)
if (group) {
groups.push(group)
}
} catch (error) {
// group was probably deleted
}
}
const groupUser: groupUser = { _id: saved._id, email: saved.email }
await groupUtils.bulkSaveGroupUsers(groups, [groupUser])
}
return saved
})
} catch (err: any) {

View File

@ -74,12 +74,6 @@ router
buildInviteValidation(),
controller.invite
)
.post(
"/api/global/users/invite",
adminOnly,
buildInviteValidation(),
controller.invite
)
.post(
"/api/global/users/multi/invite",
adminOnly,