Reject inviting the same user twice.
This commit is contained in:
parent
3f69b17c94
commit
a6a75b533c
|
@ -349,14 +349,12 @@ export const checkInvite = async (ctx: any) => {
|
|||
}
|
||||
|
||||
export const getUserInvites = async (ctx: any) => {
|
||||
let invites
|
||||
try {
|
||||
// Restricted to the currently authenticated tenant
|
||||
invites = await getInviteCodes()
|
||||
ctx.body = await getInviteCodes()
|
||||
} catch (e) {
|
||||
ctx.throw(400, "There was a problem fetching invites")
|
||||
}
|
||||
ctx.body = invites
|
||||
}
|
||||
|
||||
export const updateInvite = async (ctx: any) => {
|
||||
|
|
|
@ -59,6 +59,8 @@ describe("/api/global/users", () => {
|
|||
const email = structures.users.newEmail()
|
||||
await config.api.users.sendUserInvite(sendMailMock, email)
|
||||
|
||||
jest.clearAllMocks()
|
||||
|
||||
const { code, res } = await config.api.users.sendUserInvite(
|
||||
sendMailMock,
|
||||
email,
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import { events, tenancy, users as usersCore } from "@budibase/backend-core"
|
||||
import { InviteUsersRequest, InviteUsersResponse } from "@budibase/types"
|
||||
import {
|
||||
InviteUserRequest,
|
||||
InviteUsersRequest,
|
||||
InviteUsersResponse,
|
||||
} from "@budibase/types"
|
||||
import { sendEmail } from "../../utilities/email"
|
||||
import { EmailTemplatePurpose } from "../../constants"
|
||||
import { getInviteCodes } from "../..//utilities/redis"
|
||||
|
@ -15,12 +19,17 @@ export async function invite(
|
|||
const matchedEmails = await usersCore.searchExistingEmails(
|
||||
users.map(u => u.email)
|
||||
)
|
||||
const existingInvites = await getInviteCodes()
|
||||
const newUsers = []
|
||||
const invitedEmails = (await getInviteCodes()).map(invite => invite.email)
|
||||
const newUsers: InviteUserRequest[] = []
|
||||
|
||||
// separate duplicates from new users
|
||||
for (let user of users) {
|
||||
if (matchedEmails.includes(user.email)) {
|
||||
if (
|
||||
matchedEmails.includes(user.email) ||
|
||||
invitedEmails.includes(user.email)
|
||||
) {
|
||||
// This "Unavailable" is load bearing. The tests and frontend both check for it
|
||||
// specifically
|
||||
response.unsuccessful.push({ email: user.email, reason: "Unavailable" })
|
||||
} else {
|
||||
newUsers.push(user)
|
||||
|
|
|
@ -66,7 +66,11 @@ async function writeCode(db: RedisDBName, value: Invite | PasswordReset) {
|
|||
return code
|
||||
}
|
||||
|
||||
async function updateCode(db: RedisDBName, code: string, value: any) {
|
||||
async function updateCode(
|
||||
db: RedisDBName,
|
||||
code: string,
|
||||
value: Invite | PasswordReset
|
||||
) {
|
||||
const client = getClient(db)
|
||||
await client.store(code, value, getExpirySecondsForDB(db))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue