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

Merge branch 'feat/growi-bot' into fix/behavior-when-clicked-reset-button

zahmis 4 лет назад
Родитель
Сommit
28b5a9508b

+ 3 - 0
CHANGES.md

@@ -2,6 +2,8 @@
 
 ## v4.2.17-RC
 
+* Improvement: Invoke garbage collection when reindex all pages by elasticsearch
+* Improvement: Hide Sidebar at shared pages
 * Fix: No unsaved alert is displayed without difference the latest markdown and editor value
 * Support: Update libs
     * eslint-config-weseek
@@ -107,6 +109,7 @@
 ## v4.2.5
 
 * Improvement: Invoke garbage collection when reindex all pages by elasticsearch
+    * Turned out not working -- 2021.05.01
 * Fix: MathJax rendering does not work
 
 ## v4.2.4

+ 1 - 1
package.json

@@ -71,7 +71,7 @@
     "server:nolazy": "env-cmd -f config/env.dev.js node-dev --nolazy --inspect src/server/app.js",
     "server:dev": "env-cmd -f config/env.dev.js node-dev --expose_gc --inspect src/server/app.js",
     "server:prod:ci": "npm run server:prod -- --ci",
-    "server:prod": "env-cmd -f config/env.prod.js node src/server/app.js",
+    "server:prod": "env-cmd -f config/env.prod.js node --expose_gc src/server/app.js",
     "server": "npm run server:dev",
     "start": "npm run server:prod",
     "test": "jest --config=config/jest.config.js --passWithNoTests -- ",

+ 1 - 0
resource/locales/en_US/admin/admin.json

@@ -293,6 +293,7 @@
     "official_bot_settings": "Official bot Settings",
     "custom_bot_without_proxy_settings": "Custom Bot without proxy Settings",
     "reset": "Reset",
