|
|
@@ -378,26 +378,19 @@ module.exports = (crowi) => {
|
|
|
* 200:
|
|
|
* description: Succeeded to create slack app integration
|
|
|
*/
|
|
|
- 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);
|
|
|
- }
|
|
|
+ router.put('/slack-app-integrations', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
|
|
|
+ const SlackAppIntegrationMock = mongoose.model('SlackAppIntegrationMock');
|
|
|
+ const SlackAppIntegrationMockRecordsNum = await SlackAppIntegrationMock.countDocuments();
|
|
|
+ if (SlackAppIntegrationMockRecordsNum >= 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,
|
|
|
- });
|
|
|
+ const { tokenGtoP, tokenPtoG } = await SlackAppIntegrationMock.generateUniqueAccessTokens();
|
|
|
+ try {
|
|
|
// MOCK DATA DELETE THIS GW-6972 ---------------
|
|
|
/* This code represents the creation of the new SlackAppIntegration model instance. */
|
|
|
- const SlackAppIntegrationMock = mongoose.model('SlackAppIntegrationMock');
|
|
|
const initialSupportedCommandsForBroadcastUse = new Map();
|
|
|
const initialSupportedCommandsForSingleUse = new Map();
|
|
|
defaultSupportedCommandsNameForBroadcastUse.forEach((commandName) => {
|
|
|
@@ -406,14 +399,14 @@ module.exports = (crowi) => {
|
|
|
defaultSupportedCommandsNameForSingleUse.forEach((commandName) => {
|
|
|
initialSupportedCommandsForSingleUse.set(commandName, true);
|
|
|
});
|
|
|
- const MOCK = await SlackAppIntegrationMock.create({
|
|
|
+ const slackAppTokensMOCK = await SlackAppIntegrationMock.create({
|
|
|
tokenGtoP,
|
|
|
tokenPtoG,
|
|
|
permissionsForBroadcastUseCommands: initialSupportedCommandsForBroadcastUse,
|
|
|
permissionsForSingleUseCommands: initialSupportedCommandsForSingleUse,
|
|
|
});
|
|
|
// MOCK DATA DELETE THIS GW-6972 ---------------
|
|
|
- return res.apiv3(slackAppTokens, 200);
|
|
|
+ return res.apiv3(slackAppTokensMOCK, 200);
|
|
|
}
|
|
|
catch (error) {
|
|
|
const msg = 'Error occurred during creating slack integration settings procedure';
|
|
|
@@ -570,26 +563,49 @@ module.exports = (crowi) => {
|
|
|
const { id } = req.params;
|
|
|
|
|
|
try {
|
|
|
+ // NOT MOCK DATA BUT REFER THIS GW-7006
|
|
|
const slackAppIntegration = await SlackAppIntegration.findByIdAndUpdate(
|
|
|
id,
|
|
|
{ supportedCommandsForBroadcastUse, supportedCommandsForSingleUse },
|
|
|
{ new: true },
|
|
|
);
|
|
|
|
|
|
- const proxyUri = crowi.configManager.getConfig('crowi', 'slackbot:proxyUri');
|
|
|
- if (proxyUri != null) {
|
|
|
- await requestToProxyServer(
|
|
|
- slackAppIntegration.tokenGtoP,
|
|
|
- 'put',
|
|
|
- '/g2s/supported-commands',
|
|
|
- {
|
|
|
- supportedCommandsForBroadcastUse: slackAppIntegration.supportedCommandsForBroadcastUse,
|
|
|
- supportedCommandsForSingleUse: slackAppIntegration.supportedCommandsForSingleUse,
|
|
|
- },
|
|
|
- );
|
|
|
- }
|
|
|
+ // MOCK DATA MODIFY THIS GW-6972 ---------------
|
|
|
+ /**
|
|
|
+ * this code represents the update operation using request from client (slackapp integration settings page)
|
|
|
+ * , then send request to proxy to update cache
|
|
|
+ * permittedChannelsForEachCommandFromClient represents the data sent from client
|
|
|
+ */
|
|
|
+ const SlackAppIntegrationMock = mongoose.model('SlackAppIntegrationMock');
|
|
|
+ // MOCK DATA FROM CLIENT assume that these data were sent from client
|
|
|
+ const permissionsForBroadcastUseCommandsFromClient = {
|
|
|
+ search: false,
|
|
|
+ };
|
|
|
+ const permissionsForSingleUseCommandsFromClient = {
|
|
|
+ create: ['random'],
|
|
|
+ };
|
|
|
+ const slackAppIntegrationMock = await SlackAppIntegrationMock.findOneAndUpdate(
|
|
|
+ // MOCK DATA USE id IN req.params LIKE ABOVE
|
|
|
+ { tokenPtoG: slackAppIntegration.tokenPtoG },
|
|
|
+ {
|
|
|
+ permissionsForBroadcastUseCommands: permissionsForBroadcastUseCommandsFromClient,
|
|
|
+ permissionsForSingleUseCommands: permissionsForSingleUseCommandsFromClient,
|
|
|
+ },
|
|
|
+ { new: true },
|
|
|
+ );
|
|
|
+
|
|
|
+ await requestToProxyServer(
|
|
|
+ slackAppIntegrationMock.tokenGtoP,
|
|
|
+ 'put',
|
|
|
+ '/g2s/supported-commands',
|
|
|
+ {
|
|
|
+ permissionsForBroadcastUseCommands: slackAppIntegrationMock.permissionsForBroadcastUseCommands,
|
|
|
+ permissionsForSingleUseCommands: slackAppIntegrationMock.permissionsForSingleUseCommands,
|
|
|
+ },
|
|
|
+ );
|
|
|
+ // MOCK DATA MODIFY THIS GW-6972 ---------------
|
|
|
|
|
|
- return res.apiv3({ slackAppIntegration });
|
|
|
+ return res.apiv3({ slackAppIntegrationMock });
|
|
|
}
|
|
|
catch (error) {
|
|
|
const msg = `Error occured in updating settings. Cause: ${error.message}`;
|
|
|
@@ -627,20 +643,23 @@ module.exports = (crowi) => {
|
|
|
const { id } = req.params;
|
|
|
let slackBotToken;
|
|
|
try {
|
|
|
- const slackAppIntegration = await SlackAppIntegrationMock.findOne({ _id: id });
|
|
|
- // const slackAppIntegration = await SlackAppIntegration.findOne({ _id: id });
|
|
|
- if (slackAppIntegration == null) {
|
|
|
+ // MOCK DATA DELETE THIS GW-6972 ---------------
|
|
|
+ const SlackAppIntegrationMock = mongoose.model('SlackAppIntegrationMock');
|
|
|
+ const slackAppIntegrationMock = await SlackAppIntegrationMock.findOne({ _id: id });
|
|
|
+ // MOCK DATA DELETE THIS GW-6972 ---------------
|
|
|
+ if (slackAppIntegrationMock == null) {
|
|
|
const msg = 'Could not find SlackAppIntegration by id';
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'find-slackAppIntegration-failed'), 400);
|
|
|
}
|
|
|
|
|
|
+ // USE MOCK DATA HERE FOR cache creation at /relation-test GW-7021
|
|
|
const result = await requestToProxyServer(
|
|
|
- slackAppIntegration.tokenGtoP,
|
|
|
+ slackAppIntegrationMock.tokenGtoP,
|
|
|
'post',
|
|
|
'/g2s/relation-test',
|
|
|
{
|
|
|
- permissionsForBroadcastUseCommands: slackAppIntegration.permissionsForBroadcastUseCommands,
|
|
|
- permissionsForSingleUseCommands: slackAppIntegration.permissionsForSingleUseCommands,
|
|
|
+ permissionsForBroadcastUseCommands: slackAppIntegrationMock.permissionsForBroadcastUseCommands,
|
|
|
+ permissionsForSingleUseCommands: slackAppIntegrationMock.permissionsForSingleUseCommands,
|
|
|
},
|
|
|
);
|
|
|
|