move worker middleware to backend-core
This commit is contained in:
parent
710e71d7b8
commit
8a066fb1cb
|
@ -18,6 +18,8 @@ const {
|
||||||
ssoCallbackUrl,
|
ssoCallbackUrl,
|
||||||
csrf,
|
csrf,
|
||||||
internalApi,
|
internalApi,
|
||||||
|
adminOnly,
|
||||||
|
joiValidator,
|
||||||
} = require("./middleware")
|
} = require("./middleware")
|
||||||
|
|
||||||
const { invalidateUser } = require("./cache/user")
|
const { invalidateUser } = require("./cache/user")
|
||||||
|
@ -173,4 +175,6 @@ module.exports = {
|
||||||
refreshOAuthToken,
|
refreshOAuthToken,
|
||||||
updateUserOAuth,
|
updateUserOAuth,
|
||||||
ssoCallbackUrl,
|
ssoCallbackUrl,
|
||||||
|
adminOnly,
|
||||||
|
joiValidator,
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
module.exports = async (ctx, next) => {
|
||||||
|
if (
|
||||||
|
!ctx.internal &&
|
||||||
|
(!ctx.user || !ctx.user.admin || !ctx.user.admin.global)
|
||||||
|
) {
|
||||||
|
ctx.throw(403, "Admin user only endpoint.")
|
||||||
|
}
|
||||||
|
return next()
|
||||||
|
}
|
|
@ -9,7 +9,8 @@ const tenancy = require("./tenancy")
|
||||||
const internalApi = require("./internalApi")
|
const internalApi = require("./internalApi")
|
||||||
const datasourceGoogle = require("./passport/datasource/google")
|
const datasourceGoogle = require("./passport/datasource/google")
|
||||||
const csrf = require("./csrf")
|
const csrf = require("./csrf")
|
||||||
|
const adminOnly = require("./adminOnly")
|
||||||
|
const joiValidator = require("./joi-validator")
|
||||||
module.exports = {
|
module.exports = {
|
||||||
google,
|
google,
|
||||||
oidc,
|
oidc,
|
||||||
|
@ -25,4 +26,6 @@ module.exports = {
|
||||||
google: datasourceGoogle,
|
google: datasourceGoogle,
|
||||||
},
|
},
|
||||||
csrf,
|
csrf,
|
||||||
|
adminOnly,
|
||||||
|
joiValidator,
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
function validate(schema, property) {
|
||||||
|
// Return a Koa middleware function
|
||||||
|
return (ctx, next) => {
|
||||||
|
if (!schema) {
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
let params = null
|
||||||
|
if (ctx[property] != null) {
|
||||||
|
params = ctx[property]
|
||||||
|
} else if (ctx.request[property] != null) {
|
||||||
|
params = ctx.request[property]
|
||||||
|
}
|
||||||
|
const { error } = schema.validate(params)
|
||||||
|
if (error) {
|
||||||
|
ctx.throw(400, `Invalid ${property} - ${error.message}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.body = schema => {
|
||||||
|
return validate(schema, "body")
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.params = schema => {
|
||||||
|
return validate(schema, "params")
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
const joiValidator = require("../../../middleware/joi-validator")
|
const { joiValidator } = require("@budibase/backend-core/auth")
|
||||||
const Joi = require("joi")
|
const Joi = require("joi")
|
||||||
|
|
||||||
const OPTIONAL_STRING = Joi.string().optional().allow(null).allow("")
|
const OPTIONAL_STRING = Joi.string().optional().allow(null).allow("")
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const joiValidator = require("../../../middleware/joi-validator")
|
const { joiValidator } = require("@budibase/backend-core/auth")
|
||||||
const { DataSourceOperation } = require("../../../constants")
|
const { DataSourceOperation } = require("../../../constants")
|
||||||
const { WebhookType } = require("../../../constants")
|
const { WebhookType } = require("../../../constants")
|
||||||
const {
|
const {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const authController = require("../../controllers/global/auth")
|
const authController = require("../../controllers/global/auth")
|
||||||
const joiValidator = require("../../../middleware/joi-validator")
|
const { joiValidator } = require("@budibase/backend-core/auth")
|
||||||
const Joi = require("joi")
|
const Joi = require("joi")
|
||||||
const { updateTenantId } = require("@budibase/backend-core/tenancy")
|
const { updateTenantId } = require("@budibase/backend-core/tenancy")
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/global/configs")
|
const controller = require("../../controllers/global/configs")
|
||||||
const joiValidator = require("../../../middleware/joi-validator")
|
const { joiValidator } = require("@budibase/backend-core/auth")
|
||||||
const adminOnly = require("../../../middleware/adminOnly")
|
const { adminOnly } = require("@budibase/backend-core/auth")
|
||||||
const Joi = require("joi")
|
const Joi = require("joi")
|
||||||
const { Configs } = require("../../../constants")
|
const { Configs } = require("../../../constants")
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/global/email")
|
const controller = require("../../controllers/global/email")
|
||||||
const { EmailTemplatePurpose } = require("../../../constants")
|
const { EmailTemplatePurpose } = require("../../../constants")
|
||||||
const joiValidator = require("../../../middleware/joi-validator")
|
const { joiValidator } = require("@budibase/backend-core/auth")
|
||||||
const adminOnly = require("../../../middleware/adminOnly")
|
const { adminOnly } = require("@budibase/backend-core/auth")
|
||||||
const Joi = require("joi")
|
const Joi = require("joi")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/global/roles")
|
const controller = require("../../controllers/global/roles")
|
||||||
const adminOnly = require("../../../middleware/adminOnly")
|
const { adminOnly } = require("@budibase/backend-core/auth")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/global/sessions")
|
const controller = require("../../controllers/global/sessions")
|
||||||
const adminOnly = require("../../../middleware/adminOnly")
|
const { adminOnly } = require("@budibase/backend-core/auth")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/global/templates")
|
const controller = require("../../controllers/global/templates")
|
||||||
const joiValidator = require("../../../middleware/joi-validator")
|
const { joiValidator } = require("@budibase/backend-core/auth")
|
||||||
const Joi = require("joi")
|
const Joi = require("joi")
|
||||||
const { TemplatePurpose, TemplateTypes } = require("../../../constants")
|
const { TemplatePurpose, TemplateTypes } = require("../../../constants")
|
||||||
const adminOnly = require("../../../middleware/adminOnly")
|
const { adminOnly } = require("@budibase/backend-core/auth")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/global/users")
|
const controller = require("../../controllers/global/users")
|
||||||
const joiValidator = require("../../../middleware/joi-validator")
|
const { joiValidator } = require("@budibase/backend-core/auth")
|
||||||
const adminOnly = require("../../../middleware/adminOnly")
|
const { adminOnly } = require("@budibase/backend-core/auth")
|
||||||
const Joi = require("joi")
|
const Joi = require("joi")
|
||||||
const cloudRestricted = require("../../../middleware/cloudRestricted")
|
const cloudRestricted = require("../../../middleware/cloudRestricted")
|
||||||
const { users } = require("../validation")
|
const { users } = require("../validation")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/global/workspaces")
|
const controller = require("../../controllers/global/workspaces")
|
||||||
const joiValidator = require("../../../middleware/joi-validator")
|
const { joiValidator } = require("@budibase/backend-core/auth")
|
||||||
const adminOnly = require("../../../middleware/adminOnly")
|
const { adminOnly } = require("@budibase/backend-core/auth")
|
||||||
const Joi = require("joi")
|
const Joi = require("joi")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/system/tenants")
|
const controller = require("../../controllers/system/tenants")
|
||||||
const adminOnly = require("../../../middleware/adminOnly")
|
const { adminOnly } = require("@budibase/backend-core/auth")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue