forked from tsai/budibase
9 changed files with 124 additions and 98 deletions
@ -1,11 +1,18 @@ |
|||||
const Router = require("@koa/router") |
const Router = require("@koa/router") |
||||
const controller = require("../../controllers/global/self") |
const controller = require("../../controllers/global/self") |
||||
const builderOnly = require("../../../middleware/builderOnly") |
const builderOnly = require("../../../middleware/builderOnly") |
||||
|
const { buildUserSaveValidation } = require("../../utilities/validation") |
||||
|
|
||||
const router = Router() |
const router = Router() |
||||
|
|
||||
router |
router |
||||
.post("/api/global/self/api_key", builderOnly, controller.generateAPIKey) |
.post("/api/global/self/api_key", builderOnly, controller.generateAPIKey) |
||||
.get("/api/global/self/api_key", builderOnly, controller.fetchAPIKey) |
.get("/api/global/self/api_key", builderOnly, controller.fetchAPIKey) |
||||
|
.get("/api/global/self", controller.getSelf) |
||||
|
.post( |
||||
|
"/api/global/self", |
||||
|
buildUserSaveValidation(true), |
||||
|
controller.updateSelf |
||||
|
) |
||||
|
|
||||
module.exports = router |
module.exports = router |
||||
|
|||||
@ -0,0 +1,28 @@ |
|||||
|
const joiValidator = require("../../middleware/joi-validator") |
||||
|
const Joi = require("joi") |
||||
|
|
||||
|
exports.buildUserSaveValidation = (isSelf = false) => { |
||||
|
let schema = { |
||||
|
email: Joi.string().allow(null, ""), |
||||
|
password: Joi.string().allow(null, ""), |
||||
|
forceResetPassword: Joi.boolean().optional(), |
||||
|
firstName: Joi.string().allow(null, ""), |
||||
|
lastName: Joi.string().allow(null, ""), |
||||
|
builder: Joi.object({ |
||||
|
global: Joi.boolean().optional(), |
||||
|
apps: Joi.array().optional(), |
||||
|
}) |
||||
|
.unknown(true) |
||||
|
.optional(), |
||||
|
// maps appId -> roleId for the user
|
||||
|
roles: Joi.object().pattern(/.*/, Joi.string()).required().unknown(true), |
||||
|
} |
||||
|
if (!isSelf) { |
||||
|
schema = { |
||||
|
...schema, |
||||
|
_id: Joi.string(), |
||||
|
_rev: Joi.string(), |
||||
|
} |
||||
|
} |
||||
|
return joiValidator.body(Joi.object(schema).required().unknown(true)) |
||||
|
} |
||||
Loading…
Reference in new issue