tangled
alpha
login
or
join now
dunkirk.sh
/
irc-slack-bridge
1
fork
atom
this repo has no description
1
fork
atom
overview
issues
pulls
pipelines
feat: fix the permissions check
dunkirk.sh
3 months ago
829e68ca
81bf2537
verified
This commit was signed with the committer's
known signature
.
dunkirk.sh
SSH Key Fingerprint:
SHA256:DqcG0RXYExE26KiWo3VxJnsxswN1QNfTBvB+bdSpk80=
+36
-8
3 changed files
expand all
collapse all
unified
split
src
commands.ts
index.ts
permissions.ts
+2
-2
src/commands.ts
···
1
1
-
import type { AnyMessageBlock, Block, BlockElement } from "slack-edge";
1
1
+
import type { AnyMessageBlock } from "slack-edge";
2
2
import { channelMappings, userMappings } from "./db";
3
3
-
import { slackApp, ircClient } from "./index";
3
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
25
-
return DEFAULT_AVATARS[Math.abs(hash) % DEFAULT_AVATARS.length];
25
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
1
+
interface SlackChannel {
2
2
+
id: string;
3
3
+
created: number;
4
4
+
creator: string;
5
5
+
name: string;
6
6
+
is_channel: boolean;
7
7
+
is_private: boolean;
8
8
+
is_archived: boolean;
9
9
+
[key: string]: unknown;
10
10
+
}
11
11
+
12
12
+
interface ConversationsInfoResponse {
13
13
+
ok: boolean;
14
14
+
channel?: SlackChannel;
15
15
+
error?: string;
16
16
+
}
17
17
+
18
18
+
interface RoleAssignmentsResponse {
19
19
+
ok: boolean;
20
20
+
role_assignments?: Array<{
21
21
+
users: string[];
22
22
+
}>;
23
23
+
error?: string;
24
24
+
}
25
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
20
-
const channelInfo = await fetch(
45
45
+
const formdata = new FormData();
46
46
+
formdata.append("channel", channelId);
47
47
+
48
48
+
const channelInfo: ConversationsInfoResponse = (await fetch(
21
49
"https://slack.com/api/conversations.info",
22
50
{
23
51
method: "POST",
24
52
headers: {
25
25
-
"Content-Type": "application/json",
26
53
Authorization: `Bearer ${process.env.SLACK_BOT_TOKEN}`,
27
54
},
28
28
-
body: JSON.stringify({ channel: channelId }),
55
55
+
body: formdata,
29
56
},
30
30
-
).then((res) => res.json());
57
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
57
-
const json = await response.json();
84
84
+
const json: RoleAssignmentsResponse =
85
85
+
(await response.json()) as RoleAssignmentsResponse;
58
86
59
87
if (json.ok) {
60
88
const managers = json.role_assignments?.[0]?.users || [];