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 fbbba2e32e
commit 6302ee5551
5 changed files with 27 additions and 7 deletions

View File

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

View File

@ -151,6 +151,7 @@ export const buildUserEndpoints = API => ({
userInfo: { userInfo: {
admin: user.admin ? { global: true } : undefined, admin: user.admin ? { global: true } : undefined,
builder: user.admin || user.builder ? { 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() { async getData() {
const { cursor, query } = get(this.store) const { cursor, query } = get(this.store)
try { try {

View File

@ -3,7 +3,7 @@ import { checkInviteCode } from "../../../utilities/redis"
import { sendEmail } from "../../../utilities/email" import { sendEmail } from "../../../utilities/email"
import { users } from "../../../sdk" import { users } from "../../../sdk"
import env from "../../../environment" import env from "../../../environment"
import { CloudAccount, User } from "@budibase/types" import { CloudAccount, groupUser, User, UserGroup } from "@budibase/types"
import { import {
accounts, accounts,
cache, cache,
@ -263,6 +263,24 @@ export const inviteAccept = async (ctx: any) => {
const db = tenancy.getGlobalDB() const db = tenancy.getGlobalDB()
const user = await db.get(saved._id) const user = await db.get(saved._id)
await events.user.inviteAccepted(user) 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 return saved
}) })
} catch (err: any) { } catch (err: any) {

View File

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