Browse Source

Merge pull request #1375 from weseek/create-api-v3-update-custom-header

Create api v3 update custom header
Yuki Takei 6 years ago
parent
commit
c2d3e4be69

+ 1 - 1
resource/locales/en-US/translation.json

@@ -667,7 +667,7 @@
     "custom_title": "Custom Title",
     "custom_title": "Custom Title",
     "custom_title_detail": "You can customize <code>%s</code> tag.<br><code>%s</code> will be automatically replaced with the app name, and <code>%s</code> will be replaced with the page name/path.",
     "custom_title_detail": "You can customize <code>%s</code> tag.<br><code>%s</code> will be automatically replaced with the app name, and <code>%s</code> will be replaced with the page name/path.",
     "custom_header": "Custom HTML Header",
     "custom_header": "Custom HTML Header",
-    "custom_header_detail": "You can customize HTML header that applies all pages. Your custom script will be inserted in <code>%s</code> but above other <code>%s</code> tags.<br>Relaod page to see changes.",
+    "custom_header_detail": "You can customize HTML header that applies all pages. Your custom script will be inserted in <code>&lt;header&gt;</code> but above other <code>&lt;script&gt;</code> tags.<br>Relaod page to see changes.",
     "Custom CSS": "Custom CSS",
     "Custom CSS": "Custom CSS",
     "write_CSS": "You can write CSS that is applied to whole system.",
     "write_CSS": "You can write CSS that is applied to whole system.",
     "reflect_change": "You need to reload the page to reflect the change.",
     "reflect_change": "You need to reload the page to reflect the change.",

+ 1 - 1
resource/locales/ja/translation.json

@@ -651,7 +651,7 @@
     "custom_title": "カスタム Title",
     "custom_title": "カスタム Title",
     "custom_title_detail": "<code>%s</code>タグのコンテンツをカスタマイズできます。<br><code>%s</code>がサイト名、<code>%s</code>がページ名またはページパスに置換されます。",
     "custom_title_detail": "<code>%s</code>タグのコンテンツをカスタマイズできます。<br><code>%s</code>がサイト名、<code>%s</code>がページ名またはページパスに置換されます。",
     "custom_header": "カスタム HTML Header",
     "custom_header": "カスタム HTML Header",
-    "custom_header_detail": "システム全体に適用される HTML を記述できます。<code>%s</code> タグ内の他の <code>%s</code> タグ読み込み前に展開されます。<br>変更の反映はページの更新が必要です。",
+    "custom_header_detail": "システム全体に適用される HTML を記述できます。<code>&lt;header&gt;</code> タグ内の他の <code>&lt;script&gt;</code> タグ読み込み前に展開されます。<br>変更の反映はページの更新が必要です。",
     "Custom CSS": "カスタム CSS",
     "Custom CSS": "カスタム CSS",
     "write_CSS": " システム全体に適用されるCSSを記述できます。",
     "write_CSS": " システム全体に適用されるCSSを記述できます。",
     "reflect_change": "変更の反映はページの更新が必要です。",
     "reflect_change": "変更の反映はページの更新が必要です。",

+ 1 - 1
src/client/js/components/Admin/Customize/CustomizeHeaderSetting.jsx

