|
@@ -183,42 +183,33 @@ export class SlackCtrl {
|
|
|
const baseDate = new Date();
|
|
const baseDate = new Date();
|
|
|
|
|
|
|
|
const allowedRelationsForSingleUse:Relation[] = [];
|
|
const allowedRelationsForSingleUse:Relation[] = [];
|
|
|
|
|
+ const allowedRelationsForBroadcastUse:Relation[] = [];
|
|
|
const disallowedGrowiUrls: Set<string> = new Set();
|
|
const disallowedGrowiUrls: Set<string> = new Set();
|
|
|
|
|
|
|
|
- // check permission for single use
|
|
|
|
|
|
|
+ // check permission
|
|
|
await Promise.all(relations.map(async(relation) => {
|
|
await Promise.all(relations.map(async(relation) => {
|
|
|
- const isSupported = await this.relationsService.isSupportedGrowiCommandForSingleUse(relation, growiCommand.growiCommandType, baseDate);
|
|
|
|
|
- if (isSupported) {
|
|
|
|
|
- allowedRelationsForSingleUse.push(relation);
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- disallowedGrowiUrls.add(relation.growiUri);
|
|
|
|
|
|
|
+ const isSupportedForSingleUse = await this.relationsService.isSupportedGrowiCommandForSingleUse(
|
|
|
|
|
+ relation, growiCommand.growiCommandType, baseDate,
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ let isSupportedForBroadcastUse = false;
|
|
|
|
|
+ if (!isSupportedForSingleUse) {
|
|
|
|
|
+ isSupportedForBroadcastUse = await this.relationsService.isSupportedGrowiCommandForBroadcastUse(
|
|
|
|
|
+ relation, growiCommand.growiCommandType, baseDate,
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
- }));
|
|
|
|
|
|
|
|
|
|
- // select GROWI
|
|
|
|
|
- if (allowedRelationsForSingleUse.length > 0) {
|
|
|
|
|
- body.growiUrisForSingleUse = allowedRelationsForSingleUse.map(v => v.growiUri);
|
|
|
|
|
- return this.selectGrowiService.process(growiCommand, authorizeResult, body);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // check permission for broadcast use
|
|
|
|
|
- const relationsForBroadcastUse:Relation[] = [];
|
|
|
|
|
- await Promise.all(relations.map(async(relation) => {
|
|
|
|
|
- const isSupported = await this.relationsService.isSupportedGrowiCommandForBroadcastUse(relation, growiCommand.growiCommandType, baseDate);
|
|
|
|
|
- if (isSupported) {
|
|
|
|
|
- relationsForBroadcastUse.push(relation);
|
|
|
|
|
|
|
+ if (isSupportedForSingleUse) {
|
|
|
|
|
+ allowedRelationsForSingleUse.push(relation);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (isSupportedForBroadcastUse) {
|
|
|
|
|
+ allowedRelationsForBroadcastUse.push(relation);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
disallowedGrowiUrls.add(relation.growiUri);
|
|
disallowedGrowiUrls.add(relation.growiUri);
|
|
|
}
|
|
}
|
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
- // forward to GROWI server
|
|
|
|
|
- if (relationsForBroadcastUse.length > 0) {
|
|
|
|
|
- return this.sendCommand(growiCommand, relationsForBroadcastUse, body);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// when all of GROWI disallowed
|
|
// when all of GROWI disallowed
|
|
|
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
|
|
@@ -229,6 +220,8 @@ export class SlackCtrl {
|
|
|
+ `• ${new URL('/admin/slack-integration', growiUrl).toString()}`;
|
|
+ `• ${new URL('/admin/slack-integration', growiUrl).toString()}`;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ const growiDocsLink = 'https://docs.growi.org/en/admin-guide/upgrading/43x.html';
|
|
|
|
|
+
|
|
|
return client.chat.postEphemeral({
|
|
return client.chat.postEphemeral({
|
|
|
text: 'Error occured.',
|
|
text: 'Error occured.',
|
|
|
channel: body.channel_id,
|
|
channel: body.channel_id,
|
|
@@ -239,9 +232,23 @@ export class SlackCtrl {
|
|
|
markdownSectionBlock(
|
|
markdownSectionBlock(
|
|
|
`To use this command, modify settings from following pages: ${linkUrlList}`,
|
|
`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}`,
|
|
|
|
|
+ ),
|
|
|
],
|
|
],
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // select GROWI
|
|
|
|
|
+ if (allowedRelationsForSingleUse.length > 0) {
|
|
|
|
|
+ body.growiUrisForSingleUse = allowedRelationsForSingleUse.map(v => v.growiUri);
|
|
|
|
|
+ return this.selectGrowiService.process(growiCommand, authorizeResult, body);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // forward to GROWI server
|
|
|
|
|
+ if (allowedRelationsForBroadcastUse.length > 0) {
|
|
|
|
|
+ return this.sendCommand(growiCommand, allowedRelationsForBroadcastUse, body);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Post('/interactions')
|
|
@Post('/interactions')
|