Skip to content

Commit baa80c9

Browse files
authored
New channel permissions helper (#293)
### Notes This commit adds a new `channel-management` helper to Valkyrie which will always ensure permissions on new channels within the `defense` category are assigned to the same permission set as the base channel category permissions. It then sends a message to the newly created channel, listing the permissions and access levels they have for quick verification on channel permissions. If the channel is created with different permissions than base category, it will be overwritten by the permissions on base category. However, permissions can also be altered after creation if needed manually.
2 parents 3d6b4c2 + 357d2dd commit baa80c9

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

discord-scripts/role-management.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Client, TextChannel } from "discord.js"
2+
import { Robot } from "hubot"
3+
4+
export default async function manageChannelPermissions(
5+
discordClient: Client,
6+
robot: Robot,
7+
) {
8+
const { application } = discordClient
9+
if (process.env.DEFENSE_CATEGORY_ID) {
10+
if (application) {
11+
discordClient.on("channelCreate", async (channel) => {
12+
if (
13+
channel.parent &&
14+
channel.parentId === process.env.DEFENSE_CATEGORY_ID
15+
) {
16+
const permissions = channel.parent.permissionOverwrites.cache
17+
await channel.permissionOverwrites.set(permissions)
18+
robot.logger.info("Channel permissions set to base category")
19+
if (channel instanceof TextChannel) {
20+
await channel.send(
21+
"This channel now has the same base permissions as the Defense category.",
22+
)
23+
}
24+
}
25+
})
26+
}
27+
}
28+
}

infrastructure/kube/thesis-ops/valkyrie-hubot-deployment.yaml

+5-9
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ spec:
2323
secretKeyRef:
2424
name: valkyrie-hubot
2525
key: discord_api_token
26-
- name: HUBOT_MATRIX_USER
27-
value: "@valkyrie:thesis.co"
28-
- name: HUBOT_MATRIX_PASSWORD
29-
valueFrom:
30-
secretKeyRef:
31-
name: valkyrie-hubot
32-
key: matrix_valkyrie_password
33-
- name: HUBOT_MATRIX_HOST_SERVER
34-
value: "https://thesisco.ems.host"
3526
- name: HUBOT_HOST
3627
valueFrom:
3728
secretKeyRef:
@@ -66,6 +57,11 @@ spec:
6657
key: valkyrie_alert_flow
6758
- name: REDIS_URL
6859
value: $(VALKYRIE_REDIS_SERVICE_PORT)
60+
- name: DEFENSE_CATEGORY_ID
61+
valueFrom:
62+
secretKeyRef:
63+
name: valkyrie-hubot
64+
key: defense_category_id
6965
- name: GITHUB_CLIENT_ID
7066
valueFrom:
7167
secretKeyRef:

0 commit comments

Comments
 (0)