|
|
@@ -2,13 +2,11 @@ import {
|
|
|
IMiddleware, Inject, Middleware, Next, Req, Res,
|
|
|
} from '@tsed/common';
|
|
|
import {
|
|
|
- generateWebClient, markdownSectionBlock, GrowiCommand,
|
|
|
+ generateWebClient, markdownSectionBlock,
|
|
|
} from '@growi/slack';
|
|
|
-import { RelationMock } from '~/entities/relation-mock';
|
|
|
|
|
|
import { RelationsService } from '~/services/RelationsService';
|
|
|
import { InstallerService } from '~/services/InstallerService';
|
|
|
-// import { SelectGrowiService } from '~/services/SelectGrowiService';
|
|
|
|
|
|
import { InstallationRepository } from '~/repositories/installation';
|
|
|
import { RelationMockRepository } from '~/repositories/relation-mock';
|
|
|
@@ -47,19 +45,13 @@ export class checkCommandPermissionMiddleware implements IMiddleware {
|
|
|
let command:string;
|
|
|
if (body.payload == null) { // when request is to /commands
|
|
|
command = body.text.split(' ')[0];
|
|
|
- console.log(command);
|
|
|
}
|
|
|
else if (payload.actions != null) { // when request is to /interactions && block_actions
|
|
|
- console.log(58);
|
|
|
-
|
|
|
const actionId = payload.actions[0].action_id;
|
|
|
command = actionId.split(':')[0];
|
|
|
}
|
|
|
else { // when request is to /interactions && view_submission
|
|
|
payload = JSON.parse(req.body.payload);
|
|
|
-
|
|
|
- console.log(49, payload);
|
|
|
-
|
|
|
const privateMeta = JSON.parse(payload.view.private_metadata);
|
|
|
|
|
|
// first payload
|
|
|
@@ -68,18 +60,13 @@ export class checkCommandPermissionMiddleware implements IMiddleware {
|
|
|
}
|
|
|
// second payload
|
|
|
else {
|
|
|
- console.log(56, payload.view.callback_id);
|
|
|
-
|
|
|
command = payload.view.callback_id.split(':')[0];
|
|
|
}
|
|
|
- console.log(37, command);
|
|
|
}
|
|
|
|
|
|
const passCommandArray = ['status', 'register', 'unregister', 'help'];
|
|
|
- console.log(command);
|
|
|
|
|
|
if (passCommandArray.includes(command)) {
|
|
|
- console.log(22);
|
|
|
return next();
|
|
|
}
|
|
|
|
|
|
@@ -126,17 +113,11 @@ export class checkCommandPermissionMiddleware implements IMiddleware {
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
const permittedCommandsForChannel = Object.keys(channelsObject!); // eg. [ 'create', 'search', 'togetter', ... ]
|
|
|
- console.log(112, permittedCommandsForChannel);
|
|
|
-
|
|
|
|
|
|
const targetCommand = permittedCommandsForChannel.find(e => e === command);
|
|
|
- console.log(command);
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
- console.log(118, targetCommand);
|
|
|
-
|
|
|
const permittedChannels = channelsObject?.[targetCommand!];
|
|
|
- console.log(permittedChannels);
|
|
|
|
|
|
let fromChannel:string;
|
|
|
if (body.channel_name != null) { // commands
|
|
|
@@ -146,20 +127,15 @@ export class checkCommandPermissionMiddleware implements IMiddleware {
|
|
|
fromChannel = payload.channel.name;
|
|
|
}
|
|
|
else {
|
|
|
- console.log(payload, 154);
|
|
|
-
|
|
|
const privateMeta = JSON.parse(payload.view.private_metadata);
|
|
|
fromChannel = privateMeta.channelName;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
const isPermittedChannel = permittedChannels?.includes(fromChannel);
|
|
|
- console.log(151, isPermittedChannel);
|
|
|
if (isPermittedChannel) {
|
|
|
return next();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
if (payload != null) {
|
|
|
const isPermittedChannel = permittedChannels?.includes(fromChannel);
|
|
|
if (isPermittedChannel) {
|
|
|
@@ -170,9 +146,6 @@ export class checkCommandPermissionMiddleware implements IMiddleware {
|
|
|
// send postEphemral message for not permitted
|
|
|
const botToken = relations[0].installation?.data.bot?.token;
|
|
|
|
|
|
-
|
|
|
- console.log(179);
|
|
|
-
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
const client = generateWebClient(botToken!);
|
|
|
await client.chat.postEphemeral({
|