@@ -46,7 +46,7 @@ class CustomizeHeaderSetting extends React.Component {
         <p
         <p
           className="well"
           className="well"
           // eslint-disable-next-line react/no-danger
           // eslint-disable-next-line react/no-danger
-          dangerouslySetInnerHTML={{ __html: t('customize_page.custom_header_detail', '&lt;header&gt;', '&lt;script&gt;') }}
+          dangerouslySetInnerHTML={{ __html: t('customize_page.custom_header_detail') }}
         />
         />
 
 
         <div className="help-block">
         <div className="help-block">

+ 7 - 3
src/client/js/services/AdminCustomizeContainer.js

@@ -239,7 +239,11 @@ export default class AdminCustomizeContainer extends Container {
    * @return {string} Customize html header
    * @return {string} Customize html header
    */
    */
   async updateCustomizeHeader() {
   async updateCustomizeHeader() {
-    // TODO GW-601 create apiV3
+    const response = await this.appContainer.apiv3.put('/customize-setting/customize-header', {
+      customizeHeader: this.state.currentCustomizeHeader,
+    });
+    const { customizedParams } = response.data;
+    return customizedParams;
   }
   }
 
 
   /**
   /**
@@ -248,7 +252,7 @@ export default class AdminCustomizeContainer extends Container {
    * @return {string} Customize css
    * @return {string} Customize css
    */
    */
   async updateCustomizeCss() {
   async updateCustomizeCss() {
-    const response = await this.appContainer.apiv3.put('/customize-setting/customizeCss', {
+    const response = await this.appContainer.apiv3.put('/customize-setting/customize-css', {
       customizeCss: this.state.currentCustomizeCss,
       customizeCss: this.state.currentCustomizeCss,
     });
     });
     const { customizedParams } = response.data;
     const { customizedParams } = response.data;
@@ -261,7 +265,7 @@ export default class AdminCustomizeContainer extends Container {
    * @return {string} Customize scripts
    * @return {string} Customize scripts
    */
    */
   async updateCustomizeScript() {
   async updateCustomizeScript() {
-    const response = await this.appContainer.apiv3.put('/customize-setting/customizeScript', {
+    const response = await this.appContainer.apiv3.put('/customize-setting/customize-script', {
       customizeScript: this.state.currentCustomizeScript,
       customizeScript: this.state.currentCustomizeScript,
     });
     });
     const { customizedParams } = response.data;
     const { customizedParams } = response.data;

+ 73 - 11
src/server/routes/apiv3/customize-setting.js

@@ -10,8 +10,6 @@ const router = express.Router();
 const { body } = require('express-validator/check');
 const { body } = require('express-validator/check');
 const ErrorV3 = require('../../models/vo/error-apiv3');
 const ErrorV3 = require('../../models/vo/error-apiv3');
 
 
-const validator = {};
-
 /**
 /**
  * @swagger
  * @swagger
  *  tags:
  *  tags:
@@ -23,15 +21,19 @@ const validator = {};
  *
  *
  *  components:
  *  components:
  *    schemas:
  *    schemas:
- *      CustomizeStatus:
+ *      CustomizeLayoutTheme:
  *        type: object
  *        type: object
  *        properties:
  *        properties:
  *          layoutType:
  *          layoutType:
  *            type: string
  *            type: string
  *          themeType:
  *          themeType:
  *            type: string
  *            type: string
+ *      CustomizeBehavior:
+ *        type: object
  *          behaviorType
  *          behaviorType
  *            type: string
  *            type: string
+ *      CustomizeFunction:
+ *        type: object
  *          isEnabledTimeline:
  *          isEnabledTimeline:
  *            type: boolean
  *            type: boolean
  *          isSavedStatesOfTabChanges:
  *          isSavedStatesOfTabChanges:
@@ -40,10 +42,22 @@ const validator = {};
  *            type: boolean
  *            type: boolean
  *          recentCreatedLimit:
  *          recentCreatedLimit:
  *            type: number
  *            type: number
- *          customizeCss:
+ *      CustomizeHighlight:
+ *        type: object
+ *          styleName:
  *            type: string
  *            type: string
- *          customizeScript:
+ *          styleBorder:
+ *            type: boolean
+ *      CustomizeHeader:
+ *        type: object
+ *          customizeHeader:
+ *            type: string
+ *      CustomizeCss:
+ *        type: object
+ *          customizeCss:
  *            type: string
  *            type: string
+ *      CustomizeScript:
+ *        type: object
  *          customizeScript:
  *          customizeScript:
  *            type: string
  *            type: string
  */
  */
@@ -69,6 +83,9 @@ module.exports = (crowi) => {
       body('isEnabledAttachTitleHeader').isBoolean(),
       body('isEnabledAttachTitleHeader').isBoolean(),
       body('recentCreatedLimit').isInt(),
       body('recentCreatedLimit').isInt(),
     ],
     ],
+    customizeHeader: [
+      body('customizeHeader').isString(),
+    ],
     highlight: [
     highlight: [
       body('highlightJsStyle').isString(),
       body('highlightJsStyle').isString(),
       body('highlightJsStyleBorder').isBoolean(),
       body('highlightJsStyleBorder').isBoolean(),
@@ -116,7 +133,7 @@ module.exports = (crowi) => {
    *              schema:
    *              schema:
    *                properties:
    *                properties:
    *                  customizedParams:
    *                  customizedParams:
-   *                    $ref: '#/components/schemas/CustomizeStatus'
+   *                    $ref: '#/components/schemas/CustomizeLayoutTheme'
    */
    */
   router.put('/layoutTheme', loginRequiredStrictly, adminRequired, csrf, validator.layoutTheme, ApiV3FormValidator, async(req, res) => {
   router.put('/layoutTheme', loginRequiredStrictly, adminRequired, csrf, validator.layoutTheme, ApiV3FormValidator, async(req, res) => {
     const requestParams = {
     const requestParams = {
@@ -164,7 +181,7 @@ module.exports = (crowi) => {
    *              schema:
    *              schema:
    *                properties:
    *                properties:
    *                  customizedParams:
    *                  customizedParams:
-   *                    $ref: '#/components/schemas/CustomizeStatus'
+   *                    $ref: '#/components/schemas/CustomizeBehavior'
    */
    */
   router.put('/behavior', loginRequiredStrictly, adminRequired, csrf, validator.behavior, ApiV3FormValidator, async(req, res) => {
   router.put('/behavior', loginRequiredStrictly, adminRequired, csrf, validator.behavior, ApiV3FormValidator, async(req, res) => {
     const requestParams = {
     const requestParams = {
@@ -219,7 +236,7 @@ module.exports = (crowi) => {
    *              schema:
    *              schema:
    *                properties:
    *                properties:
    *                  customizedParams:
    *                  customizedParams:
-   *                    $ref: '#/components/schemas/CustomizeStatus'
+   *                    $ref: '#/components/schemas/CustomizeFunction'
    */
    */
   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 = {
@@ -274,7 +291,7 @@ module.exports = (crowi) => {
    *                schema:
    *                schema:
    *                  properties:
    *                  properties:
    *                    customizedParams:
    *                    customizedParams:
-   *                      $ref: '#/components/schemas/CustomizeStatus'
+   *                      $ref: '#/components/schemas/CustomizeHighlight'
    */
    */
   router.put('/highlight', loginRequiredStrictly, adminRequired, csrf, validator.highlight, ApiV3FormValidator, async(req, res) => {
   router.put('/highlight', loginRequiredStrictly, adminRequired, csrf, validator.highlight, ApiV3FormValidator, async(req, res) => {
     const requestParams = {
     const requestParams = {
@@ -297,6 +314,51 @@ module.exports = (crowi) => {
     }
     }
   });
   });
 
 
+  /**
+   * @swagger
+   *
+   *    /customize-setting/customizeHeader:
+   *      put:
+   *        tags: [CustomizeSetting]
+   *        description: Update customizeHeader
+   *        requestBody:
+   *          required: true
+   *          content:
+   *            application/json:
+   *              schama:
+   *                type: object
+   *                properties:
+   *                  customizeHeader:
+   *                    description: customize header
+   *                    type: string
+   *      responses:
+   *        200:
+   *          description: Succeeded to update customize header
+   *          content:
+   *            application/json:
+   *              schema:
+   *                properties:
+   *                  customizedParams:
+   *                    $ref: '#/components/schemas/CustomizeHeader'
+   */
+  router.put('/customize-header', loginRequiredStrictly, adminRequired, csrf, validator.customizeHeader, ApiV3FormValidator, async(req, res) => {
+    const requestParams = {
+      'customize:header': req.body.customizeHeader,
+    };
+    try {
+      await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
+      const customizedParams = {
+        customizeCss: await crowi.configManager.getConfig('crowi', 'customize:header'),
+      };
+      return res.apiv3({ customizedParams });
+    }
+    catch (err) {
+      const msg = 'Error occurred in updating customizeHeader';
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(msg, 'update-customizeHeader-failed'));
+    }
+  });
+
   /**
   /**
    * @swagger
    * @swagger
    *
    *
@@ -322,7 +384,7 @@ module.exports = (crowi) => {
    *              schema:
    *              schema:
    *                properties:
    *                properties:
    *                  customizedParams:
    *                  customizedParams:
-   *                    $ref: '#/components/schemas/CustomizeStatus'
+   *                    $ref: '#/components/schemas/CustomizeCss'
    */
    */
   router.put('/customize-css', loginRequiredStrictly, adminRequired, csrf, validator.customizeCss, ApiV3FormValidator, async(req, res) => {
   router.put('/customize-css', loginRequiredStrictly, adminRequired, csrf, validator.customizeCss, ApiV3FormValidator, async(req, res) => {
     const requestParams = {
     const requestParams = {
@@ -367,7 +429,7 @@ module.exports = (crowi) => {
    *              schema:
    *              schema:
    *                properties:
    *                properties:
    *                  customizedParams:
    *                  customizedParams:
-   *                    $ref: '#/components/schemas/CustomizeStatus'
+   *                    $ref: '#/components/schemas/CustomizeScript'
    */
    */
   router.put('/customize-script', loginRequiredStrictly, adminRequired, csrf, validator.customizeScript, ApiV3FormValidator, async(req, res) => {
   router.put('/customize-script', loginRequiredStrictly, adminRequired, csrf, validator.customizeScript, ApiV3FormValidator, async(req, res) => {
     const requestParams = {
     const requestParams = {