Просмотр исходного кода

Merge pull request #1356 from weseek/create-apiV3-update-customizeScript

Create api v3 update customize script
itizawa 6 лет назад
Родитель
Сommit
efef38564d

+ 5 - 1
src/client/js/services/AdminCustomizeContainer.js

@@ -188,7 +188,11 @@ export default class AdminCustomizeContainer extends Container {
    * @return {string} Customize scripts
    * @return {string} Customize scripts
    */
    */
   async updateCustomizeScript() {
   async updateCustomizeScript() {
-    // TODO GW-538 create apiV3
+    const response = await this.appContainer.apiv3.put('/customize-setting/customizeScript', {
+      customizeScript: this.state.currentCustomizeScript,
+    });
+    const { customizedParams } = response.data;
+    return customizedParams;
   }
   }
 
 
 
 

+ 77 - 0
src/server/routes/apiv3/customize-setting.js

@@ -18,6 +18,35 @@ const validator = {};
  *    name: CustomizeSetting
  *    name: CustomizeSetting
  */
  */
 
 
+/**
+ * @swagger
+ *
+ *  components:
+ *    schemas:
+ *      CustomizeStatus:
+ *        type: object
+ *        properties:
+ *          layoutType:
+ *            type: string
+ *          themeType:
+ *            type: string
+ *          behaviorType
+ *            type: string
+ *          isEnabledTimeline:
+ *            type: boolean
+ *          isSavedStatesOfTabChanges:
+ *            type: boolean
+ *          isEnabledAttachTitleHeader:
+ *            type: boolean
+ *          recentCreatedLimit:
+ *            type: number
+ *          customizeCss:
+ *            type: string
+ *          customizeScript:
+ *            type: string
+ *          customizeScript:
+ *            type: string
+ */
 module.exports = (crowi) => {
 module.exports = (crowi) => {
   const loginRequiredStrictly = require('../../middleware/login-required')(crowi);
   const loginRequiredStrictly = require('../../middleware/login-required')(crowi);
   const adminRequired = require('../../middleware/admin-required')(crowi);
   const adminRequired = require('../../middleware/admin-required')(crowi);
@@ -43,6 +72,9 @@ module.exports = (crowi) => {
     customizeCss: [
     customizeCss: [
       body('customizeCss').isString(),
       body('customizeCss').isString(),
     ],
     ],
+    customizeScript: [
+      body('customizeScript').isString(),
+    ],
   };
   };
 
 
   /**
   /**
@@ -248,5 +280,50 @@ module.exports = (crowi) => {
     }
     }
   });
   });
 
 
+  /**
+   * @swagger
+   *
+   *    /customize-setting/customizeScript:
+   *      put:
+   *        tags: [CustomizeSetting]
+   *        description: Update customizeScript
+   *        requestBody:
+   *          required: true
+   *          content:
+   *            application/json:
+   *              schama:
+   *                type: object
+   *                properties:
+   *                  customizeScript:
+   *                    description: customize script
+   *                    type: string
+   *      responses:
+   *        200:
+   *          description: Succeeded to update customize script
+   *          content:
+   *            application/json:
+   *              schema:
+   *                properties:
+   *                  customizedParams:
+   *                    $ref: '#/components/schemas/CustomizeStatus'
+   */
+  router.put('/customize-script', loginRequiredStrictly, adminRequired, csrf, validator.customizeScript, ApiV3FormValidator, async(req, res) => {
+    const requestParams = {
+      'customize:script': req.body.customizeScript,
+    };
+    try {
+      await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
+      const customizedParams = {
+        customizeScript: await crowi.configManager.getConfig('crowi', 'customize:script'),
+      };
+      return res.apiv3({ customizedParams });
+    }
+    catch (err) {
+      const msg = 'Error occurred in updating customizeScript';
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(msg, 'update-customizeScript-failed'));
+    }
+  });
+
   return router;
   return router;
 };
 };