Updating configs API based on some feedback during the development of the settings frontend.
This commit is contained in:
parent
403ee4a870
commit
5d2c1c23aa
|
@ -48,7 +48,7 @@ exports.save = async function (ctx) {
|
||||||
exports.fetch = async function (ctx) {
|
exports.fetch = async function (ctx) {
|
||||||
const db = new CouchDB(GLOBAL_DB)
|
const db = new CouchDB(GLOBAL_DB)
|
||||||
const response = await db.allDocs(
|
const response = await db.allDocs(
|
||||||
getConfigParams(undefined, {
|
getConfigParams({ type: ctx.params.type }, {
|
||||||
include_docs: true,
|
include_docs: true,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -61,11 +61,10 @@ exports.fetch = async function (ctx) {
|
||||||
*/
|
*/
|
||||||
exports.find = async function (ctx) {
|
exports.find = async function (ctx) {
|
||||||
const db = new CouchDB(GLOBAL_DB)
|
const db = new CouchDB(GLOBAL_DB)
|
||||||
const userId = ctx.params.user && ctx.params.user._id
|
|
||||||
|
|
||||||
const { group } = ctx.query
|
const { userId, groupId } = ctx.query
|
||||||
if (group) {
|
if (groupId && userId) {
|
||||||
const group = await db.get(group)
|
const group = await db.get(groupId)
|
||||||
const userInGroup = group.users.some(groupUser => groupUser === userId)
|
const userInGroup = group.users.some(groupUser => groupUser === userId)
|
||||||
if (!ctx.user.admin && !userInGroup) {
|
if (!ctx.user.admin && !userInGroup) {
|
||||||
ctx.throw(400, `User is not in specified group: ${group}.`)
|
ctx.throw(400, `User is not in specified group: ${group}.`)
|
||||||
|
@ -77,7 +76,7 @@ exports.find = async function (ctx) {
|
||||||
const scopedConfig = await determineScopedConfig(db, {
|
const scopedConfig = await determineScopedConfig(db, {
|
||||||
type: ctx.params.type,
|
type: ctx.params.type,
|
||||||
user: userId,
|
user: userId,
|
||||||
group,
|
group: groupId,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (scopedConfig) {
|
if (scopedConfig) {
|
||||||
|
|
|
@ -54,14 +54,21 @@ function buildConfigSaveValidation() {
|
||||||
{ is: Configs.GOOGLE, then: googleValidation() }
|
{ is: Configs.GOOGLE, then: googleValidation() }
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
}),
|
}).required(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildConfigGetValidation() {
|
||||||
|
// prettier-ignore
|
||||||
|
return joiValidator.params(Joi.object({
|
||||||
|
type: Joi.string().valid(...Object.values(Configs)).required()
|
||||||
|
}).unknown(true).required())
|
||||||
|
}
|
||||||
|
|
||||||
router
|
router
|
||||||
.post("/api/admin/configs", buildConfigSaveValidation(), controller.save)
|
.post("/api/admin/configs", buildConfigSaveValidation(), controller.save)
|
||||||
.delete("/api/admin/configs/:id", controller.destroy)
|
.delete("/api/admin/configs/:id", controller.destroy)
|
||||||
.get("/api/admin/configs", controller.fetch)
|
.get("/api/admin/configs/all/:type", buildConfigGetValidation(), controller.fetch)
|
||||||
.get("/api/admin/configs/:type", controller.find)
|
.get("/api/admin/configs/:type", buildConfigGetValidation(), controller.find)
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
Loading…
Reference in New Issue