slack-integration.ts 790 B

12345678910111213141516171819202122232425
  1. import { getSupportedGrowiActionsRegExp, IChannelOptionalId, permissionParser } from '@growi/slack';
  2. type CommandPermission = { [key:string]: string[] | boolean }
  3. export const checkPermission = (
  4. commandPermission: CommandPermission, commandOrActionIdOrCallbackId: string, fromChannel: IChannelOptionalId,
  5. ): boolean => {
  6. let isPermitted = false;
  7. // help
  8. if (commandOrActionIdOrCallbackId === 'help') {
  9. return true;
  10. }
  11. Object.entries(commandPermission).forEach((entry) => {
  12. const [command, value] = entry;
  13. const permission = value;
  14. const commandRegExp = getSupportedGrowiActionsRegExp(command);
  15. if (!commandRegExp.test(commandOrActionIdOrCallbackId)) return;
  16. isPermitted = permissionParser(permission, fromChannel);
  17. });
  18. return isPermitted;
  19. };