|
@@ -1,5 +1,8 @@
|
|
|
|
|
+import { SlackbotType } from '@growi/slack';
|
|
|
|
|
+
|
|
|
import loggerFactory from '~/utils/logger';
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
|
|
+
|
|
|
const mongoose = require('mongoose');
|
|
const mongoose = require('mongoose');
|
|
|
const express = require('express');
|
|
const express = require('express');
|
|
|
const { body, query, param } = require('express-validator');
|
|
const { body, query, param } = require('express-validator');
|
|
@@ -61,7 +64,7 @@ module.exports = (crowi) => {
|
|
|
],
|
|
],
|
|
|
slackIntegration: [
|
|
slackIntegration: [
|
|
|
body('currentBotType')
|
|
body('currentBotType')
|
|
|
- .isIn(['officialBot', 'customBotWithoutProxy', 'customBotWithProxy']),
|
|
|
|
|
|
|
+ .isIn(Object.values(SlackbotType)),
|
|
|
],
|
|
],
|
|
|
proxyUri: [
|
|
proxyUri: [
|
|
|
body('proxyUri').if(value => value !== '').trim().matches(/^(https?:\/\/)/)
|
|
body('proxyUri').if(value => value !== '').trim().matches(/^(https?:\/\/)/)
|
|
@@ -108,7 +111,7 @@ module.exports = (crowi) => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// set url if officialBot is specified
|
|
// set url if officialBot is specified
|
|
|
- if (initializedType === 'officialBot') {
|
|
|
|
|
|
|
+ if (initializedType === SlackbotType.OFFICIAL) {
|
|
|
params['slackbot:proxyServerUri'] = OFFICIAL_SLACKBOT_PROXY_URI;
|
|
params['slackbot:proxyServerUri'] = OFFICIAL_SLACKBOT_PROXY_URI;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -173,7 +176,7 @@ module.exports = (crowi) => {
|
|
|
|
|
|
|
|
// retrieve settings
|
|
// retrieve settings
|
|
|
const settings = {};
|
|
const settings = {};
|
|
|
- if (currentBotType === 'customBotWithoutProxy') {
|
|
|
|
|
|
|
+ if (currentBotType === SlackbotType.CUSTOM_WITHOUT_PROXY) {
|
|
|
settings.slackSigningSecretEnvVars = configManager.getConfigFromEnvVars('crowi', 'slackbot:signingSecret');
|
|
settings.slackSigningSecretEnvVars = configManager.getConfigFromEnvVars('crowi', 'slackbot:signingSecret');
|
|
|
settings.slackBotTokenEnvVars = configManager.getConfigFromEnvVars('crowi', 'slackbot:token');
|
|
settings.slackBotTokenEnvVars = configManager.getConfigFromEnvVars('crowi', 'slackbot:token');
|
|
|
settings.slackSigningSecret = configManager.getConfig('crowi', 'slackbot:signingSecret');
|
|
settings.slackSigningSecret = configManager.getConfig('crowi', 'slackbot:signingSecret');
|
|
@@ -191,7 +194,7 @@ module.exports = (crowi) => {
|
|
|
if (currentBotType == null) {
|
|
if (currentBotType == null) {
|
|
|
// no need to do anything
|
|
// no need to do anything
|
|
|
}
|
|
}
|
|
|
- else if (currentBotType === 'customBotWithoutProxy') {
|
|
|
|
|
|
|
+ else if (currentBotType === SlackbotType.CUSTOM_WITHOUT_PROXY) {
|
|
|
const token = settings.slackBotToken;
|
|
const token = settings.slackBotToken;
|
|
|
// check the token is not null
|
|
// check the token is not null
|
|
|
if (token != null) {
|
|
if (token != null) {
|
|
@@ -333,7 +336,7 @@ module.exports = (crowi) => {
|
|
|
*/
|
|
*/
|
|
|
router.put('/without-proxy/update-settings', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
|
|
router.put('/without-proxy/update-settings', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
|
|
|
const currentBotType = crowi.configManager.getConfig('crowi', 'slackbot:currentBotType');
|
|
const currentBotType = crowi.configManager.getConfig('crowi', 'slackbot:currentBotType');
|
|
|
- if (currentBotType !== 'customBotWithoutProxy') {
|
|
|
|
|
|
|
+ if (currentBotType !== SlackbotType.CUSTOM_WITHOUT_PROXY) {
|
|
|
const msg = 'Not CustomBotWithoutProxy';
|
|
const msg = 'Not CustomBotWithoutProxy';
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'not-customBotWithoutProxy'), 400);
|
|
return res.apiv3Err(new ErrorV3(msg, 'not-customBotWithoutProxy'), 400);
|
|
|
}
|
|
}
|
|
@@ -592,7 +595,7 @@ module.exports = (crowi) => {
|
|
|
// eslint-disable-next-line max-len
|
|
// eslint-disable-next-line max-len
|
|
|
router.post('/slack-app-integrations/:id/relation-test', loginRequiredStrictly, adminRequired, csrf, validator.relationTest, apiV3FormValidator, async(req, res) => {
|
|
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');
|
|
const currentBotType = crowi.configManager.getConfig('crowi', 'slackbot:currentBotType');
|
|
|
- if (currentBotType === 'customBotWithoutProxy') {
|
|
|
|
|
|
|
+ if (currentBotType === SlackbotType.CUSTOM_WITHOUT_PROXY) {
|
|
|
const msg = 'Not Proxy Type';
|
|
const msg = 'Not Proxy Type';
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'not-proxy-type'), 400);
|
|
return res.apiv3Err(new ErrorV3(msg, 'not-proxy-type'), 400);
|
|
|
}
|
|
}
|
|
@@ -666,7 +669,7 @@ module.exports = (crowi) => {
|
|
|
*/
|
|
*/
|
|
|
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');
|
|
const currentBotType = crowi.configManager.getConfig('crowi', 'slackbot:currentBotType');
|
|
|
- if (currentBotType !== 'customBotWithoutProxy') {
|
|
|
|
|
|
|
+ if (currentBotType !== SlackbotType.CUSTOM_WITHOUT_PROXY) {
|
|
|
const msg = 'Select Without Proxy Type';
|
|
const msg = 'Select Without Proxy Type';
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'select-not-proxy-type'), 400);
|
|
return res.apiv3Err(new ErrorV3(msg, 'select-not-proxy-type'), 400);
|
|
|
}
|
|
}
|