Updating administration middleware so that internal requests allowed through automatically.
This commit is contained in:
parent
27fc3a3c5e
commit
c6a6d49cd7
|
@ -43,6 +43,7 @@ module.exports = (noAuthPatterns = [], opts) => {
|
||||||
// this is an internal request, no user made it
|
// this is an internal request, no user made it
|
||||||
if (apiKey && apiKey === env.INTERNAL_API_KEY) {
|
if (apiKey && apiKey === env.INTERNAL_API_KEY) {
|
||||||
ctx.isAuthenticated = true
|
ctx.isAuthenticated = true
|
||||||
|
ctx.internal = true
|
||||||
} else if (authCookie) {
|
} else if (authCookie) {
|
||||||
try {
|
try {
|
||||||
const db = database.getDB(StaticDatabases.GLOBAL.name)
|
const db = database.getDB(StaticDatabases.GLOBAL.name)
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
const schema = {
|
const schema = {
|
||||||
email: {},
|
email: {},
|
||||||
developmentAccess: { displayName: "Development Access", type: "boolean" },
|
developmentAccess: { displayName: "Development Access", type: "boolean" },
|
||||||
|
adminAccess: { displayName: "Admin Access", type: "boolean" },
|
||||||
// role: { type: "options" },
|
// role: { type: "options" },
|
||||||
group: {},
|
group: {},
|
||||||
// access: {},
|
// access: {},
|
||||||
|
@ -36,6 +37,7 @@
|
||||||
...user,
|
...user,
|
||||||
group: ["All users"],
|
group: ["All users"],
|
||||||
developmentAccess: user.builder.global,
|
developmentAccess: user.builder.global,
|
||||||
|
adminAccess: user.admin.global,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
let createUserModal
|
let createUserModal
|
||||||
|
|
|
@ -2,6 +2,7 @@ const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/admin/email")
|
const controller = require("../../controllers/admin/email")
|
||||||
const { EmailTemplatePurpose } = require("../../../constants")
|
const { EmailTemplatePurpose } = require("../../../constants")
|
||||||
const joiValidator = require("../../../middleware/joi-validator")
|
const joiValidator = require("../../../middleware/joi-validator")
|
||||||
|
const adminOnly = require("../../../middleware/adminOnly")
|
||||||
const Joi = require("joi")
|
const Joi = require("joi")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
@ -21,6 +22,7 @@ function buildEmailSendValidation() {
|
||||||
router.post(
|
router.post(
|
||||||
"/api/admin/email/send",
|
"/api/admin/email/send",
|
||||||
buildEmailSendValidation(),
|
buildEmailSendValidation(),
|
||||||
|
adminOnly,
|
||||||
controller.sendEmail
|
controller.sendEmail
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -54,16 +54,9 @@ router
|
||||||
buildUserSaveValidation(),
|
buildUserSaveValidation(),
|
||||||
controller.save
|
controller.save
|
||||||
)
|
)
|
||||||
.get("/api/admin/users", controller.fetch)
|
.get("/api/admin/users", adminOnly, controller.fetch)
|
||||||
.post("/api/admin/users/init", controller.adminUser)
|
|
||||||
.get("/api/admin/users/self", controller.getSelf)
|
|
||||||
.post(
|
|
||||||
"/api/admin/users/self",
|
|
||||||
buildUserSaveValidation(true),
|
|
||||||
controller.updateSelf
|
|
||||||
)
|
|
||||||
.delete("/api/admin/users/:id", adminOnly, controller.destroy)
|
.delete("/api/admin/users/:id", adminOnly, controller.destroy)
|
||||||
.get("/api/admin/users/:id", controller.find)
|
.get("/api/admin/users/:id", adminOnly, controller.find)
|
||||||
.get("/api/admin/roles/:appId")
|
.get("/api/admin/roles/:appId")
|
||||||
.post(
|
.post(
|
||||||
"/api/admin/users/invite",
|
"/api/admin/users/invite",
|
||||||
|
@ -71,10 +64,18 @@ router
|
||||||
buildInviteValidation(),
|
buildInviteValidation(),
|
||||||
controller.invite
|
controller.invite
|
||||||
)
|
)
|
||||||
|
// non-admin endpoints
|
||||||
|
.post(
|
||||||
|
"/api/admin/users/self",
|
||||||
|
buildUserSaveValidation(true),
|
||||||
|
controller.updateSelf
|
||||||
|
)
|
||||||
.post(
|
.post(
|
||||||
"/api/admin/users/invite/accept",
|
"/api/admin/users/invite/accept",
|
||||||
buildInviteAcceptValidation(),
|
buildInviteAcceptValidation(),
|
||||||
controller.inviteAccept
|
controller.inviteAccept
|
||||||
)
|
)
|
||||||
|
.post("/api/admin/users/init", controller.adminUser)
|
||||||
|
.get("/api/admin/users/self", controller.getSelf)
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module.exports = async (ctx, next) => {
|
module.exports = async (ctx, next) => {
|
||||||
if (!ctx.user || !ctx.user.admin || !ctx.user.admin.global) {
|
if (!ctx.internal && (!ctx.user || !ctx.user.admin || !ctx.user.admin.global)) {
|
||||||
ctx.throw(403, "Admin user only endpoint.")
|
ctx.throw(403, "Admin user only endpoint.")
|
||||||
}
|
}
|
||||||
return next()
|
return next()
|
||||||
|
|
Loading…
Reference in New Issue