Update for worker, get builder endpoints working for app builders.
This commit is contained in:
parent
77f1bf1acf
commit
72438f531d
|
@ -1,4 +1,5 @@
|
|||
import { existsSync, readFileSync } from "fs"
|
||||
import { ServiceName } from "@budibase/types"
|
||||
|
||||
function isTest() {
|
||||
return isCypress() || isJest()
|
||||
|
@ -83,10 +84,20 @@ function getPackageJsonFields(): {
|
|||
}
|
||||
}
|
||||
|
||||
function isWorker() {
|
||||
return environment.SERVICE_NAME === ServiceName.WORKER
|
||||
}
|
||||
|
||||
function isApps() {
|
||||
return environment.SERVICE_NAME === ServiceName.APPS
|
||||
}
|
||||
|
||||
const environment = {
|
||||
isTest,
|
||||
isJest,
|
||||
isDev,
|
||||
isWorker,
|
||||
isApps,
|
||||
isProd: () => {
|
||||
return !isDev()
|
||||
},
|
||||
|
@ -153,6 +164,7 @@ const environment = {
|
|||
SMTP_FROM_ADDRESS: process.env.SMTP_FROM_ADDRESS,
|
||||
DISABLE_JWT_WARNING: process.env.DISABLE_JWT_WARNING,
|
||||
BLACKLIST_IPS: process.env.BLACKLIST_IPS,
|
||||
SERVICE_TYPE: "unknown",
|
||||
/**
|
||||
* Enable to allow an admin user to login using a password.
|
||||
* This can be useful to prevent lockout when configuring SSO.
|
||||
|
|
|
@ -1,9 +1,18 @@
|
|||
import { UserCtx } from "@budibase/types"
|
||||
import { isBuilder } from "../users"
|
||||
import { isBuilder, hasBuilderPermissions } from "../users"
|
||||
import { getAppId } from "../context"
|
||||
import env from "../environment"
|
||||
|
||||
export default async (ctx: UserCtx, next: any) => {
|
||||
const appId = getAppId()
|
||||
const builderFn = env.isWorker()
|
||||
? hasBuilderPermissions
|
||||
: env.isApps()
|
||||
? isBuilder
|
||||
: undefined
|
||||
if (!builderFn) {
|
||||
throw new Error("Service name unknown - middleware inactive.")
|
||||
}
|
||||
if (!ctx.internal && !isBuilder(ctx.user, appId)) {
|
||||
ctx.throw(403, "Builder user only endpoint.")
|
||||
}
|
||||
|
|
|
@ -1,10 +1,19 @@
|
|||
import { UserCtx } from "@budibase/types"
|
||||
import { isBuilder, isAdmin } from "../users"
|
||||
import { isBuilder, isAdmin, hasBuilderPermissions } from "../users"
|
||||
import { getAppId } from "../context"
|
||||
import env from "../environment"
|
||||
|
||||
export default async (ctx: UserCtx, next: any) => {
|
||||
const appId = getAppId()
|
||||
if (!ctx.internal && !isBuilder(ctx.user, appId) && !isAdmin(ctx.user)) {
|
||||
const builderFn = env.isWorker()
|
||||
? hasBuilderPermissions
|
||||
: env.isApps()
|
||||
? isBuilder
|
||||
: undefined
|
||||
if (!builderFn) {
|
||||
throw new Error("Service name unknown - middleware inactive.")
|
||||
}
|
||||
if (!ctx.internal && !builderFn(ctx.user, appId) && !isAdmin(ctx.user)) {
|
||||
ctx.throw(403, "Admin/Builder user only endpoint.")
|
||||
}
|
||||
return next()
|
||||
|
|
|
@ -15,7 +15,15 @@ import * as api from "./api"
|
|||
import * as automations from "./automations"
|
||||
import { Thread } from "./threads"
|
||||
import * as redis from "./utilities/redis"
|
||||
import { events, logging, middleware, timers } from "@budibase/backend-core"
|
||||
import { ServiceType } from "@budibase/types"
|
||||
import {
|
||||
events,
|
||||
logging,
|
||||
middleware,
|
||||
timers,
|
||||
env as coreEnv,
|
||||
} from "@budibase/backend-core"
|
||||
coreEnv._set("SERVICE_TYPE", ServiceType.APPS)
|
||||
import { startup } from "./startup"
|
||||
const Sentry = require("@sentry/node")
|
||||
const destroyable = require("server-destroy")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export * from "./installation"
|
|
@ -0,0 +1,4 @@
|
|||
export enum ServiceType {
|
||||
WORKER = "worker",
|
||||
APPS = "apps",
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
export * from "./documents"
|
||||
export * from "./sdk"
|
||||
export * from "./api"
|
||||
export * from "./core"
|
||||
|
|
|
@ -10,6 +10,7 @@ import Application from "koa"
|
|||
import { bootstrap } from "global-agent"
|
||||
import * as db from "./db"
|
||||
import { sdk as proSdk } from "@budibase/pro"
|
||||
import { ServiceType } from "@budibase/types"
|
||||
import {
|
||||
auth,
|
||||
logging,
|
||||
|
@ -19,6 +20,7 @@ import {
|
|||
env as coreEnv,
|
||||
timers,
|
||||
} from "@budibase/backend-core"
|
||||
coreEnv._set("SERVICE_TYPE", ServiceType.WORKER)
|
||||
db.init()
|
||||
import Koa from "koa"
|
||||
import koaBody from "koa-body"
|
||||
|
|
Loading…
Reference in New Issue