WESEEK Kaito 6 лет назад
Родитель
Сommit
b83bc388a0
2 измененных файлов с 35 добавлено и 225 удалено
  1. 0 185
      src/server/routes/apiv3/security-setting-proto.js
  2. 35 40
      src/server/routes/apiv3/security-setting.js

+ 0 - 185
src/server/routes/apiv3/security-setting-proto.js

@@ -1,185 +0,0 @@
-/* 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: 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 = {
-    layoutTheme: [
-      body('layoutType').isString(),
-      body('themeType').isString(),
-    ],
-    behavior: [
-      body('behaviorType').isString(),
-    ],
-    function: [
-      body('isEnabledTimeline').isBoolean(),
-      body('isSavedStatesOfTabChanges').isBoolean(),
-      body('isEnabledAttachTitleHeader').isBoolean(),
-      body('recentCreatedLimit').isInt(),
-    ],
-  };
-
-  /**
-   * @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'));
-    }
-  });
-
-  /**
-   * @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;
-};

+ 35 - 40
src/server/routes/apiv3/security-setting.js

@@ -29,6 +29,13 @@ module.exports = (crowi) => {
     guestMode: [
     guestMode: [
       body('restrictGuestMode').isString(),
       body('restrictGuestMode').isString(),
     ],
     ],
+    pageDeletion: [
+      body('pageCompleteDeletionAuthority').isString(),
+    ],
+    function: [
+      body('hideRestrictedByOwner').isBoolean(),
+      body('hideRestrictedByGroup').isBoolean(),
+    ],
   };
   };
 
 
   /**
   /**
@@ -52,19 +59,17 @@ module.exports = (crowi) => {
    *          200:
    *          200:
    *            description: Succeeded to update layout and theme
    *            description: Succeeded to update layout and theme
    */
    */
