feat(writeapi): admin settings update route

v1.18.x
Julian Lam 4 years ago
parent 2ec838fc59
commit a55b381791

@ -1022,6 +1022,32 @@ paths:
response:
type: object
properties: {}
/admin/settings/{setting}:
put:
tags:
- admin
summary: update configuration setting
description: This operation updates a configuration setting in the backend. The calling user must have the `admin:settings` privilege (or be a superadmin) in order for this call to proceed.
parameters:
- in: path
name: setting
schema:
type: string
required: true
description: backend id of the setting to update
responses:
'200':
description: Admin setting updated
content:
application/json:
schema:
type: object
properties:
status:
$ref: '#/components/schemas/Status'
response:
type: object
properties: {}
components:
schemas:
Status:

@ -0,0 +1,16 @@
'use strict';
const meta = require('../../meta');
const helpers = require('../helpers');
const Admin = module.exports;
Admin.updateSetting = async (req, res) => {
if (!res.locals.privileges['admin:settings']) {
return helpers.formatApiResponse(403, res);
}
await meta.configs.set(req.params.setting, req.body.value);
helpers.formatApiResponse(200, res);
};

@ -7,3 +7,4 @@ Write.groups = require('./groups');
Write.categories = require('./categories');
Write.topics = require('./topics');
Write.posts = require('./posts');
Write.admin = require('./admin');

@ -0,0 +1,16 @@
'use strict';
const router = require('express').Router();
const middleware = require('../../middleware');
const controllers = require('../../controllers');
const routeHelpers = require('../helpers');
const setupApiRoute = routeHelpers.setupApiRoute;
module.exports = function () {
const middlewares = [middleware.authenticate];
setupApiRoute(router, '/settings/:setting', middleware, [...middlewares, middleware.checkRequired.bind(null, ['value']), middleware.exposePrivilegeSet], 'put', controllers.write.admin.updateSetting);
return router;
};

@ -25,7 +25,7 @@ Write.reload = (params) => {
router.use('/api/v3/categories', require('./categories')());
router.use('/api/v3/topics', require('./topics')());
router.use('/api/v3/posts', require('./posts')());
// router.use('/api/v3/util', require('./util')());
router.use('/api/v3/admin', require('./admin')());
router.get('/api/v3/ping', function (req, res) {
helpers.formatApiResponse(200, res, {

Loading…
Cancel
Save