|
@@ -48,7 +48,8 @@ module.exports = (crowi) => {
|
|
|
const csrf = require('../../middlewares/csrf')(crowi);
|
|
const csrf = require('../../middlewares/csrf')(crowi);
|
|
|
const apiV3FormValidator = require('../../middlewares/apiv3-form-validator')(crowi);
|
|
const apiV3FormValidator = require('../../middlewares/apiv3-form-validator')(crowi);
|
|
|
|
|
|
|
|
- const SlackAppIntegration = mongoose.model('SlackAppIntegration');
|
|
|
|
|
|
|
+ // const SlackAppIntegration = mongoose.model('SlackAppIntegration');
|
|
|
|
|
+ const SlackAppIntegrationMock = mongoose.model('SlackAppIntegrationMock');
|
|
|
|
|
|
|
|
const validator = {
|
|
const validator = {
|
|
|
BotType: [
|
|
BotType: [
|
|
@@ -81,7 +82,7 @@ module.exports = (crowi) => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
async function resetAllBotSettings() {
|
|
async function resetAllBotSettings() {
|
|
|
- await SlackAppIntegration.deleteMany();
|
|
|
|
|
|
|
+ await SlackAppIntegrationMock.deleteMany();
|
|
|
|
|
|
|
|
const params = {
|
|
const params = {
|
|
|
'slackbot:currentBotType': null,
|
|
'slackbot:currentBotType': null,
|
|
@@ -182,7 +183,7 @@ module.exports = (crowi) => {
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
try {
|
|
try {
|
|
|
- const slackAppIntegrations = await SlackAppIntegration.find();
|
|
|
|
|
|
|
+ const slackAppIntegrations = await SlackAppIntegrationMock.find();
|
|
|
settings.slackAppIntegrations = slackAppIntegrations;
|
|
settings.slackAppIntegrations = slackAppIntegrations;
|
|
|
}
|
|
}
|
|
|
catch (e) {
|
|
catch (e) {
|
|
@@ -400,16 +401,16 @@ module.exports = (crowi) => {
|
|
|
* description: Succeeded to create slack app integration
|
|
* description: Succeeded to create slack app integration
|
|
|
*/
|
|
*/
|
|
|
router.put('/slack-app-integrations', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
|
|
router.put('/slack-app-integrations', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
|
|
|
- const SlackAppIntegrationRecordsNum = await SlackAppIntegration.countDocuments();
|
|
|
|
|
|
|
+ const SlackAppIntegrationRecordsNum = await SlackAppIntegrationMock.countDocuments();
|
|
|
if (SlackAppIntegrationRecordsNum >= 10) {
|
|
if (SlackAppIntegrationRecordsNum >= 10) {
|
|
|
const msg = 'Not be able to create more than 10 slack workspace integration settings';
|
|
const msg = 'Not be able to create more than 10 slack workspace integration settings';
|
|
|
logger.error('Error', msg);
|
|
logger.error('Error', msg);
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'create-slackAppIntegeration-failed'), 500);
|
|
return res.apiv3Err(new ErrorV3(msg, 'create-slackAppIntegeration-failed'), 500);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const { tokenGtoP, tokenPtoG } = await SlackAppIntegration.generateUniqueAccessTokens();
|
|
|
|
|
|
|
+ const { tokenGtoP, tokenPtoG } = await SlackAppIntegrationMock.generateUniqueAccessTokens();
|
|
|
try {
|
|
try {
|
|
|
- const slackAppTokens = await SlackAppIntegration.create({
|
|
|
|
|
|
|
+ const slackAppTokens = await SlackAppIntegrationMock.create({
|
|
|
tokenGtoP,
|
|
tokenGtoP,
|
|
|
tokenPtoG,
|
|
tokenPtoG,
|
|
|
supportedCommandsForBroadcastUse: defaultSupportedCommandsNameForBroadcastUse,
|
|
supportedCommandsForBroadcastUse: defaultSupportedCommandsNameForBroadcastUse,
|
|
@@ -442,8 +443,8 @@ module.exports = (crowi) => {
|
|
|
const { slackAppIntegrationId } = req.body;
|
|
const { slackAppIntegrationId } = req.body;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- const { tokenGtoP, tokenPtoG } = await SlackAppIntegration.generateUniqueAccessTokens();
|
|
|
|
|
- const slackAppTokens = await SlackAppIntegration.findByIdAndUpdate(slackAppIntegrationId, { tokenGtoP, tokenPtoG });
|
|
|
|
|
|
|
+ const { tokenGtoP, tokenPtoG } = await SlackAppIntegrationMock.generateUniqueAccessTokens();
|
|
|
|
|
+ const slackAppTokens = await SlackAppIntegrationMock.findByIdAndUpdate(slackAppIntegrationId, { tokenGtoP, tokenPtoG });
|
|
|
|
|
|
|
|
return res.apiv3(slackAppTokens, 200);
|
|
return res.apiv3(slackAppTokens, 200);
|
|
|
}
|
|
}
|
|
@@ -517,7 +518,7 @@ module.exports = (crowi) => {
|
|
|
const { id } = req.params;
|
|
const { id } = req.params;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- const slackAppIntegration = await SlackAppIntegration.findByIdAndUpdate(
|
|
|
|
|
|
|
+ const slackAppIntegration = await SlackAppIntegrationMock.findByIdAndUpdate(
|
|
|
id,
|
|
id,
|
|
|
{ supportedCommandsForBroadcastUse, supportedCommandsForSingleUse },
|
|
{ supportedCommandsForBroadcastUse, supportedCommandsForSingleUse },
|
|
|
{ new: true },
|
|
{ new: true },
|
|
@@ -572,7 +573,7 @@ module.exports = (crowi) => {
|
|
|
const { slackAppIntegrationId } = req.body;
|
|
const { slackAppIntegrationId } = req.body;
|
|
|
let slackBotToken;
|
|
let slackBotToken;
|
|
|
try {
|
|
try {
|
|
|
- const slackAppIntegration = await SlackAppIntegration.findOne({ _id: slackAppIntegrationId });
|
|
|
|
|
|
|
+ const slackAppIntegration = await SlackAppIntegrationMock.findOne({ _id: slackAppIntegrationId });
|
|
|
if (slackAppIntegration == null) {
|
|
if (slackAppIntegration == null) {
|
|
|
const msg = 'Could not find SlackAppIntegration by id';
|
|
const msg = 'Could not find SlackAppIntegration by id';
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'find-slackAppIntegration-failed'), 400);
|
|
return res.apiv3Err(new ErrorV3(msg, 'find-slackAppIntegration-failed'), 400);
|