type tidy up and lint
This commit is contained in:
parent
ba52a901a9
commit
6d4e3082e3
|
@ -4,7 +4,8 @@ import env from "../environment"
|
|||
import {
|
||||
PlatformUser,
|
||||
PlatformUserByEmail,
|
||||
PlatformUserById, PlatformUserBySsoId,
|
||||
PlatformUserById,
|
||||
PlatformUserBySsoId,
|
||||
User,
|
||||
} from "@budibase/types"
|
||||
|
||||
|
@ -49,7 +50,7 @@ function newUserSsoIdDoc(
|
|||
ssoId: string,
|
||||
email: string,
|
||||
userId: string,
|
||||
tenantId: string,
|
||||
tenantId: string
|
||||
): PlatformUserBySsoId {
|
||||
return {
|
||||
_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 = [
|
||||
addUserDoc(userId, () => newUserIdDoc(userId, tenantId)),
|
||||
addUserDoc(email, () => newUserEmailDoc(userId, email, tenantId)),
|
||||
]
|
||||
|
||||
if (ssoId) {
|
||||
promises.push(addUserDoc(ssoId, () => newUserSsoIdDoc(ssoId, email, userId, tenantId)))
|
||||
promises.push(
|
||||
addUserDoc(ssoId, () => newUserSsoIdDoc(ssoId, email, userId, tenantId))
|
||||
)
|
||||
}
|
||||
|
||||
await Promise.all(promises)
|
||||
|
|
|
@ -278,7 +278,12 @@ export class UserDB {
|
|||
builtUser._rev = response.rev
|
||||
|
||||
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 Promise.all(groupPromises)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { generator, uuid, quotas } from "."
|
||||
import { generator, quotas, uuid } from "."
|
||||
import { generateGlobalUserID } from "../../../../src/docIds"
|
||||
import {
|
||||
Account,
|
||||
|
@ -6,10 +6,11 @@ import {
|
|||
AccountSSOProviderType,
|
||||
AuthType,
|
||||
CloudAccount,
|
||||
Hosting,
|
||||
SSOAccount,
|
||||
CreateAccount,
|
||||
CreatePassswordAccount,
|
||||
CreateVerifiableSSOAccount,
|
||||
Hosting,
|
||||
SSOAccount,
|
||||
} from "@budibase/types"
|
||||
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 = {
|
||||
email: "cloud@budibase.com",
|
||||
tenantId: "cloud",
|
||||
|
@ -91,6 +109,19 @@ export const cloudSSOCreateAccount: CreateAccount = {
|
|||
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 = {
|
||||
email: "self@budibase.com",
|
||||
tenantId: "self",
|
||||
|
|
|
@ -61,6 +61,7 @@ export interface CreateAdminUserRequest {
|
|||
email: string
|
||||
password: string
|
||||
tenantId: string
|
||||
ssoId?: string
|
||||
}
|
||||
|
||||
export interface CreateAdminUserResponse {
|
||||
|
|
|
@ -94,9 +94,11 @@ export enum AccountSSOProvider {
|
|||
MICROSOFT = "microsoft",
|
||||
}
|
||||
|
||||
const verifiableSSOProviders: AccountSSOProvider[] = [AccountSSOProvider.MICROSOFT]
|
||||
const verifiableSSOProviders: AccountSSOProvider[] = [
|
||||
AccountSSOProvider.MICROSOFT,
|
||||
]
|
||||
export function isVerifiableSSOProvider(provider: AccountSSOProvider): boolean {
|
||||
return verifiableSSOProviders.includes(provider);
|
||||
return verifiableSSOProviders.includes(provider)
|
||||
}
|
||||
|
||||
export interface AccountSSO {
|
||||
|
|
|
@ -24,4 +24,7 @@ export interface PlatformUserBySsoId extends Document {
|
|||
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 (
|
||||
ctx: Ctx<CreateAdminUserRequest, CreateAdminUserResponse>
|
||||
) => {
|
||||
// @ts-ignore
|
||||
const { email, password, tenantId, ssoId } = ctx.request.body
|
||||
|
||||
if (await platform.tenants.exists(tenantId)) {
|
||||
|
@ -137,7 +136,6 @@ export const adminUser = async (
|
|||
global: true,
|
||||
},
|
||||
tenantId,
|
||||
// @ts-ignore
|
||||
ssoId,
|
||||
}
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue