| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- /* eslint-disable no-unused-vars */
- const loggerFactory = require('@alias/logger');
- const logger = loggerFactory('growi:routes:apiv3:security-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: SecuritySetting
- */
- 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;
- const validator = {
- guestMode: [
- body('restrictGuestMode').isString(),
- ],
- };
- /**
- * @swagger
- *
- * /security-setting/guestMode:
- * put:
- * tags: [SecuritySetting]
- * description: Get restrictGuestMode
- * requestBody:
- * required: true
- * content:
- * application/json:
- * schama:
- * type: object
- * properties:
- * restructGuestMode:
- * description: type of restrutGuestMode
- * type: string
- * responses:
- * 200:
- * description: Succeeded to update layout and theme
- */
- router.put('guestMode', loginRequiredStrictly, adminRequired, csrf, validator.guestMode, 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'));
- }
- });
- /**
- * @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'));
- }
- });
- /**
- * @swagger
- *
- * /customize-setting/function:
- * put:
- * tags: [CustomizeSetting]
- * description: Update function
- * requestBody:
- * required: true
- * content:
- * application/json:
- * schama:
- * type: object
- * properties:
- * isEnabledTimeline:
- * description: is enabled timeline
- * type: boolean
- * isSavedStatesOfTabChanges:
- * description: is saved states of tabChanges
- * type: boolean
- * isEnabledAttachTitleHeader:
- * description: is enabled attach titleHeader
- * type: boolean
- * recentCreatedLimit:
- * description: limit of recent created
- * type: number
- * responses:
- * 200:
- * description: Succeeded to update function
- */
- router.put('/function', loginRequiredStrictly, adminRequired, csrf, validator.function, ApiV3FormValidator, async(req, res) => {
- const requestParams = {
- 'customize:isEnabledTimeline': req.body.isEnabledTimeline,
- 'customize:isSavedStatesOfTabChanges': req.body.isSavedStatesOfTabChanges,
- 'customize:isEnabledAttachTitleHeader': req.body.isEnabledAttachTitleHeader,
- 'customize:showRecentCreatedNumber': req.body.recentCreatedLimit,
- };
- try {
- await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
- const customizedParams = {
- isEnabledTimeline: await crowi.configManager.getConfig('crowi', 'customize:isEnabledTimeline'),
- isSavedStatesOfTabChanges: await crowi.configManager.getConfig('crowi', 'customize:isSavedStatesOfTabChanges'),
- isEnabledAttachTitleHeader: await crowi.configManager.getConfig('crowi', 'customize:isEnabledAttachTitleHeader'),
- recentCreatedLimit: await crowi.configManager.getConfig('crowi', 'customize:showRecentCreatedNumber'),
- };
- return res.apiv3({ customizedParams });
- }
- catch (err) {
- const msg = 'Error occurred in updating function';
- logger.error('Error', err);
- return res.apiv3Err(new ErrorV3(msg, 'update-function-failed'));
- }
- });
- return router;
- };
|