Skip to content

Commit

Permalink
New channel permissions helper (#293)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
Shadowfiend authored Mar 12, 2024
2 parents 3d6b4c2 + 357d2dd commit baa80c9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
28 changes: 28 additions & 0 deletions discord-scripts/role-management.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Client, TextChannel } from "discord.js"
import { Robot } from "hubot"

export default async function manageChannelPermissions(
discordClient: Client,
robot: Robot,
) {
const { application } = discordClient
if (process.env.DEFENSE_CATEGORY_ID) {
if (application) {
discordClient.on("channelCreate", async (channel) => {
if (
channel.parent &&
channel.parentId === process.env.DEFENSE_CATEGORY_ID
) {
const permissions = channel.parent.permissionOverwrites.cache
await channel.permissionOverwrites.set(permissions)
robot.logger.info("Channel permissions set to base category")
if (channel instanceof TextChannel) {
await channel.send(
"This channel now has the same base permissions as the Defense category.",
)
}
}
})
}
}
}
14 changes: 5 additions & 9 deletions infrastructure/kube/thesis-ops/valkyrie-hubot-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ spec:
secretKeyRef:
name: valkyrie-hubot
key: discord_api_token
- name: HUBOT_MATRIX_USER
value: "@valkyrie:thesis.co"
- name: HUBOT_MATRIX_PASSWORD
valueFrom:
secretKeyRef:
name: valkyrie-hubot
key: matrix_valkyrie_password
- name: HUBOT_MATRIX_HOST_SERVER
value: "https://thesisco.ems.host"
- name: HUBOT_HOST
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -66,6 +57,11 @@ spec:
key: valkyrie_alert_flow
- name: REDIS_URL
value: $(VALKYRIE_REDIS_SERVICE_PORT)
- name: DEFENSE_CATEGORY_ID
valueFrom:
secretKeyRef:
name: valkyrie-hubot
key: defense_category_id
- name: GITHUB_CLIENT_ID
valueFrom:
secretKeyRef:
Expand Down

0 comments on commit baa80c9

Please sign in to comment.