PR comments
This commit is contained in:
parent
493706d9e3
commit
096da509d9
|
@ -1,4 +1,5 @@
|
|||
import { doWithDB } from "../db"
|
||||
import { queryPlatformView } from "../db/views"
|
||||
import { StaticDatabases, ViewName } from "../db/constants"
|
||||
import { baseGlobalDBName } from "./utils"
|
||||
import {
|
||||
|
@ -8,7 +9,6 @@ import {
|
|||
getTenantIDFromAppID,
|
||||
} from "../context"
|
||||
import env from "../environment"
|
||||
import { queryPlatformView } from "../db"
|
||||
|
||||
const TENANT_DOC = StaticDatabases.PLATFORM_INFO.docs.tenants
|
||||
const PLATFORM_INFO_DB = StaticDatabases.PLATFORM_INFO.name
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -23,6 +23,7 @@
|
|||
"dev:stack:init": "node ./scripts/dev/manage.js init",
|
||||
"dev:builder": "npm run dev:stack:init && nodemon",
|
||||
"test": "jest --runInBand",
|
||||
"test:watch": "jest --watch",
|
||||
"env:multi:enable": "node scripts/multiTenancy.js enable",
|
||||
"env:multi:disable": "node scripts/multiTenancy.js disable",
|
||||
"env:selfhost:enable": "node scripts/selfhost.js enable",
|
||||
|
|
|
@ -242,6 +242,26 @@ describe("/api/global/users", () => {
|
|||
expect(response.body.message).toBe(`Unavailable`)
|
||||
expect(events.user.created).toBeCalledTimes(0)
|
||||
})
|
||||
|
||||
it("should not be able to create a user with the same email and different casing", async () => {
|
||||
const user = structures.users.user()
|
||||
await api.users.saveUser(user)
|
||||
|
||||
user.email = user.email.toUpperCase()
|
||||
await api.users.saveUser(user)
|
||||
|
||||
expect(events.user.created).toBeCalledTimes(1)
|
||||
})
|
||||
|
||||
it("should not be able to bulk create a user with the same email and different casing", async () => {
|
||||
const user = structures.users.user()
|
||||
await api.users.saveUser(user)
|
||||
|
||||
user.email = user.email.toUpperCase()
|
||||
await api.users.bulkCreateUsers([user])
|
||||
|
||||
expect(events.user.created).toBeCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe("update", () => {
|
||||
|
|
|
@ -267,8 +267,9 @@ export const addTenant = async (
|
|||
}
|
||||
|
||||
const getExistingTenantUsers = async (emails: string[]): Promise<User[]> => {
|
||||
const lcEmails = emails.map(email => email.toLowerCase())
|
||||
return dbUtils.queryGlobalView(ViewName.USER_BY_EMAIL, {
|
||||
keys: emails,
|
||||
keys: lcEmails,
|
||||
include_docs: true,
|
||||
arrayResponse: true,
|
||||
})
|
||||
|
@ -277,8 +278,9 @@ const getExistingTenantUsers = async (emails: string[]): Promise<User[]> => {
|
|||
const getExistingPlatformUsers = async (
|
||||
emails: string[]
|
||||
): Promise<PlatformUserByEmail[]> => {
|
||||
const lcEmails = emails.map(email => email.toLowerCase())
|
||||
return dbUtils.queryPlatformView(ViewName.PLATFORM_USERS_LOWERCASE, {
|
||||
keys: emails.map(email => email.toLowerCase()),
|
||||
keys: lcEmails,
|
||||
include_docs: true,
|
||||
arrayResponse: true,
|
||||
})
|
||||
|
@ -287,8 +289,9 @@ const getExistingPlatformUsers = async (
|
|||
const getExistingAccounts = async (
|
||||
emails: string[]
|
||||
): Promise<AccountMetadata[]> => {
|
||||
const lcEmails = emails.map(email => email.toLowerCase())
|
||||
return dbUtils.queryPlatformView(ViewName.ACCOUNT_BY_EMAIL, {
|
||||
keys: emails,
|
||||
keys: lcEmails,
|
||||
include_docs: true,
|
||||
arrayResponse: true,
|
||||
})
|
||||
|
@ -333,7 +336,7 @@ export const bulkCreate = async (
|
|||
for (const newUser of newUsersRequested) {
|
||||
if (
|
||||
newUsers.find(
|
||||
(x: any) => x.email.toLowerCase() === newUser.email.toLowerCase()
|
||||
(x: User) => x.email.toLowerCase() === newUser.email.toLowerCase()
|
||||
) ||
|
||||
existingEmails.includes(newUser.email.toLowerCase())
|
||||
) {
|
||||
|
|
Loading…
Reference in New Issue