this repo has no description

feat: fix the permissions check

dunkirk.sh 829e68ca 81bf2537

verified
+36 -8
+2 -2
src/commands.ts
··· 1 - import type { AnyMessageBlock, Block, BlockElement } from "slack-edge"; 1 + import type { AnyMessageBlock } from "slack-edge"; 2 2 import { channelMappings, userMappings } from "./db"; 3 - import { slackApp, ircClient } from "./index"; 3 + import { ircClient, slackApp } from "./index"; 4 4 import { canManageChannel } from "./permissions"; 5 5 6 6 export function registerCommands() {
+1 -1
src/index.ts
··· 22 22 hash = (hash << 5) - hash + nick.charCodeAt(i); 23 23 hash = hash & hash; // Convert to 32bit integer 24 24 } 25 - return DEFAULT_AVATARS[Math.abs(hash) % DEFAULT_AVATARS.length]; 25 + return DEFAULT_AVATARS[Math.abs(hash) % DEFAULT_AVATARS.length] as string; 26 26 } 27 27 28 28 const missingEnvVars = [];
+33 -5
src/permissions.ts
··· 1 + interface SlackChannel { 2 + id: string; 3 + created: number; 4 + creator: string; 5 + name: string; 6 + is_channel: boolean; 7 + is_private: boolean; 8 + is_archived: boolean; 9 + [key: string]: unknown; 10 + } 11 + 12 + interface ConversationsInfoResponse { 13 + ok: boolean; 14 + channel?: SlackChannel; 15 + error?: string; 16 + } 17 + 18 + interface RoleAssignmentsResponse { 19 + ok: boolean; 20 + role_assignments?: Array<{ 21 + users: string[]; 22 + }>; 23 + error?: string; 24 + } 25 + 1 26 /** 2 27 * Check if a user has permission to manage a Slack channel 3 28 * Returns true if the user is: ··· 17 42 18 43 try { 19 44 // Check if user is channel creator 20 - const channelInfo = await fetch( 45 + const formdata = new FormData(); 46 + formdata.append("channel", channelId); 47 + 48 + const channelInfo: ConversationsInfoResponse = (await fetch( 21 49 "https://slack.com/api/conversations.info", 22 50 { 23 51 method: "POST", 24 52 headers: { 25 - "Content-Type": "application/json", 26 53 Authorization: `Bearer ${process.env.SLACK_BOT_TOKEN}`, 27 54 }, 28 - body: JSON.stringify({ channel: channelId }), 55 + body: formdata, 29 56 }, 30 - ).then((res) => res.json()); 57 + ).then((res) => res.json())) as ConversationsInfoResponse; 31 58 32 59 if (channelInfo.ok && channelInfo.channel?.creator === userId) { 33 60 return true; ··· 54 81 }, 55 82 ); 56 83 57 - const json = await response.json(); 84 + const json: RoleAssignmentsResponse = 85 + (await response.json()) as RoleAssignmentsResponse; 58 86 59 87 if (json.ok) { 60 88 const managers = json.role_assignments?.[0]?.users || [];