| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- /* 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(),
- ],
- pageDeletion: [
- body('pageCompleteDeletionAuthority').isString(),
- ],
- function: [
- body('hideRestrictedByOwner').isBoolean(),
- body('hideRestrictedByGroup').isBoolean(),
- ],
- };
- /**
- * @swagger
- *
- * /security-setting/guestMode:
- * put:
- * tags: [SecuritySetting]
- * description: Get restrictGuestMode
- * requestBody:
- * required: true
- * content:
- * application/json:
- * schama:
- * type: object
- * properties:
- * restrictGuestMode:
- * description: type of restrictGuestMode
- * type: string
- * responses:
- * 200:
- * description: Succeeded to update restrictGuestMode
- */
- router.put('/guestMode', loginRequiredStrictly, adminRequired, csrf, validator.guestMode, ApiV3FormValidator, async(req, res) => {
- const requestParams = {
- 'security:restrictGuestMode': req.body.restrictGuestMode,
- };
- try {
- await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
- const securitySettingParams = {
- restrictGuestMode: await crowi.configManager.getConfig('crowi', 'security:restrictGuestMode'),
- };
- return res.apiv3({ securitySettingParams });
- }
- 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
- *
- * /security-setting/pageDeletion:
- * put:
- * tags: [SecuritySetting]
- * description: Update pageDeletion Setting
- * requestBody:
- * required: true
- * content:
- * application/json:
- * schama:
- * type: object
- * properties:
- * pageCompleteDeletionAuthority:
- * description: type of pageCompleteDeletionAuthority
- * type: string
- * responses:
- * 200:
- * description: Succeeded to update behavior
- */
- router.put('/pageDeletion', loginRequiredStrictly, adminRequired, csrf, validator.pageDeletion, ApiV3FormValidator, async(req, res) => {
- const requestParams = {
- 'security:pageCompleteDeletionAuthority': req.body.pageCompleteDeletionAuthority,
- };
- try {
- await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
- const securitySettingParams = {
- pageCompleteDeletionAuthority: await crowi.configManager.getConfig('crowi', 'security:pageCompleteDeletionAuthority'),
- };
- return res.apiv3({ securitySettingParams });
- }
- catch (err) {
- const msg = 'Error occurred in updating page-deletion-setting';
- logger.error('Error', err);
- return res.apiv3Err(new ErrorV3(msg, 'update-page-deletion-setting-failed'));
- }
- });
- /**
- * @swagger
- *
- * /security-setting/function:
- * put:
- * tags: [SecuritySetting]
- * description: Update function
- * requestBody:
- * required: true
- * content:
- * application/json:
- * schama:
- * type: object
- * properties:
- * hideRestrictedByOwner:
- * description: is enabled hideRestrictedByOwner
- * type: boolean
- * ihideRestrictedByGroup:
- * description: is enabled hideRestrictedBygroup
- * type: boolean
- * responses:
- * 200:
- * description: Succeeded to update function
- */
- router.put('/function', loginRequiredStrictly, adminRequired, csrf, validator.function, ApiV3FormValidator, async(req, res) => {
- const requestParams = {
- 'security:list-policy:hideRestrictedByOwner': req.body.hideRestrictedByOwner,
- 'security:list-policy:hideRestrictedByGroup': req.body.hideRestrictedByGroup,
- };
- try {
- await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
- const securitySettingParams = {
- hideRestrictedByOwner: await crowi.configManager.getConfig('crowi', 'security:list-policy:hideRestrictedByOwner'),
- hideRestrictedByGroup: await crowi.configManager.getConfig('crowi', 'customize:security:list-policy:hideRestrictedByGroup'),
- };
- return res.apiv3({ securitySettingParams });
- }
- catch (err) {
- const msg = 'Error occurred in updating function';
- logger.error('Error', err);
- return res.apiv3Err(new ErrorV3(msg, 'update-function-failed'));
- }
- });
- return router;
- };
|