+    "reset_all_settings": "Reset all settings",
     "delete_slackbot_settings": "Reset Slack Bot settings",
     "slackbot_settings_notice": "Reset",
     "accordion": {

+ 1 - 0
resource/locales/ja_JP/admin/admin.json

@@ -290,6 +290,7 @@
     "cooperation_procedure": "連携手順",
     "custom_bot_without_proxy_settings": "Custom Bot (Without-Proxy) 設定",
     "reset": "リセット",
+    "reset_all_settings": "全ての設定をリセット",
     "delete_slackbot_settings": "Slack Bot 設定をリセットする",
     "slackbot_settings_notice": "リセットします",
     "accordion": {

+ 1 - 0
resource/locales/zh_CN/admin/admin.json

@@ -300,6 +300,7 @@
     "cooperation_procedure": "协作程序",
     "custom_bot_without_proxy_settings": "Custom Bot (Without-Proxy) 设置",
     "reset":"重置",
+    "reset_all_settings": "重置所有设置",
     "delete_slackbot_settings": "重置 Slack Bot 设置",
     "slackbot_settings_notice": "重置",
     "accordion": {

+ 13 - 1
src/client/js/components/Admin/SlackIntegration/SlackIntegration.jsx

@@ -145,7 +145,19 @@ const SlackIntegration = (props) => {
           </a>
         </h2>
 
-        {t('admin:slack_integration.selecting_bot_types.selecting_bot_type')}
+        <div className="d-flex justify-content">
+          <div className="mr-auto">
+            {t('admin:slack_integration.selecting_bot_types.selecting_bot_type')}
+          </div>
+
+          {(currentBotType === 'officialBot' || currentBotType === 'customBotWithProxy') && (
+            <button
+              className="mx-3 btn btn-outline-danger flex-end"
+              type="button"
+            >{t('admin:slack_integration.reset_all_settings')}
+            </button>
+          )}
+        </div>
 
         <div className="row my-5 flex-wrap-reverse justify-content-center">
           {botTypes.map((botType) => {

+ 21 - 7
src/server/models/slack-app-integration.js

@@ -1,10 +1,24 @@
-module.exports = function(crowi) {
-  const mongoose = require('mongoose');
+const crypto = require('crypto');
+const mongoose = require('mongoose');
+
+const schema = new mongoose.Schema({
+  tokenGtoP: { type: String, required: true, unique: true },
+  tokenPtoG: { type: String, required: true, unique: true },
+});
+class SlackAppIntegration {
 
-  const slackAppIntegrationSchema = new mongoose.Schema({
-    tokenGtoP: { type: String, required: true, unique: true },
-    tokenPtoG: { type: String, required: true, unique: true },
-  });
+  static generateAccessToken(user) {
+    const hasher1 = crypto.createHash('sha512');
+    const hasher2 = crypto.createHash('sha512');
+    const tokenGtoP = hasher1.update(new Date().getTime() + user._id).digest('base64');
+    const tokenPtoG = hasher2.update(new Date().getTime() + user.username).digest('base64');
+    return [tokenGtoP, tokenPtoG];
+  }
 
-  return mongoose.model('SlackAppIntegration', slackAppIntegrationSchema);
+}
+
+module.exports = function(crowi) {
+  SlackAppIntegration.crowi = crowi;
+  schema.loadClass(SlackAppIntegration);
+  return mongoose.model('SlackAppIntegration', schema);
 };

+ 37 - 0
src/server/routes/apiv3/slack-integration-settings.js

@@ -1,3 +1,4 @@
+const mongoose = require('mongoose');
 const express = require('express');
 const { body } = require('express-validator');
 const axios = require('axios');
@@ -304,6 +305,42 @@ module.exports = (crowi) => {
     }
   });
 
+  /**
+   * @swagger
+   *
+   *    /slack-integration/access-token:
+   *      put:
+   *        tags: [SlackIntegration]
+   *        operationId:
+   *        summary: /slack-integration
+   *        description: Generate accessToken
+   *        responses:
+   *          200:
+   *            description: Succeeded to update access token for slack
+   */
+  router.put('/access-tokens', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
+    const SlackAppIntegration = mongoose.model('SlackAppIntegration');
+    let checkTokens;
+    let tokenGtoP;
+    let tokenPtoG;
+    do {
+      // TODO imple generate tokens at GW-5859. The following tokens is temporary.
+      tokenGtoP = 'v2';
+      tokenPtoG = 'v2';
+      // eslint-disable-next-line no-await-in-loop
+      checkTokens = await SlackAppIntegration.findOne({ $or: [{ tokenGtoP }, { tokenPtoG }] });
+    } while (checkTokens != null);
+
+    try {
+      const slackAppTokens = await SlackAppIntegration.create({ tokenGtoP, tokenPtoG });
+      return res.apiv3(slackAppTokens, 200);
+    }
+    catch (error) {
+      const msg = 'Error occured in updating access token for slack app tokens';
+      logger.error('Error', error);
+      return res.apiv3Err(new ErrorV3(msg, 'update-slackAppTokens-failed'), 500);
+    }
+  });
 
   return router;
 };

+ 3 - 1
src/server/views/layout-growi/shared_page.html

@@ -17,6 +17,8 @@
 {% endblock %}
 {% block head_warn_alert_siteurl_undefined %}
 {% endblock %}
+{% block sidebar %}
+{% endblock %}
 
 {% block content_main %}
   <div class="container-lg">
@@ -29,7 +31,7 @@
       <div id="share-link-alert"></div>
 
       {% include '../widget/page_content.html' %}
-      
+
     </div>
 
   </div>

+ 2 - 1
src/server/views/layout/layout.html

@@ -77,8 +77,9 @@
   {% block head_warn_breaking_changes %}{% include '../widget/alert_breaking_changes.html' %}{% endblock %}
 
   <div id="page-wrapper" class="page-wrapper d-flex d-print-block">
-    {# Sidebar #}
+    {% block sidebar %}
     <div id="grw-sidebar-wrapper"></div>
+    {% endblock %}
 
     <div class="flex-fill mw-0">
       {% block head_warn_alert_siteurl_undefined %}{% include '../widget/alert_siteurl_undefined.html' %}{% endblock %}