-  router.put('guestMode', loginRequiredStrictly, adminRequired, csrf, validator.guestMode, ApiV3FormValidator, async(req, res) => {
+  router.put('/guestMode', loginRequiredStrictly, adminRequired, csrf, validator.guestMode, ApiV3FormValidator, async(req, res) => {
     const requestParams = {
     const requestParams = {
-      'customize:layout': req.body.layoutType,
-      'customize:theme': req.body.themeType,
+      'security:restrictGuestMode': req.body.restrictGuestMode,
     };
     };
 
 
     try {
     try {
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
-      const customizedParams = {
-        layoutType: await crowi.configManager.getConfig('crowi', 'customize:layout'),
-        themeType: await crowi.configManager.getConfig('crowi', 'customize:theme'),
+      const guestModeParams = {
+        restrictGuestMode: await crowi.configManager.getConfig('crowi', 'security:restrictGuestMode'),
       };
       };
-      return res.apiv3({ customizedParams });
+      return res.apiv3({ guestModeParams });
     }
     }
     catch (err) {
     catch (err) {
       const msg = 'Error occurred in updating layout and theme';
       const msg = 'Error occurred in updating layout and theme';
@@ -76,10 +81,10 @@ module.exports = (crowi) => {
   /**
   /**
    * @swagger
    * @swagger
    *
    *
-   *    /customize-setting/behavior:
+   *    /security-setting/pageDeletion:
    *      put:
    *      put:
-   *        tags: [CustomizeSetting]
-   *        description: Update behavior
+   *        tags: [SecuritySetting]
+   *        description: Update pageDeletion Setting
    *        requestBody:
    *        requestBody:
    *          required: true
    *          required: true
    *          content:
    *          content:
@@ -87,38 +92,38 @@ module.exports = (crowi) => {
    *              schama:
    *              schama:
    *                type: object
    *                type: object
    *                properties:
    *                properties:
-   *                  behaviorType:
-   *                    description: type of behavior
+   *                 pageCompleteDeletionAuthority:
+   *                    description: type of pageCompleteDeletionAuthority
    *                    type: string
    *                    type: string
    *      responses:
    *      responses:
    *          200:
    *          200:
    *            description: Succeeded to update behavior
    *            description: Succeeded to update behavior
    */
    */
-  router.put('/behavior', loginRequiredStrictly, adminRequired, csrf, validator.behavior, ApiV3FormValidator, async(req, res) => {
+  router.put('/pageDeletion', loginRequiredStrictly, adminRequired, csrf, validator.pageDeletion, ApiV3FormValidator, async(req, res) => {
     const requestParams = {
     const requestParams = {
-      'customize:behavior': req.body.behaviorType,
+      'security:pageCompleteDeletionAuthority': req.body.pageCompleteDeletionAuthority,
     };
     };
 
 
     try {
     try {
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
-      const customizedParams = {
+      const pageDeletionParams = {
         behaviorType: await crowi.configManager.getConfig('crowi', 'customize:behavior'),
         behaviorType: await crowi.configManager.getConfig('crowi', 'customize:behavior'),
       };
       };
-      return res.apiv3({ customizedParams });
+      return res.apiv3({ pageDeletionParams });
     }
     }
     catch (err) {
     catch (err) {
-      const msg = 'Error occurred in updating behavior';
+      const msg = 'Error occurred in updating page-deletion-setting';
       logger.error('Error', err);
       logger.error('Error', err);
-      return res.apiv3Err(new ErrorV3(msg, 'update-behavior-failed'));
+      return res.apiv3Err(new ErrorV3(msg, 'update-page-deletion-setting-failed'));
     }
     }
   });
   });
 
 
   /**
   /**
    * @swagger
    * @swagger
    *
    *
-   *    /customize-setting/function:
+   *    /security-setting/function:
    *      put:
    *      put:
-   *        tags: [CustomizeSetting]
+   *        tags: [SecuritySetting]
    *        description: Update function
    *        description: Update function
    *        requestBody:
    *        requestBody:
    *          required: true
    *          required: true
@@ -127,39 +132,29 @@ module.exports = (crowi) => {
    *              schama:
    *              schama:
    *                type: object
    *                type: object
    *                properties:
    *                properties:
-   *                  isEnabledTimeline:
-   *                    description: is enabled timeline
-   *                    type: boolean
-   *                  isSavedStatesOfTabChanges:
-   *                    description: is saved states of tabChanges
+   *                  hideRestrictedByOwner:
+   *                    description: is enabled hideRestrictedByOwner
    *                    type: boolean
    *                    type: boolean
-   *                  isEnabledAttachTitleHeader:
-   *                    description: is enabled attach titleHeader
+   *                  ihideRestrictedByGroup:
+   *                    description: is enabled hideRestrictedBygroup
    *                    type: boolean
    *                    type: boolean
-   *                  recentCreatedLimit:
-   *                    description: limit of recent created
-   *                    type: number
    *      responses:
    *      responses:
    *          200:
    *          200:
    *            description: Succeeded to update function
    *            description: Succeeded to update function
    */
    */
   router.put('/function', loginRequiredStrictly, adminRequired, csrf, validator.function, ApiV3FormValidator, async(req, res) => {
   router.put('/function', loginRequiredStrictly, adminRequired, csrf, validator.function, ApiV3FormValidator, async(req, res) => {
     const requestParams = {
     const requestParams = {
-      'customize:isEnabledTimeline': req.body.isEnabledTimeline,
-      'customize:isSavedStatesOfTabChanges': req.body.isSavedStatesOfTabChanges,
-      'customize:isEnabledAttachTitleHeader': req.body.isEnabledAttachTitleHeader,
-      'customize:showRecentCreatedNumber': req.body.recentCreatedLimit,
+      'security:list-policy:hideRestrictedByOwner': req.body.hideRestrictedByOwner,
+      'security:list-policy:hideRestrictedByGroup': req.body.hideRestrictedByGroup,
     };
     };
 
 
     try {
     try {
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
       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'),
+      const listPolicyParams = {
+        hideRestrictedByOwner: await crowi.configManager.getConfig('crowi', 'security:list-policy:hideRestrictedByOwner'),
+        hideRestrictedByGroup: await crowi.configManager.getConfig('crowi', 'customize:security:list-policy:hideRestrictedByGroup'),
       };
       };
-      return res.apiv3({ customizedParams });
+      return res.apiv3({ listPolicyParams });
     }
     }
     catch (err) {
     catch (err) {
       const msg = 'Error occurred in updating function';
       const msg = 'Error occurred in updating function';