|
@@ -36,7 +36,7 @@ import { JoinToConversationMiddleware } from '~/middlewares/slack-to-growi/join-
|
|
|
|
|
|
|
|
const logger = loggerFactory('slackbot-proxy:controllers:slack');
|
|
const logger = loggerFactory('slackbot-proxy:controllers:slack');
|
|
|
|
|
|
|
|
-const postNotAllowedMessage = async(client:WebClient, body:any, disallowedGrowiUrls:Set<string>, commandName:string):Promise<void> => {
|
|
|
|
|
|
|
+const postNotAllowedMessage = async(client:WebClient, channelId:string, userId:string, disallowedGrowiUrls:Set<string>, commandName:string):Promise<void> => {
|
|
|
|
|
|
|
|
const linkUrlList = Array.from(disallowedGrowiUrls).map((growiUrl) => {
|
|
const linkUrlList = Array.from(disallowedGrowiUrls).map((growiUrl) => {
|
|
|
return '\n'
|
|
return '\n'
|
|
@@ -45,10 +45,11 @@ const postNotAllowedMessage = async(client:WebClient, body:any, disallowedGrowiU
|
|
|
|
|
|
|
|
const growiDocsLink = 'https://docs.growi.org/en/admin-guide/upgrading/43x.html';
|
|
const growiDocsLink = 'https://docs.growi.org/en/admin-guide/upgrading/43x.html';
|
|
|
|
|
|
|
|
|
|
+
|
|
|
await client.chat.postEphemeral({
|
|
await client.chat.postEphemeral({
|
|
|
text: 'Error occured.',
|
|
text: 'Error occured.',
|
|
|
- channel: body.channel_id,
|
|
|
|
|
- user: body.user_id,
|
|
|
|
|
|
|
+ channel: channelId,
|
|
|
|
|
+ user: userId,
|
|
|
blocks: [
|
|
blocks: [
|
|
|
markdownSectionBlock('*None of GROWI permitted the command.*'),
|
|
markdownSectionBlock('*None of GROWI permitted the command.*'),
|
|
|
markdownSectionBlock(`*'${commandName}'* command was not allowed.`),
|
|
markdownSectionBlock(`*'${commandName}'* command was not allowed.`),
|
|
@@ -239,7 +240,7 @@ export class SlackCtrl {
|
|
|
if (relations.length === disallowedGrowiUrls.size) {
|
|
if (relations.length === disallowedGrowiUrls.size) {
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
const client = generateWebClient(authorizeResult.botToken!);
|
|
const client = generateWebClient(authorizeResult.botToken!);
|
|
|
- return postNotAllowedMessage(client, body, disallowedGrowiUrls, growiCommand.growiCommandType);
|
|
|
|
|
|
|
+ return postNotAllowedMessage(client, body.channel_id, body.user_id, disallowedGrowiUrls, growiCommand.growiCommandType);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// select GROWI
|
|
// select GROWI
|
|
@@ -330,53 +331,29 @@ export class SlackCtrl {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- const allowedRelations:Relation[] = [];
|
|
|
|
|
- const disallowedGrowiUrls: Set<string> = new Set();
|
|
|
|
|
- let notAllowedCommandName!:string;
|
|
|
|
|
const actionId:string = payload?.actions?.[0].action_id;
|
|
const actionId:string = payload?.actions?.[0].action_id;
|
|
|
|
|
+ const permission = await this.relationsService.checkPermissionForInteractions(relations, actionId, callbackId, channelName);
|
|
|
|
|
+ const {
|
|
|
|
|
+ allowedRelations, disallowedGrowiUrls, commandName, rejectedResults,
|
|
|
|
|
+ } = permission;
|
|
|
|
|
|
|
|
- await Promise.all(relations.map(async(relation) => {
|
|
|
|
|
- const permission = await this.relationsService.checkPermissionForInteractions(relation, channelName, callbackId, actionId);
|
|
|
|
|
- const { isPermittedForInteractions, commandName } = permission;
|
|
|
|
|
-
|
|
|
|
|
- if (!isPermittedForInteractions) {
|
|
|
|
|
- disallowedGrowiUrls.add(relation.growiUri);
|
|
|
|
|
- notAllowedCommandName = commandName;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- allowedRelations.push(relation);
|
|
|
|
|
- }));
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
|
|
+ await postEphemeralErrors(rejectedResults, payload.channel.id, payload.user.id, authorizeResult.botToken!);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ logger.error(err);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (relations.length === disallowedGrowiUrls.size) {
|
|
if (relations.length === disallowedGrowiUrls.size) {
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
const client = generateWebClient(authorizeResult.botToken!);
|
|
const client = generateWebClient(authorizeResult.botToken!);
|
|
|
- const linkUrlList = Array.from(disallowedGrowiUrls).map((growiUrl) => {
|
|
|
|
|
- return '\n'
|
|
|
|
|
- + `• ${new URL('/admin/slack-integration', growiUrl).toString()}`;
|
|
|
|
|
- });
|
|
|
|
|
- const growiDocsLink = 'https://docs.growi.org/en/admin-guide/upgrading/43x.html';
|
|
|
|
|
- return client.chat.postEphemeral({
|
|
|
|
|
- text: 'Error occured.',
|
|
|
|
|
- channel: body.channel_id,
|
|
|
|
|
- user: body.user_id,
|
|
|
|
|
- blocks: [
|
|
|
|
|
- markdownSectionBlock('*None of GROWI permitted the command.*'),
|
|
|
|
|
- markdownSectionBlock(`*'${notAllowedCommandName}'* command was not allowed.`),
|
|
|
|
|
- markdownSectionBlock(
|
|
|
|
|
- `To use this command, modify settings from following pages: ${linkUrlList}`,
|
|
|
|
|
- ),
|
|
|
|
|
- markdownSectionBlock(
|
|
|
|
|
- `Or, if your GROWI version is 4.3.0 or below, upgrade GROWI to use commands and permission settings: ${growiDocsLink}`,
|
|
|
|
|
- ),
|
|
|
|
|
- ],
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ return postNotAllowedMessage(client, payload.channel.id, payload.user.id, disallowedGrowiUrls, commandName);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
* forward to GROWI server
|
|
* forward to GROWI server
|
|
|
*/
|
|
*/
|
|
|
-
|
|
|
|
|
allowedRelations.map(async(relation) => {
|
|
allowedRelations.map(async(relation) => {
|
|
|
try {
|
|
try {
|
|
|
// generate API URL
|
|
// generate API URL
|
|
@@ -392,8 +369,8 @@ export class SlackCtrl {
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
logger.error(err);
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Post('/events')
|
|
@Post('/events')
|