| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /* eslint-disable no-unused-vars */
- const loggerFactory = require('@alias/logger');
- const logger = loggerFactory('growi:routes:apiv3:customize-setting');
- const express = require('express');
- const router = express.Router();
- const { body } = require('express-validator/check');
- const ErrorV3 = require('../../models/vo/error-apiv3');
- const validator = {};
- /**
- * @swagger
- * tags:
- * name: CustomizeSetting
- */
- module.exports = (crowi) => {
- const loginRequiredStrictly = require('../../middleware/login-required')(crowi);
- const adminRequired = require('../../middleware/admin-required')(crowi);
- const csrf = require('../../middleware/csrf')(crowi);
- const { ApiV3FormValidator } = crowi.middlewares;
- validator.layoutTheme = [
- body('layoutType').isString(),
- body('themeType').isString(),
- ];
- /**
- * @swagger
- *
- * /customize-setting/layoutTheme:
- * put:
- * tags: [CustomizeSetting]
- * description: Update layout and theme
- * requestBody:
- * required: true
- * content:
- * application/json:
- * schama:
- * type: object
- * properties:
- * layoutType:
- * description: type of layout
- * type: string
- * themeType:
- * description: type of theme
- * type: string
- * responses:
- * 200:
- * description: Succeeded to update layout and theme
- */
- router.put('/layoutTheme', loginRequiredStrictly, adminRequired, csrf, validator.layoutTheme, ApiV3FormValidator, async(req, res) => {
- const requestParams = {
- 'customize:layout': req.body.layoutType,
- 'customize:theme': req.body.themeType,
- };
- try {
- await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
- const customizedParams = {
- layoutType: await crowi.configManager.getConfig('crowi', 'customize:layout'),
- themeType: await crowi.configManager.getConfig('crowi', 'customize:theme'),
- };
- return res.apiv3({ customizedParams });
- }
- catch (err) {
- const msg = 'Error occurred in updating layout and theme';
- logger.error('Error', err);
- return res.apiv3Err(new ErrorV3(msg, 'update-layoutTheme-failed'));
- }
- });
- validator.behavior = [
- body('behaviorType').isString(),
- ];
- /**
- * @swagger
- *
- * /customize-setting/behavior:
- * put:
- * tags: [CustomizeSetting]
- * description: Update behavior
- * requestBody:
- * required: true
- * content:
- * application/json:
- * schama:
- * type: object
- * properties:
- * behaviorType:
- * description: type of behavior
- * type: string
- * responses:
- * 200:
- * description: Succeeded to update behavior
- */
- router.put('/behavior', loginRequiredStrictly, adminRequired, csrf, validator.behavior, ApiV3FormValidator, async(req, res) => {
- const requestParams = {
- 'customize:behavior': req.body.behaviorType,
- };
- try {
- await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
- const customizedParams = {
- behaviorType: await crowi.configManager.getConfig('crowi', 'customize:behavior'),
- };
- return res.apiv3({ customizedParams });
- }
- catch (err) {
- const msg = 'Error occurred in updating behavior';
- logger.error('Error', err);
- return res.apiv3Err(new ErrorV3(msg, 'update-behavior-failed'));
- }
- });
- return router;
- };
|