type tidy up and lint
This commit is contained in:
parent
ba52a901a9
commit
6d4e3082e3
|
@ -4,7 +4,8 @@ import env from "../environment"
|
||||||
import {
|
import {
|
||||||
PlatformUser,
|
PlatformUser,
|
||||||
PlatformUserByEmail,
|
PlatformUserByEmail,
|
||||||
PlatformUserById, PlatformUserBySsoId,
|
PlatformUserById,
|
||||||
|
PlatformUserBySsoId,
|
||||||
User,
|
User,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ function newUserSsoIdDoc(
|
||||||
ssoId: string,
|
ssoId: string,
|
||||||
email: string,
|
email: string,
|
||||||
userId: string,
|
userId: string,
|
||||||
tenantId: string,
|
tenantId: string
|
||||||
): PlatformUserBySsoId {
|
): PlatformUserBySsoId {
|
||||||
return {
|
return {
|
||||||
_id: ssoId,
|
_id: ssoId,
|
||||||
|
@ -78,14 +79,21 @@ async function addUserDoc(emailOrId: string, newDocFn: () => PlatformUser) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addUser(tenantId: string, userId: string, email: string, ssoId?: string) {
|
export async function addUser(
|
||||||
|
tenantId: string,
|
||||||
|
userId: string,
|
||||||
|
email: string,
|
||||||
|
ssoId?: string
|
||||||
|
) {
|
||||||
const promises = [
|
const promises = [
|
||||||
addUserDoc(userId, () => newUserIdDoc(userId, tenantId)),
|
addUserDoc(userId, () => newUserIdDoc(userId, tenantId)),
|
||||||
addUserDoc(email, () => newUserEmailDoc(userId, email, tenantId)),
|
addUserDoc(email, () => newUserEmailDoc(userId, email, tenantId)),
|
||||||
]
|
]
|
||||||
|
|
||||||
if (ssoId) {
|
if (ssoId) {
|
||||||
promises.push(addUserDoc(ssoId, () => newUserSsoIdDoc(ssoId, email, userId, tenantId)))
|
promises.push(
|
||||||
|
addUserDoc(ssoId, () => newUserSsoIdDoc(ssoId, email, userId, tenantId))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(promises)
|
await Promise.all(promises)
|
||||||
|
|
|
@ -278,7 +278,12 @@ export class UserDB {
|
||||||
builtUser._rev = response.rev
|
builtUser._rev = response.rev
|
||||||
|
|
||||||
await eventHelpers.handleSaveEvents(builtUser, dbUser)
|
await eventHelpers.handleSaveEvents(builtUser, dbUser)
|
||||||
await platform.users.addUser(tenantId, builtUser._id!, builtUser.email, builtUser.ssoId)
|
await platform.users.addUser(
|
||||||
|
tenantId,
|
||||||
|
builtUser._id!,
|
||||||
|
builtUser.email,
|
||||||
|
builtUser.ssoId
|
||||||
|
)
|
||||||
await cache.user.invalidateUser(response.id)
|
await cache.user.invalidateUser(response.id)
|
||||||
|
|
||||||
await Promise.all(groupPromises)
|
await Promise.all(groupPromises)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { generator, uuid, quotas } from "."
|
import { generator, quotas, uuid } from "."
|
||||||
import { generateGlobalUserID } from "../../../../src/docIds"
|
import { generateGlobalUserID } from "../../../../src/docIds"
|
||||||
import {
|
import {
|
||||||
Account,
|
Account,
|
||||||
|
@ -6,10 +6,11 @@ import {
|
||||||
AccountSSOProviderType,
|
AccountSSOProviderType,
|
||||||
AuthType,
|
AuthType,
|
||||||
CloudAccount,
|
CloudAccount,
|
||||||
Hosting,
|
|
||||||
SSOAccount,
|
|
||||||
CreateAccount,
|
CreateAccount,
|
||||||
CreatePassswordAccount,
|
CreatePassswordAccount,
|
||||||
|
CreateVerifiableSSOAccount,
|
||||||
|
Hosting,
|
||||||
|
SSOAccount,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import sample from "lodash/sample"
|
import sample from "lodash/sample"
|
||||||
|
|
||||||
|
@ -68,6 +69,23 @@ export function ssoAccount(account: Account = cloudAccount()): SSOAccount {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function verifiableSsoAccount(
|
||||||
|
account: Account = cloudAccount()
|
||||||
|
): SSOAccount {
|
||||||
|
return {
|
||||||
|
...account,
|
||||||
|
authType: AuthType.SSO,
|
||||||
|
oauth2: {
|
||||||
|
accessToken: generator.string(),
|
||||||
|
refreshToken: generator.string(),
|
||||||
|
},
|
||||||
|
pictureUrl: generator.url(),
|
||||||
|
provider: AccountSSOProvider.MICROSOFT,
|
||||||
|
providerType: AccountSSOProviderType.MICROSOFT,
|
||||||
|
thirdPartyProfile: { id: "abc123" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const cloudCreateAccount: CreatePassswordAccount = {
|
export const cloudCreateAccount: CreatePassswordAccount = {
|
||||||
email: "cloud@budibase.com",
|
email: "cloud@budibase.com",
|
||||||
tenantId: "cloud",
|
tenantId: "cloud",
|
||||||
|
@ -91,6 +109,19 @@ export const cloudSSOCreateAccount: CreateAccount = {
|
||||||
profession: "Software Engineer",
|
profession: "Software Engineer",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const cloudVerifiableSSOCreateAccount: CreateVerifiableSSOAccount = {
|
||||||
|
email: "cloud-sso@budibase.com",
|
||||||
|
tenantId: "cloud-sso",
|
||||||
|
hosting: Hosting.CLOUD,
|
||||||
|
authType: AuthType.SSO,
|
||||||
|
tenantName: "cloudsso",
|
||||||
|
name: "Budi Armstrong",
|
||||||
|
size: "10+",
|
||||||
|
profession: "Software Engineer",
|
||||||
|
provider: AccountSSOProvider.MICROSOFT,
|
||||||
|
thirdPartyProfile: { id: "abc123" },
|
||||||
|
}
|
||||||
|
|
||||||
export const selfCreateAccount: CreatePassswordAccount = {
|
export const selfCreateAccount: CreatePassswordAccount = {
|
||||||
email: "self@budibase.com",
|
email: "self@budibase.com",
|
||||||
tenantId: "self",
|
tenantId: "self",
|
||||||
|
|
|
@ -61,6 +61,7 @@ export interface CreateAdminUserRequest {
|
||||||
email: string
|
email: string
|
||||||
password: string
|
password: string
|
||||||
tenantId: string
|
tenantId: string
|
||||||
|
ssoId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateAdminUserResponse {
|
export interface CreateAdminUserResponse {
|
||||||
|
|
|
@ -94,9 +94,11 @@ export enum AccountSSOProvider {
|
||||||
MICROSOFT = "microsoft",
|
MICROSOFT = "microsoft",
|
||||||
}
|
}
|
||||||
|
|
||||||
const verifiableSSOProviders: AccountSSOProvider[] = [AccountSSOProvider.MICROSOFT]
|
const verifiableSSOProviders: AccountSSOProvider[] = [
|
||||||
|
AccountSSOProvider.MICROSOFT,
|
||||||
|
]
|
||||||
export function isVerifiableSSOProvider(provider: AccountSSOProvider): boolean {
|
export function isVerifiableSSOProvider(provider: AccountSSOProvider): boolean {
|
||||||
return verifiableSSOProviders.includes(provider);
|
return verifiableSSOProviders.includes(provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AccountSSO {
|
export interface AccountSSO {
|
||||||
|
|
|
@ -24,4 +24,7 @@ export interface PlatformUserBySsoId extends Document {
|
||||||
email: string
|
email: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PlatformUser = PlatformUserByEmail | PlatformUserById | PlatformUserBySsoId
|
export type PlatformUser =
|
||||||
|
| PlatformUserByEmail
|
||||||
|
| PlatformUserById
|
||||||
|
| PlatformUserBySsoId
|
||||||
|
|
|
@ -95,7 +95,6 @@ const parseBooleanParam = (param: any) => {
|
||||||
export const adminUser = async (
|
export const adminUser = async (
|
||||||
ctx: Ctx<CreateAdminUserRequest, CreateAdminUserResponse>
|
ctx: Ctx<CreateAdminUserRequest, CreateAdminUserResponse>
|
||||||
) => {
|
) => {
|
||||||
// @ts-ignore
|
|
||||||
const { email, password, tenantId, ssoId } = ctx.request.body
|
const { email, password, tenantId, ssoId } = ctx.request.body
|
||||||
|
|
||||||
if (await platform.tenants.exists(tenantId)) {
|
if (await platform.tenants.exists(tenantId)) {
|
||||||
|
@ -137,7 +136,6 @@ export const adminUser = async (
|
||||||
global: true,
|
global: true,
|
||||||
},
|
},
|
||||||
tenantId,
|
tenantId,
|
||||||
// @ts-ignore
|
|
||||||
ssoId,
|
ssoId,
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue