Clean code

This commit is contained in:
adrinr 2023-03-27 11:10:30 +01:00
parent 04bd9dda9c
commit 099cc145bf
5 changed files with 2 additions and 19 deletions

View File

@ -19,12 +19,7 @@ export function doInIdentityContext(identity: IdentityContext, task: any) {
} }
// used in server/worker // used in server/worker
export function doInUserContext( export function doInUserContext(user: User, ctx: Ctx, task: any) {
user: User,
ctx: Ctx,
task: any,
isScim: boolean
) {
const userContext: UserContext = { const userContext: UserContext = {
...user, ...user,
_id: user._id as string, _id: user._id as string,
@ -34,7 +29,6 @@ export function doInUserContext(
// filled in by koa-useragent package // filled in by koa-useragent package
userAgent: ctx.userAgent._agent.source, userAgent: ctx.userAgent._agent.source,
}, },
isScimCall: isScim,
} }
return doInIdentityContext(userContext, task) return doInIdentityContext(userContext, task)
} }

View File

@ -4,7 +4,6 @@ import {
clearCookie, clearCookie,
openJwt, openJwt,
isValidInternalAPIKey, isValidInternalAPIKey,
isScimEndpoint,
} from "../utils" } from "../utils"
import { getUser } from "../cache/user" import { getUser } from "../cache/user"
import { getSession, updateSessionTTL } from "../security/sessions" import { getSession, updateSessionTTL } from "../security/sessions"
@ -106,8 +105,6 @@ export default function (
apiKey = ctx.request.headers[Header.AUTHORIZATION].split(" ")[1] apiKey = ctx.request.headers[Header.AUTHORIZATION].split(" ")[1]
} }
const isScimCall = isScimEndpoint(ctx)
const tenantId = ctx.request.headers[Header.TENANT_ID] const tenantId = ctx.request.headers[Header.TENANT_ID]
let authenticated = false, let authenticated = false,
user = null, user = null,
@ -171,7 +168,7 @@ export default function (
finalise(ctx, { authenticated, user, internal, version, publicEndpoint }) finalise(ctx, { authenticated, user, internal, version, publicEndpoint })
if (user && user.email) { if (user && user.email) {
return identity.doInUserContext(user, ctx, next, isScimCall) return identity.doInUserContext(user, ctx, next)
} else { } else {
return next() return next()
} }

View File

@ -1,6 +0,0 @@
import { Ctx } from "@budibase/types"
const SCIM_ENDPOINTS = new RegExp(["scim/"].join("|"))
export function isScimEndpoint(ctx: Ctx): boolean {
return SCIM_ENDPOINTS.test(ctx.request.url)
}

View File

@ -1,3 +1,2 @@
export * from "./hashing" export * from "./hashing"
export * from "./utils" export * from "./utils"
export * from "./endpointUtils"

View File

@ -17,7 +17,6 @@ export interface UserContext extends BaseContext, User {
tenantId: string tenantId: string
account?: Account account?: Account
hostInfo: HostInfo hostInfo: HostInfo
isScimCall?: boolean
} }
export type IdentityContext = BaseContext | AccountUserContext | UserContext export type IdentityContext = BaseContext | AccountUserContext | UserContext