this repo has no description

feat: fix the permissions check

dunkirk.sh 829e68ca 81bf2537

verified
Changed files
+36 -8
src
+2 -2
src/commands.ts
···
-
import type { AnyMessageBlock, Block, BlockElement } from "slack-edge";
+
import type { AnyMessageBlock } from "slack-edge";
import { channelMappings, userMappings } from "./db";
-
import { slackApp, ircClient } from "./index";
+
import { ircClient, slackApp } from "./index";
import { canManageChannel } from "./permissions";
export function registerCommands() {
+1 -1
src/index.ts
···
hash = (hash << 5) - hash + nick.charCodeAt(i);
hash = hash & hash; // Convert to 32bit integer
}
-
return DEFAULT_AVATARS[Math.abs(hash) % DEFAULT_AVATARS.length];
+
return DEFAULT_AVATARS[Math.abs(hash) % DEFAULT_AVATARS.length] as string;
}
const missingEnvVars = [];
+33 -5
src/permissions.ts
···
+
interface SlackChannel {
+
id: string;
+
created: number;
+
creator: string;
+
name: string;
+
is_channel: boolean;
+
is_private: boolean;
+
is_archived: boolean;
+
[key: string]: unknown;
+
}
+
+
interface ConversationsInfoResponse {
+
ok: boolean;
+
channel?: SlackChannel;
+
error?: string;
+
}
+
+
interface RoleAssignmentsResponse {
+
ok: boolean;
+
role_assignments?: Array<{
+
users: string[];
+
}>;
+
error?: string;
+
}
+
/**
* Check if a user has permission to manage a Slack channel
* Returns true if the user is:
···
try {
// Check if user is channel creator
-
const channelInfo = await fetch(
+
const formdata = new FormData();
+
formdata.append("channel", channelId);
+
+
const channelInfo: ConversationsInfoResponse = (await fetch(
"https://slack.com/api/conversations.info",
{
method: "POST",
headers: {
-
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.SLACK_BOT_TOKEN}`,
},
-
body: JSON.stringify({ channel: channelId }),
+
body: formdata,
},
-
).then((res) => res.json());
+
).then((res) => res.json())) as ConversationsInfoResponse;
if (channelInfo.ok && channelInfo.channel?.creator === userId) {
return true;
···
},
);
-
const json = await response.json();
+
const json: RoleAssignmentsResponse =
+
(await response.json()) as RoleAssignmentsResponse;
if (json.ok) {
const managers = json.role_assignments?.[0]?.users || [];