Skip to content

Commit

Permalink
feat(writeapi): admin settings update route
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Oct 8, 2020
1 parent 2ec838f commit a55b381
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
26 changes: 26 additions & 0 deletions public/openapi/write.yaml
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions src/controllers/write/admin.js
@@ -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);
};
1 change: 1 addition & 0 deletions src/controllers/write/index.js
Expand Up @@ -7,3 +7,4 @@ Write.groups = require('./groups');
Write.categories = require('./categories');
Write.topics = require('./topics');
Write.posts = require('./posts');
Write.admin = require('./admin');
16 changes: 16 additions & 0 deletions src/routes/write/admin.js
@@ -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;
};
2 changes: 1 addition & 1 deletion src/routes/write/index.js
Expand Up @@ -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, {
Expand Down

0 comments on commit a55b381

Please sign in to comment.