|
@@ -3,6 +3,7 @@ const loggerFactory = require('@alias/logger');
|
|
|
const logger = loggerFactory('growi:routes:apiv3:notification-setting');
|
|
const logger = loggerFactory('growi:routes:apiv3:notification-setting');
|
|
|
const express = require('express');
|
|
const express = require('express');
|
|
|
const { body } = require('express-validator');
|
|
const { body } = require('express-validator');
|
|
|
|
|
+const crypto = require('crypto');
|
|
|
const ErrorV3 = require('../../models/vo/error-apiv3');
|
|
const ErrorV3 = require('../../models/vo/error-apiv3');
|
|
|
|
|
|
|
|
const router = express.Router();
|
|
const router = express.Router();
|
|
@@ -18,8 +19,8 @@ const router = express.Router();
|
|
|
*
|
|
*
|
|
|
* components:
|
|
* components:
|
|
|
* schemas:
|
|
* schemas:
|
|
|
- * CustomBotNonProxy:
|
|
|
|
|
- * description: CustomBotNonProxy
|
|
|
|
|
|
|
+ * CustomBotWithoutProxy:
|
|
|
|
|
+ * description: CustomBotWithoutProxy
|
|
|
* type: object
|
|
* type: object
|
|
|
* properties:
|
|
* properties:
|
|
|
* slackSigningSecret:
|
|
* slackSigningSecret:
|
|
@@ -40,7 +41,7 @@ module.exports = (crowi) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
const validator = {
|
|
const validator = {
|
|
|
- CusotmBotNonProxy: [
|
|
|
|
|
|
|
+ CusotmBotWithoutProxy: [
|
|
|
body('slackSigningSecret').isString(),
|
|
body('slackSigningSecret').isString(),
|
|
|
body('slackBotToken').isString(),
|
|
body('slackBotToken').isString(),
|
|
|
body('botType').isString(),
|
|
body('botType').isString(),
|
|
@@ -53,6 +54,14 @@ module.exports = (crowi) => {
|
|
|
return configManager.updateConfigsInTheSameNamespace('crowi', params, true);
|
|
return configManager.updateConfigsInTheSameNamespace('crowi', params, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ function generateAccessToken(user) {
|
|
|
|
|
+ const hasher = crypto.createHash('sha512');
|
|
|
|
|
+ hasher.update(new Date().getTime() + user._id);
|
|
|
|
|
+
|
|
|
|
|
+ return hasher.digest('base64');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
|
*
|
|
*
|
|
@@ -75,7 +84,7 @@ module.exports = (crowi) => {
|
|
|
// TODO impl this after GW-4939
|
|
// TODO impl this after GW-4939
|
|
|
// AccessToken: "tempaccessdatahogehoge",
|
|
// AccessToken: "tempaccessdatahogehoge",
|
|
|
},
|
|
},
|
|
|
- customBotNonProxySettings: {
|
|
|
|
|
|
|
+ customBotWithoutProxySettings: {
|
|
|
// TODO impl this after GW-4939
|
|
// TODO impl this after GW-4939
|
|
|
// AccessToken: "tempaccessdatahogehoge",
|
|
// AccessToken: "tempaccessdatahogehoge",
|
|
|
slackSigningSecretEnvVars: crowi.configManager.getConfigFromEnvVars('crowi', 'slackbot:signingSecret'),
|
|
slackSigningSecretEnvVars: crowi.configManager.getConfigFromEnvVars('crowi', 'slackbot:signingSecret'),
|
|
@@ -95,24 +104,24 @@ module.exports = (crowi) => {
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
|
*
|
|
*
|
|
|
- * /slack-integration/custom-bot-non-proxy/:
|
|
|
|
|
|
|
+ * /slack-integration/custom-bot-without-proxy/:
|
|
|
* put:
|
|
* put:
|
|
|
- * tags: [CustomBotNonProxy]
|
|
|
|
|
- * operationId: putCustomBotNonProxy
|
|
|
|
|
- * summary: /slack-integration/custom-bot-non-proxy
|
|
|
|
|
- * description: Put customBotNonProxy setting.
|
|
|
|
|
|
|
+ * tags: [CustomBotWithoutProxy]
|
|
|
|
|
+ * operationId: putCustomBotWithoutProxy
|
|
|
|
|
+ * summary: /slack-integration/custom-bot-without-proxy
|
|
|
|
|
+ * description: Put customBotWithoutProxy setting.
|
|
|
* requestBody:
|
|
* requestBody:
|
|
|
* required: true
|
|
* required: true
|
|
|
* content:
|
|
* content:
|
|
|
* application/json:
|
|
* application/json:
|
|
|
* schema:
|
|
* schema:
|
|
|
- * $ref: '#/components/schemas/CustomBotNonProxy'
|
|
|
|
|
|
|
+ * $ref: '#/components/schemas/CustomBotWithoutProxy'
|
|
|
* responses:
|
|
* responses:
|
|
|
* 200:
|
|
* 200:
|
|
|
- * description: Succeeded to put CustomBotNonProxy setting.
|
|
|
|
|
|
|
+ * description: Succeeded to put CustomBotWithoutProxy setting.
|
|
|
*/
|
|
*/
|
|
|
- router.put('/custom-bot-non-proxy',
|
|
|
|
|
- accessTokenParser, loginRequiredStrictly, adminRequired, csrf, validator.CusotmBotNonProxy, apiV3FormValidator, async(req, res) => {
|
|
|
|
|
|
|
+ router.put('/custom-bot-without-proxy',
|
|
|
|
|
+ accessTokenParser, loginRequiredStrictly, adminRequired, csrf, validator.CusotmBotWithoutProxy, apiV3FormValidator, async(req, res) => {
|
|
|
const { slackSigningSecret, slackBotToken, botType } = req.body;
|
|
const { slackSigningSecret, slackBotToken, botType } = req.body;
|
|
|
|
|
|
|
|
const requestParams = {
|
|
const requestParams = {
|
|
@@ -129,12 +138,12 @@ module.exports = (crowi) => {
|
|
|
crowi.boltService.publishUpdatedMessage();
|
|
crowi.boltService.publishUpdatedMessage();
|
|
|
|
|
|
|
|
// TODO Impl to delete AccessToken both of Proxy and GROWI when botType changes.
|
|
// TODO Impl to delete AccessToken both of Proxy and GROWI when botType changes.
|
|
|
- const customBotNonProxySettingParams = {
|
|
|
|
|
|
|
+ const customBotWithoutProxySettingParams = {
|
|
|
slackSigningSecret: crowi.configManager.getConfig('crowi', 'slackbot:signingSecret'),
|
|
slackSigningSecret: crowi.configManager.getConfig('crowi', 'slackbot:signingSecret'),
|
|
|
slackBotToken: crowi.configManager.getConfig('crowi', 'slackbot:token'),
|
|
slackBotToken: crowi.configManager.getConfig('crowi', 'slackbot:token'),
|
|
|
slackBotType: crowi.configManager.getConfig('crowi', 'slackbot:type'),
|
|
slackBotType: crowi.configManager.getConfig('crowi', 'slackbot:type'),
|
|
|
};
|
|
};
|
|
|
- return res.apiv3({ customBotNonProxySettingParams });
|
|
|
|
|
|
|
+ return res.apiv3({ customBotWithoutProxySettingParams });
|
|
|
}
|
|
}
|
|
|
catch (error) {
|
|
catch (error) {
|
|
|
const msg = 'Error occured in updating Custom bot setting';
|
|
const msg = 'Error occured in updating Custom bot setting';
|
|
@@ -143,5 +152,33 @@ module.exports = (crowi) => {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @swagger
|
|
|
|
|
+ *
|
|
|
|
|
+ * /slack-integration/access-token:
|
|
|
|
|
+ * put:
|
|
|
|
|
+ * tags: [SlackIntegration]
|
|
|
|
|
+ * operationId: getCustomBotSetting
|
|
|
|
|
+ * summary: /slack-integration
|
|
|
|
|
+ * description: Generate accessToken
|
|
|
|
|
+ * responses:
|
|
|
|
|
+ * 200:
|
|
|
|
|
+ * description: Succeeded to update access token for slack
|
|
|
|
|
+ */
|
|
|
|
|
+ router.put('/access-token', loginRequiredStrictly, adminRequired, async(req, res) => {
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const accessToken = generateAccessToken(req.user);
|
|
|
|
|
+ await updateSlackBotSettings({ 'slackbot:access-token': accessToken });
|
|
|
|
|
+
|
|
|
|
|
+ return res.apiv3({ accessToken });
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (error) {
|
|
|
|
|
+ const msg = 'Error occured in updating access token for access token';
|
|
|
|
|
+ logger.error('Error', error);
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-accessToken-failed'));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
return router;
|
|
return router;
|
|
|
};
|
|
};
|