|
|
@@ -7,7 +7,10 @@ const axios = require('axios');
|
|
|
const urljoin = require('url-join');
|
|
|
|
|
|
const {
|
|
|
- getConnectionStatus, getConnectionStatuses, sendSuccessMessage, defaultSupportedCommandsNameForBroadcastUse, defaultSupportedCommandsNameForSingleUse,
|
|
|
+ getConnectionStatus, getConnectionStatuses,
|
|
|
+ sendSuccessMessage,
|
|
|
+ defaultSupportedCommandsNameForBroadcastUse, defaultSupportedCommandsNameForSingleUse,
|
|
|
+ REQUEST_TIMEOUT_FOR_GTOP,
|
|
|
} = require('@growi/slack');
|
|
|
|
|
|
const ErrorV3 = require('../../models/vo/error-apiv3');
|
|
|
@@ -16,6 +19,8 @@ const logger = loggerFactory('growi:routes:apiv3:slack-integration-settings');
|
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
|
+const OFFICIAL_SLACKBOT_PROXY_URI = 'https://slackbot-proxy.growi.org';
|
|
|
+
|
|
|
/**
|
|
|
* @swagger
|
|
|
* tags:
|
|
|
@@ -51,10 +56,10 @@ module.exports = (crowi) => {
|
|
|
const SlackAppIntegration = mongoose.model('SlackAppIntegration');
|
|
|
|
|
|
const validator = {
|
|
|
- BotType: [
|
|
|
+ botType: [
|
|
|
body('currentBotType').isString(),
|
|
|
],
|
|
|
- SlackIntegration: [
|
|
|
+ slackIntegration: [
|
|
|
body('currentBotType')
|
|
|
.isIn(['officialBot', 'customBotWithoutProxy', 'customBotWithProxy']),
|
|
|
],
|
|
|
@@ -62,42 +67,52 @@ module.exports = (crowi) => {
|
|
|
body('proxyUri').if(value => value !== '').trim().matches(/^(https?:\/\/)/)
|
|
|
.isURL({ require_tld: false }),
|
|
|
],
|
|
|
+ makePrimary: [
|
|
|
+ param('id').isMongoId().withMessage('id is required'),
|
|
|
+ ],
|
|
|
updateSupportedCommands: [
|
|
|
body('supportedCommandsForSingleUse').toArray(),
|
|
|
body('supportedCommandsForBroadcastUse').toArray(),
|
|
|
param('id').isMongoId().withMessage('id is required'),
|
|
|
],
|
|
|
- RelationTest: [
|
|
|
- body('slackAppIntegrationId').isMongoId(),
|
|
|
+ relationTest: [
|
|
|
+ param('id').isMongoId(),
|
|
|
body('channel').trim().isString(),
|
|
|
],
|
|
|
+ regenerateTokens: [
|
|
|
+ param('id').isMongoId(),
|
|
|
+ ],
|
|
|
deleteIntegration: [
|
|
|
- query('integrationIdToDelete').isMongoId(),
|
|
|
+ param('id').isMongoId(),
|
|
|
],
|
|
|
- SlackChannel: [
|
|
|
+ slackChannel: [
|
|
|
body('channel').trim().not().isEmpty()
|
|
|
.isString(),
|
|
|
],
|
|
|
};
|
|
|
|
|
|
- async function resetAllBotSettings() {
|
|
|
+ async function updateSlackBotSettings(params) {
|
|
|
+ const { configManager } = crowi;
|
|
|
+ // update config without publishing S2sMessage
|
|
|
+ return configManager.updateConfigsInTheSameNamespace('crowi', params, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ async function resetAllBotSettings(initializedType) {
|
|
|
await SlackAppIntegration.deleteMany();
|
|
|
|
|
|
const params = {
|
|
|
- 'slackbot:currentBotType': null,
|
|
|
+ 'slackbot:currentBotType': initializedType,
|
|
|
'slackbot:signingSecret': null,
|
|
|
'slackbot:token': null,
|
|
|
'slackbot:proxyServerUri': null,
|
|
|
};
|
|
|
- const { configManager } = crowi;
|
|
|
- // update config without publishing S2sMessage
|
|
|
- return configManager.updateConfigsInTheSameNamespace('crowi', params, true);
|
|
|
- }
|
|
|
|
|
|
- async function updateSlackBotSettings(params) {
|
|
|
- const { configManager } = crowi;
|
|
|
- // update config without publishing S2sMessage
|
|
|
- return configManager.updateConfigsInTheSameNamespace('crowi', params, true);
|
|
|
+ // set url if officialBot is specified
|
|
|
+ if (initializedType === 'officialBot') {
|
|
|
+ params['slackbot:proxyServerUri'] = OFFICIAL_SLACKBOT_PROXY_URI;
|
|
|
+ }
|
|
|
+
|
|
|
+ return updateSlackBotSettings(params);
|
|
|
}
|
|
|
|
|
|
async function getConnectionStatusesFromProxy(tokens) {
|
|
|
@@ -107,6 +122,7 @@ module.exports = (crowi) => {
|
|
|
const result = await axios.get(urljoin(proxyUri, '/g2s/connection-status'), {
|
|
|
headers: {
|
|
|
'x-growi-gtop-tokens': csv,
|
|
|
+ timeout: REQUEST_TIMEOUT_FOR_GTOP,
|
|
|
},
|
|
|
});
|
|
|
|
|
|
@@ -119,13 +135,22 @@ module.exports = (crowi) => {
|
|
|
throw new Error('Proxy URL is not registered');
|
|
|
}
|
|
|
|
|
|
- const headers = {
|
|
|
- 'x-growi-gtop-tokens': token,
|
|
|
- };
|
|
|
-
|
|
|
- const result = await axios[method](urljoin(proxyUri, endpoint), body, { headers });
|
|
|
+ try {
|
|
|
+ const result = await axios[method](
|
|
|
+ urljoin(proxyUri, endpoint),
|
|
|
+ body, {
|
|
|
+ headers: {
|
|
|
+ 'x-growi-gtop-tokens': token,
|
|
|
+ },
|
|
|
+ timeout: REQUEST_TIMEOUT_FOR_GTOP,
|
|
|
+ },
|
|
|
+ );
|
|
|
|
|
|
- return result.data;
|
|
|
+ return result.data;
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ throw new Error(`Requesting to proxy server failed: ${err.message}`);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -206,7 +231,7 @@ module.exports = (crowi) => {
|
|
|
});
|
|
|
}
|
|
|
catch (e) {
|
|
|
- errorMsg = 'Incorrect Proxy URL';
|
|
|
+ errorMsg = 'Something went wrong when retrieving information from Proxy Server.';
|
|
|
errorCode = 'test-connection-failed';
|
|
|
logger.error(errorMsg, e);
|
|
|
}
|
|
|
@@ -218,48 +243,15 @@ module.exports = (crowi) => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- /**
|
|
|
- * @swagger
|
|
|
- *
|
|
|
- * /slack-integration-settings/:
|
|
|
- * put:
|
|
|
- * tags: [SlackIntegration]
|
|
|
- * operationId: putSlackIntegration
|
|
|
- * summary: put /slack-integration
|
|
|
- * description: Put SlackIntegration setting.
|
|
|
- * requestBody:
|
|
|
- * required: true
|
|
|
- * content:
|
|
|
- * application/json:
|
|
|
- * schema:
|
|
|
- * $ref: '#/components/schemas/SlackIntegration'
|
|
|
- * responses:
|
|
|
- * 200:
|
|
|
- * description: Succeeded to put Slack Integration setting.
|
|
|
- */
|
|
|
- router.put('/', accessTokenParser, loginRequiredStrictly, adminRequired, csrf, validator.SlackIntegration, apiV3FormValidator, async(req, res) => {
|
|
|
- const { currentBotType } = req.body;
|
|
|
-
|
|
|
- const requestParams = {
|
|
|
- 'slackbot:currentBotType': currentBotType,
|
|
|
- };
|
|
|
-
|
|
|
- try {
|
|
|
- await updateSlackBotSettings(requestParams);
|
|
|
- crowi.slackBotService.publishUpdatedMessage();
|
|
|
|
|
|
- const slackIntegrationSettingsParams = {
|
|
|
- currentBotType: crowi.configManager.getConfig('crowi', 'slackbot:currentBotType'),
|
|
|
- };
|
|
|
- return res.apiv3({ slackIntegrationSettingsParams });
|
|
|
- }
|
|
|
- catch (error) {
|
|
|
- const msg = 'Error occured in updating Slack bot setting';
|
|
|
- logger.error('Error', error);
|
|
|
- return res.apiv3Err(new ErrorV3(msg, 'update-SlackIntegrationSetting-failed'), 500);
|
|
|
- }
|
|
|
- });
|
|
|
+ const handleBotTypeChanging = async(req, res, initializedBotType) => {
|
|
|
+ await resetAllBotSettings(initializedBotType);
|
|
|
+ crowi.slackIntegrationService.publishUpdatedMessage();
|
|
|
|
|
|
+ // TODO Impl to delete AccessToken both of Proxy and GROWI when botType changes.
|
|
|
+ const slackBotTypeParam = { slackBotType: crowi.configManager.getConfig('crowi', 'slackbot:currentBotType') };
|
|
|
+ return res.apiv3({ slackBotTypeParam });
|
|
|
+ };
|
|
|
|
|
|
/**
|
|
|
* @swagger
|
|
|
@@ -280,23 +272,15 @@ module.exports = (crowi) => {
|
|
|
* 200:
|
|
|
* description: Succeeded to put botType setting.
|
|
|
*/
|
|
|
- router.put('/bot-type', accessTokenParser, loginRequiredStrictly, adminRequired, csrf, validator.BotType, apiV3FormValidator, async(req, res) => {
|
|
|
+ router.put('/bot-type', accessTokenParser, loginRequiredStrictly, adminRequired, csrf, validator.botType, apiV3FormValidator, async(req, res) => {
|
|
|
const { currentBotType } = req.body;
|
|
|
|
|
|
- await resetAllBotSettings();
|
|
|
- const requestParams = { 'slackbot:currentBotType': currentBotType };
|
|
|
-
|
|
|
- if (currentBotType === 'officialBot') {
|
|
|
- requestParams['slackbot:proxyServerUri'] = 'https://slackbot-proxy.growi.org';
|
|
|
+ if (currentBotType == null) {
|
|
|
+ return res.apiv3Err(new ErrorV3('The param \'currentBotType\' must be specified.', 'update-CustomBotSetting-failed'), 400);
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- await updateSlackBotSettings(requestParams);
|
|
|
- crowi.slackBotService.publishUpdatedMessage();
|
|
|
-
|
|
|
- // TODO Impl to delete AccessToken both of Proxy and GROWI when botType changes.
|
|
|
- const slackBotTypeParam = { slackBotType: crowi.configManager.getConfig('crowi', 'slackbot:currentBotType') };
|
|
|
- return res.apiv3({ slackBotTypeParam });
|
|
|
+ await handleBotTypeChanging(req, res, currentBotType);
|
|
|
}
|
|
|
catch (error) {
|
|
|
const msg = 'Error occured in updating Custom bot setting';
|
|
|
@@ -324,22 +308,13 @@ module.exports = (crowi) => {
|
|
|
* description: Succeeded to delete botType setting.
|
|
|
*/
|
|
|
router.delete('/bot-type', accessTokenParser, loginRequiredStrictly, adminRequired, csrf, apiV3FormValidator, async(req, res) => {
|
|
|
-
|
|
|
- await resetAllBotSettings();
|
|
|
- const params = { 'slackbot:currentBotType': null };
|
|
|
-
|
|
|
try {
|
|
|
- await updateSlackBotSettings(params);
|
|
|
- crowi.slackBotService.publishUpdatedMessage();
|
|
|
-
|
|
|
- // TODO Impl to delete AccessToken both of Proxy and GROWI when botType changes.
|
|
|
- const slackBotTypeParam = { slackBotType: crowi.configManager.getConfig('crowi', 'slackbot:currentBotType') };
|
|
|
- return res.apiv3({ slackBotTypeParam });
|
|
|
+ await handleBotTypeChanging(req, res, null);
|
|
|
}
|
|
|
catch (error) {
|
|
|
- const msg = 'Error occured in updating Custom bot setting';
|
|
|
+ const msg = 'Error occured in resetting all';
|
|
|
logger.error('Error', error);
|
|
|
- return res.apiv3Err(new ErrorV3(msg, 'update-CustomBotSetting-failed'), 500);
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'resetting-all-failed'), 500);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -370,7 +345,7 @@ module.exports = (crowi) => {
|
|
|
};
|
|
|
try {
|
|
|
await updateSlackBotSettings(requestParams);
|
|
|
- crowi.slackBotService.publishUpdatedMessage();
|
|
|
+ crowi.slackIntegrationService.publishUpdatedMessage();
|
|
|
|
|
|
const customBotWithoutProxySettingParams = {
|
|
|
slackSigningSecret: crowi.configManager.getConfig('crowi', 'slackbot:signingSecret'),
|
|
|
@@ -390,7 +365,7 @@ module.exports = (crowi) => {
|
|
|
* @swagger
|
|
|
*
|
|
|
* /slack-integration-settings/slack-app-integrations:
|
|
|
- * put:
|
|
|
+ * post:
|
|
|
* tags: [SlackIntegration]
|
|
|
* operationId: putSlackAppIntegrations
|
|
|
* summary: /slack-integration
|
|
|
@@ -399,19 +374,20 @@ module.exports = (crowi) => {
|
|
|
* 200:
|
|
|
* description: Succeeded to create slack app integration
|
|
|
*/
|
|
|
- router.put('/slack-app-integrations', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
|
|
|
- const SlackAppIntegrationRecordsNum = await SlackAppIntegration.countDocuments();
|
|
|
- if (SlackAppIntegrationRecordsNum >= 10) {
|
|
|
- const msg = 'Not be able to create more than 10 slack workspace integration settings';
|
|
|
- logger.error('Error', msg);
|
|
|
- return res.apiv3Err(new ErrorV3(msg, 'create-slackAppIntegeration-failed'), 500);
|
|
|
- }
|
|
|
-
|
|
|
+ router.post('/slack-app-integrations', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
|
|
|
const { tokenGtoP, tokenPtoG } = await SlackAppIntegration.generateUniqueAccessTokens();
|
|
|
try {
|
|
|
+ const count = await SlackAppIntegration.countDocuments();
|
|
|
+ if (count >= 10) {
|
|
|
+ const msg = 'Not be able to create more than 10 slack workspace integration settings';
|
|
|
+ logger.error('Error', msg);
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'create-slackAppIntegeration-failed'), 500);
|
|
|
+ }
|
|
|
+
|
|
|
const slackAppTokens = await SlackAppIntegration.create({
|
|
|
tokenGtoP,
|
|
|
tokenPtoG,
|
|
|
+ isPrimary: count === 0 ? true : undefined,
|
|
|
supportedCommandsForBroadcastUse: defaultSupportedCommandsNameForBroadcastUse,
|
|
|
supportedCommandsForSingleUse: defaultSupportedCommandsNameForSingleUse,
|
|
|
});
|
|
|
@@ -427,37 +403,7 @@ module.exports = (crowi) => {
|
|
|
/**
|
|
|
* @swagger
|
|
|
*
|
|
|
- * /slack-integration-settings/regenerate-tokens:
|
|
|
- * put:
|
|
|
- * tags: [SlackIntegration]
|
|
|
- * operationId: putRegenerateTokens
|
|
|
- * summary: /slack-integration
|
|
|
- * description: Regenerate SlackAppTokens
|
|
|
- * responses:
|
|
|
- * 200:
|
|
|
- * description: Succeeded to regenerate slack app tokens
|
|
|
- */
|
|
|
- router.put('/regenerate-tokens', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
|
|
|
-
|
|
|
- const { slackAppIntegrationId } = req.body;
|
|
|
-
|
|
|
- try {
|
|
|
- const { tokenGtoP, tokenPtoG } = await SlackAppIntegration.generateUniqueAccessTokens();
|
|
|
- const slackAppTokens = await SlackAppIntegration.findByIdAndUpdate(slackAppIntegrationId, { tokenGtoP, tokenPtoG });
|
|
|
-
|
|
|
- return res.apiv3(slackAppTokens, 200);
|
|
|
- }
|
|
|
- catch (error) {
|
|
|
- const msg = 'Error occurred during regenerating slack app tokens';
|
|
|
- logger.error('Error', error);
|
|
|
- return res.apiv3Err(new ErrorV3(msg, 'regenerating-slackAppTokens-failed'), 500);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- /**
|
|
|
- * @swagger
|
|
|
- *
|
|
|
- * /slack-integration-settings/slack-app-integration:
|
|
|
+ * /slack-integration-settings/slack-app-integrations/:id:
|
|
|
* delete:
|
|
|
* tags: [SlackIntegration]
|
|
|
* operationId: deleteAccessTokens
|
|
|
@@ -467,11 +413,19 @@ module.exports = (crowi) => {
|
|
|
* 200:
|
|
|
* description: Succeeded to delete access tokens for slack
|
|
|
*/
|
|
|
- router.delete('/slack-app-integration', validator.deleteIntegration, apiV3FormValidator, async(req, res) => {
|
|
|
+ router.delete('/slack-app-integrations/:id', validator.deleteIntegration, apiV3FormValidator, async(req, res) => {
|
|
|
const SlackAppIntegration = mongoose.model('SlackAppIntegration');
|
|
|
- const { integrationIdToDelete } = req.query;
|
|
|
+ const { id } = req.params;
|
|
|
+
|
|
|
try {
|
|
|
- const response = await SlackAppIntegration.findOneAndDelete({ _id: integrationIdToDelete });
|
|
|
+ const response = await SlackAppIntegration.findOneAndDelete({ _id: id });
|
|
|
+
|
|
|
+ // update primary
|
|
|
+ const countOfPrimary = await SlackAppIntegration.countDocuments({ isPrimary: true });
|
|
|
+ if (countOfPrimary === 0) {
|
|
|
+ await SlackAppIntegration.updateOne({}, { isPrimary: true });
|
|
|
+ }
|
|
|
+
|
|
|
return res.apiv3({ response });
|
|
|
}
|
|
|
catch (error) {
|
|
|
@@ -488,13 +442,13 @@ module.exports = (crowi) => {
|
|
|
|
|
|
try {
|
|
|
await updateSlackBotSettings(requestParams);
|
|
|
- crowi.slackBotService.publishUpdatedMessage();
|
|
|
+ crowi.slackIntegrationService.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 res.apiv3Err(new ErrorV3(msg, 'delete-SlackAppIntegration-failed'), 500);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
@@ -502,7 +456,83 @@ module.exports = (crowi) => {
|
|
|
/**
|
|
|
* @swagger
|
|
|
*
|
|
|
- * /slack-integration-settings/:id/supported-commands:
|
|
|
+ * /slack-integration-settings/slack-app-integrations/:id/makeprimary:
|
|
|
+ * put:
|
|
|
+ * tags: [SlackIntegration]
|
|
|
+ * operationId: makePrimary
|
|
|
+ * summary: /slack-integration
|
|
|
+ * description: Make SlackAppTokens primary
|
|
|
+ * responses:
|
|
|
+ * 200:
|
|
|
+ * description: Succeeded to make it primary
|
|
|
+ */
|
|
|
+ // eslint-disable-next-line max-len
|
|
|
+ router.put('/slack-app-integrations/:id/make-primary', loginRequiredStrictly, adminRequired, csrf, validator.makePrimary, apiV3FormValidator, async(req, res) => {
|
|
|
+
|
|
|
+ const { id } = req.params;
|
|
|
+
|
|
|
+ try {
|
|
|
+ await SlackAppIntegration.bulkWrite([
|
|
|
+ // unset isPrimary for others
|
|
|
+ {
|
|
|
+ updateMany: {
|
|
|
+ filter: { _id: { $ne: id } },
|
|
|
+ update: { $unset: { isPrimary: '' } },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ // set primary
|
|
|
+ {
|
|
|
+ updateOne: {
|
|
|
+ filter: { _id: id },
|
|
|
+ update: { isPrimary: true },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return res.apiv3();
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ const msg = 'Error occurred during making SlackAppIntegration primary';
|
|
|
+ logger.error('Error', error);
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'making-primary-failed'), 500);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @swagger
|
|
|
+ *
|
|
|
+ * /slack-integration-settings/slack-app-integrations/:id/regenerate-tokens:
|
|
|
+ * put:
|
|
|
+ * tags: [SlackIntegration]
|
|
|
+ * operationId: putRegenerateTokens
|
|
|
+ * summary: /slack-integration
|
|
|
+ * description: Regenerate SlackAppTokens
|
|
|
+ * responses:
|
|
|
+ * 200:
|
|
|
+ * description: Succeeded to regenerate slack app tokens
|
|
|
+ */
|
|
|
+ // eslint-disable-next-line max-len
|
|
|
+ router.put('/slack-app-integrations/:id/regenerate-tokens', loginRequiredStrictly, adminRequired, csrf, validator.regenerateTokens, apiV3FormValidator, async(req, res) => {
|
|
|
+
|
|
|
+ const { id } = req.params;
|
|
|
+
|
|
|
+ try {
|
|
|
+ const { tokenGtoP, tokenPtoG } = await SlackAppIntegration.generateUniqueAccessTokens();
|
|
|
+ const slackAppTokens = await SlackAppIntegration.findByIdAndUpdate(id, { tokenGtoP, tokenPtoG });
|
|
|
+
|
|
|
+ return res.apiv3(slackAppTokens, 200);
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ const msg = 'Error occurred during regenerating slack app tokens';
|
|
|
+ logger.error('Error', error);
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'regenerating-slackAppTokens-failed'), 500);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @swagger
|
|
|
+ *
|
|
|
+ * /slack-integration-settings/slack-app-integrations/:id/supported-commands:
|
|
|
* put:
|
|
|
* tags: [SlackIntegration]
|
|
|
* operationId: putSupportedCommands
|
|
|
@@ -512,7 +542,8 @@ module.exports = (crowi) => {
|
|
|
* 200:
|
|
|
* description: Succeeded to update supported commands
|
|
|
*/
|
|
|
- router.put('/:id/supported-commands', loginRequiredStrictly, adminRequired, csrf, validator.updateSupportedCommands, apiV3FormValidator, async(req, res) => {
|
|
|
+ // eslint-disable-next-line max-len
|
|
|
+ router.put('/slack-app-integrations/:id/supported-commands', loginRequiredStrictly, adminRequired, csrf, validator.updateSupportedCommands, apiV3FormValidator, async(req, res) => {
|
|
|
const { supportedCommandsForBroadcastUse, supportedCommandsForSingleUse } = req.body;
|
|
|
const { id } = req.params;
|
|
|
|
|
|
@@ -523,56 +554,58 @@ module.exports = (crowi) => {
|
|
|
{ new: true },
|
|
|
);
|
|
|
|
|
|
- await requestToProxyServer(
|
|
|
- slackAppIntegration.tokenGtoP,
|
|
|
- 'put',
|
|
|
- '/g2s/supported-commands',
|
|
|
- {
|
|
|
- supportedCommandsForBroadcastUse: slackAppIntegration.supportedCommandsForBroadcastUse,
|
|
|
- supportedCommandsForSingleUse: slackAppIntegration.supportedCommandsForSingleUse,
|
|
|
- },
|
|
|
- );
|
|
|
+ const proxyUri = crowi.configManager.getConfig('crowi', 'slackbot:proxyServerUri');
|
|
|
+ if (proxyUri != null) {
|
|
|
+ await requestToProxyServer(
|
|
|
+ slackAppIntegration.tokenGtoP,
|
|
|
+ 'put',
|
|
|
+ '/g2s/supported-commands',
|
|
|
+ {
|
|
|
+ supportedCommandsForBroadcastUse: slackAppIntegration.supportedCommandsForBroadcastUse,
|
|
|
+ supportedCommandsForSingleUse: slackAppIntegration.supportedCommandsForSingleUse,
|
|
|
+ },
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
return res.apiv3({ slackAppIntegration });
|
|
|
}
|
|
|
catch (error) {
|
|
|
- const msg = 'Error occured in updating Custom bot setting';
|
|
|
+ const msg = `Error occured in updating settings. Cause: ${error.message}`;
|
|
|
logger.error('Error', error);
|
|
|
- return res.apiv3Err(new ErrorV3(msg, 'update-CustomBotSetting-failed'), 500);
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-supported-commands-failed'), 500);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* @swagger
|
|
|
*
|
|
|
- * /slack-integration-settings/with-proxy/relation-test:
|
|
|
+ * /slack-integration-settings/slack-app-integrations/:id/relation-test:
|
|
|
* post:
|
|
|
* tags: [botType]
|
|
|
* operationId: postRelationTest
|
|
|
- * summary: /slack-integration/bot-type
|
|
|
+ * summary: Test relation
|
|
|
* description: Delete botType setting.
|
|
|
- * requestBody:
|
|
|
- * content:
|
|
|
- * application/json:
|
|
|
- * schema:
|
|
|
- * properties:
|
|
|
- * slackAppIntegrationId:
|
|
|
- * type: string
|
|
|
* responses:
|
|
|
* 200:
|
|
|
* description: Succeeded to delete botType setting.
|
|
|
*/
|
|
|
- router.post('/with-proxy/relation-test', loginRequiredStrictly, adminRequired, csrf, validator.RelationTest, apiV3FormValidator, async(req, res) => {
|
|
|
+ // eslint-disable-next-line max-len
|
|
|
+ router.post('/slack-app-integrations/:id/relation-test', loginRequiredStrictly, adminRequired, csrf, validator.relationTest, apiV3FormValidator, async(req, res) => {
|
|
|
const currentBotType = crowi.configManager.getConfig('crowi', 'slackbot:currentBotType');
|
|
|
if (currentBotType === 'customBotWithoutProxy') {
|
|
|
const msg = 'Not Proxy Type';
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'not-proxy-type'), 400);
|
|
|
}
|
|
|
|
|
|
- const { slackAppIntegrationId } = req.body;
|
|
|
+ const proxyUri = crowi.configManager.getConfig('crowi', 'slackbot:proxyServerUri');
|
|
|
+ if (proxyUri == null) {
|
|
|
+ return res.apiv3Err(new ErrorV3('Proxy URL is null.', 'not-proxy-Uri'), 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ const { id } = req.params;
|
|
|
let slackBotToken;
|
|
|
try {
|
|
|
- const slackAppIntegration = await SlackAppIntegration.findOne({ _id: slackAppIntegrationId });
|
|
|
+ const slackAppIntegration = await SlackAppIntegration.findOne({ _id: id });
|
|
|
if (slackAppIntegration == null) {
|
|
|
const msg = 'Could not find SlackAppIntegration by id';
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'find-slackAppIntegration-failed'), 400);
|
|
|
@@ -631,7 +664,7 @@ module.exports = (crowi) => {
|
|
|
* 200:
|
|
|
* description: Succeeded to connect to slack work space.
|
|
|
*/
|
|
|
- router.post('/without-proxy/test', loginRequiredStrictly, adminRequired, csrf, validator.SlackChannel, apiV3FormValidator, async(req, res) => {
|
|
|
+ router.post('/without-proxy/test', loginRequiredStrictly, adminRequired, csrf, validator.slackChannel, apiV3FormValidator, async(req, res) => {
|
|
|
const currentBotType = crowi.configManager.getConfig('crowi', 'slackbot:currentBotType');
|
|
|
if (currentBotType !== 'customBotWithoutProxy') {
|
|
|
const msg = 'Select Without Proxy Type';
|