adding limits for uploading users
This commit is contained in:
parent
9e75b18784
commit
cd426a5ca7
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
const BYTES_IN_MB = 1000000
|
const BYTES_IN_MB = 1000000
|
||||||
const FILE_SIZE_LIMIT = BYTES_IN_MB * 5
|
const FILE_SIZE_LIMIT = BYTES_IN_MB * 5
|
||||||
|
const MAX_USERS_UPLOAD_LIMIT = 1000
|
||||||
export let createUsersFromCsv
|
export let createUsersFromCsv
|
||||||
|
|
||||||
let files = []
|
let files = []
|
||||||
|
@ -27,6 +27,12 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
const validEmails = userEmails => {
|
const validEmails = userEmails => {
|
||||||
|
if (userEmails.length > MAX_USERS_UPLOAD_LIMIT) {
|
||||||
|
notifications.error(
|
||||||
|
`Max limit for upload is 1000 users. Please reduce file size and try again.`
|
||||||
|
)
|
||||||
|
return false
|
||||||
|
}
|
||||||
for (const email of userEmails) {
|
for (const email of userEmails) {
|
||||||
if (emailValidator(email) !== true) invalidEmails.push(email)
|
if (emailValidator(email) !== true) invalidEmails.push(email)
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,8 +123,8 @@
|
||||||
try {
|
try {
|
||||||
const res = await users.invite({
|
const res = await users.invite({
|
||||||
emails: emails,
|
emails: emails,
|
||||||
builder: true,
|
builder: false,
|
||||||
admin: true,
|
admin: false,
|
||||||
})
|
})
|
||||||
notifications.success(res.message)
|
notifications.success(res.message)
|
||||||
inviteConfirmationModal.show()
|
inviteConfirmationModal.show()
|
||||||
|
|
|
@ -14,6 +14,8 @@ import {
|
||||||
} from "@budibase/backend-core"
|
} from "@budibase/backend-core"
|
||||||
import { checkAnyUserExists } from "../../../utilities/users"
|
import { checkAnyUserExists } from "../../../utilities/users"
|
||||||
|
|
||||||
|
const MAX_USERS_UPLOAD_LIMIT = 1000
|
||||||
|
|
||||||
export const save = async (ctx: any) => {
|
export const save = async (ctx: any) => {
|
||||||
try {
|
try {
|
||||||
ctx.body = await users.save(ctx.request.body)
|
ctx.body = await users.save(ctx.request.body)
|
||||||
|
@ -24,6 +26,14 @@ export const save = async (ctx: any) => {
|
||||||
|
|
||||||
export const bulkCreate = async (ctx: any) => {
|
export const bulkCreate = async (ctx: any) => {
|
||||||
let { users: newUsersRequested, groups } = ctx.request.body
|
let { users: newUsersRequested, groups } = ctx.request.body
|
||||||
|
|
||||||
|
if (!env.SELF_HOSTED && newUsersRequested.length > MAX_USERS_UPLOAD_LIMIT) {
|
||||||
|
ctx.throw(
|
||||||
|
400,
|
||||||
|
"Max limit for upload is 1000 users. Please reduce file size and try again."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const db = tenancy.getGlobalDB()
|
const db = tenancy.getGlobalDB()
|
||||||
let groupsToSave: any[] = []
|
let groupsToSave: any[] = []
|
||||||
|
|
||||||
|
@ -275,7 +285,11 @@ export const inviteMultiple = async (ctx: any) => {
|
||||||
subject: "{{ company }} platform invitation",
|
subject: "{{ company }} platform invitation",
|
||||||
info: userInfo,
|
info: userInfo,
|
||||||
}
|
}
|
||||||
await sendEmail(emails, EmailTemplatePurpose.INVITATION, opts)
|
|
||||||
|
for (let i = 0; i < emails.length; i++) {
|
||||||
|
await sendEmail(emails[i], EmailTemplatePurpose.INVITATION, opts)
|
||||||
|
}
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
message: "Invitations have been sent.",
|
message: "Invitations have been sent.",
|
||||||
}
|
}
|
||||||
|
@ -300,6 +314,7 @@ export const inviteAccept = async (ctx: any) => {
|
||||||
return saved
|
return saved
|
||||||
})
|
})
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
console.log(err)
|
||||||
if (err.code === errors.codes.USAGE_LIMIT_EXCEEDED) {
|
if (err.code === errors.codes.USAGE_LIMIT_EXCEEDED) {
|
||||||
// explicitly re-throw limit exceeded errors
|
// explicitly re-throw limit exceeded errors
|
||||||
ctx.throw(400, err)
|
ctx.throw(400, err)
|
||||||
|
|
|
@ -194,16 +194,9 @@ exports.sendEmail = async (
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
if (email.length > 1) {
|
message = {
|
||||||
message = {
|
...message,
|
||||||
...message,
|
to: email,
|
||||||
bcc: email,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
message = {
|
|
||||||
...message,
|
|
||||||
to: email,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subject || config.subject) {
|
if (subject || config.subject) {
|
||||||
|
|
Loading…
Reference in New Issue