|
|
@@ -2,8 +2,6 @@ const mongoose = require('mongoose');
|
|
|
const express = require('express');
|
|
|
const { body } = require('express-validator');
|
|
|
const axios = require('axios');
|
|
|
-const crypto = require('crypto');
|
|
|
-
|
|
|
const loggerFactory = require('@alias/logger');
|
|
|
|
|
|
const { getConnectionStatuses } = require('@growi/slack');
|
|
|
@@ -82,14 +80,6 @@ module.exports = (crowi) => {
|
|
|
return configManager.updateConfigsInTheSameNamespace('crowi', params, true);
|
|
|
}
|
|
|
|
|
|
- // eslint-disable-next-line no-unused-vars
|
|
|
- function generateAccessToken(user) {
|
|
|
- const hasher = crypto.createHash('sha512');
|
|
|
- hasher.update(new Date().getTime() + user._id);
|
|
|
-
|
|
|
- return hasher.digest('base64');
|
|
|
- }
|
|
|
-
|
|
|
async function getConnectionStatusesFromProxy(tokens) {
|
|
|
const csv = tokens.join(',');
|
|
|
|
|
|
@@ -139,7 +129,10 @@ module.exports = (crowi) => {
|
|
|
|
|
|
// retrieve connection statuses
|
|
|
let connectionStatuses;
|
|
|
- if (currentBotType === 'customBotWithoutProxy') {
|
|
|
+ if (currentBotType == null) {
|
|
|
+ // TODO imple null action
|
|
|
+ }
|
|
|
+ else if (currentBotType === 'customBotWithoutProxy') {
|
|
|
const token = settings.slackBotToken;
|
|
|
// check the token is not null
|
|
|
if (token != null) {
|
|
|
@@ -268,29 +261,73 @@ module.exports = (crowi) => {
|
|
|
/**
|
|
|
* @swagger
|
|
|
*
|
|
|
- * /slack-integration/access-token:
|
|
|
+ * /slack-integration/without-proxy/update-settings/:
|
|
|
+ * put:
|
|
|
+ * tags: [UpdateWithoutProxySettings]
|
|
|
+ * operationId: putWithoutProxySettings
|
|
|
+ * summary: update customBotWithoutProxy settings
|
|
|
+ * description: Update customBotWithoutProxy setting.
|
|
|
+ * responses:
|
|
|
+ * 200:
|
|
|
+ * description: Succeeded to put CustomBotWithoutProxy setting.
|
|
|
+ */
|
|
|
+ router.put('/without-proxy/update-settings', async(req, res) => {
|
|
|
+ const currentBotType = crowi.configManager.getConfig('crowi', 'slackbot:currentBotType');
|
|
|
+ if (currentBotType !== 'customBotWithoutProxy') {
|
|
|
+ const msg = 'Not CustomBotWithoutProxy';
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'not-customBotWithoutProxy'), 400);
|
|
|
+ }
|
|
|
+ const { slackSigningSecret, slackBotToken } = req.body;
|
|
|
+ const requestParams = {
|
|
|
+ 'slackbot:signingSecret': slackSigningSecret,
|
|
|
+ 'slackbot:token': slackBotToken,
|
|
|
+ };
|
|
|
+ try {
|
|
|
+ await updateSlackBotSettings(requestParams);
|
|
|
+ crowi.slackBotService.publishUpdatedMessage();
|
|
|
+
|
|
|
+ const customBotWithoutProxySettingParams = {
|
|
|
+ slackSigningSecret: crowi.configManager.getConfig('crowi', 'slackbot:signingSecret'),
|
|
|
+ slackBotToken: crowi.configManager.getConfig('crowi', 'slackbot:token'),
|
|
|
+ };
|
|
|
+ return res.apiv3({ customBotWithoutProxySettingParams });
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ const msg = 'Error occured in updating Custom bot setting';
|
|
|
+ logger.error('Error', error);
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-CustomBotSetting-failed'), 500);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @swagger
|
|
|
+ *
|
|
|
+ * /slack-integration/access-tokens:
|
|
|
* put:
|
|
|
* tags: [SlackIntegration]
|
|
|
- * operationId:
|
|
|
+ * operationId: putAccessTokens
|
|
|
* summary: /slack-integration
|
|
|
- * description: Generate accessToken
|
|
|
+ * description: Generate accessTokens
|
|
|
* responses:
|
|
|
* 200:
|
|
|
- * description: Succeeded to update access token for slack
|
|
|
+ * description: Succeeded to update access tokens for slack
|
|
|
*/
|
|
|
router.put('/access-tokens', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
|
|
|
const SlackAppIntegration = mongoose.model('SlackAppIntegration');
|
|
|
let checkTokens;
|
|
|
let tokenGtoP;
|
|
|
let tokenPtoG;
|
|
|
+ let generateTokens;
|
|
|
do {
|
|
|
- // TODO imple generate tokens at GW-5859. The following tokens is temporary.
|
|
|
- tokenGtoP = 'v2';
|
|
|
- tokenPtoG = 'v2';
|
|
|
+ generateTokens = SlackAppIntegration.generateAccessToken();
|
|
|
+ tokenGtoP = generateTokens[0];
|
|
|
+ tokenPtoG = generateTokens[1];
|
|
|
// 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);
|
|
|
@@ -302,5 +339,24 @@ module.exports = (crowi) => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ router.put('/proxy-uri', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
|
|
|
+ const { proxyUri } = req.body;
|
|
|
+ console.log('proxyUri', proxyUri);
|
|
|
+
|
|
|
+ const requestParams = { 'slackbot:serverUri': proxyUri };
|
|
|
+
|
|
|
+ try {
|
|
|
+ await updateSlackBotSettings(requestParams);
|
|
|
+ crowi.slackBotService.publishUpdatedMessage();
|
|
|
+ return res.apiv3({});
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ const msg = 'Error occured in updating Custom bot setting';
|
|
|
+ logger.error('Error', error);
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-CustomBotSetting-failed'), 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
return router;
|
|
|
};
|