Skip to content

Commit b2c32c0

Browse files
committed
Add mapping for LDAP group to github team slugs
1 parent 9b27969 commit b2c32c0

2 files changed

Lines changed: 24 additions & 14 deletions

File tree

arthur/constants.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
"""Constants, primarily used for LDAP enrollment preferences."""
22

3+
from typing import TypedDict
4+
5+
6+
class LDAPGroupMapping(TypedDict):
7+
"""Mapping of an LDAP group to its Discord role ID and GitHub team ID."""
8+
9+
discord_role_id: int
10+
github_team_slug: str
11+
12+
313
# Users are only checked for enrollment if they have this role. This doesn't grant them any
414
# permissions, it is for performance to avoid iterating roles for every other user in the guild.
515
LDAP_BASE_STAFF_ROLE = 267630620367257601
616

7-
# This is a mapping of LDAP groups to Discord roles. It is used to determine which users should be
8-
# eligible for LDAP enrollment.
9-
LDAP_ROLE_MAPPING = {
10-
"devops": 409416496733880320,
11-
"administrators": 267628507062992896,
12-
"moderators": 267629731250176001,
13-
"coredevs": 587606783669829632,
14-
"events": 787816728474288181,
15-
"directors": 267627879762755584,
17+
# This is a mapping of LDAP groups to Discord role IDs and GitHub team IDs. It is used to determine
18+
# which users should be eligible for LDAP enrollment.
19+
LDAP_ROLE_MAPPING: dict[str, LDAPGroupMapping] = {
20+
"devops": {"discord_role_id": 409416496733880320, "github_team_slug": "devops"},
21+
"administrators": {"discord_role_id": 267628507062992896, "github_team_slug": "admins"},
22+
"moderators": {"discord_role_id": 267629731250176001, "github_team_slug": "moderators"},
23+
"coredevs": {"discord_role_id": 587606783669829632, "github_team_slug": "core-developers"},
24+
"events": {"discord_role_id": 787816728474288181, "github_team_slug": "events"},
25+
"directors": {"discord_role_id": 267627879762755584, "github_team_slug": "directors"},
1626
}

arthur/exts/directory/ldap.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ async def cog_load(self) -> None: # noqa: C901, PLR0912
330330
await channel.send(bootstrap_message, view=BootstrapView(self))
331331

332332
# Validate all enrolled roles can see the channel
333-
for role_id in LDAP_ROLE_MAPPING.values():
334-
role = channel.guild.get_role(role_id)
333+
for mapping in LDAP_ROLE_MAPPING.values():
334+
role = channel.guild.get_role(mapping["discord_role_id"])
335335

336336
if not role:
337337
continue
@@ -361,8 +361,8 @@ def _user_groups(user: discord.Member) -> list[str]:
361361
"""Return the groups a user is enrolled in."""
362362
return [
363363
role
364-
for role, discord_role_id in LDAP_ROLE_MAPPING.items()
365-
if discord_role_id in [r.id for r in user.roles]
364+
for role, mapping in LDAP_ROLE_MAPPING.items()
365+
if mapping["discord_role_id"] in [r.id for r in user.roles]
366366
]
367367

368368
async def get_user_diff(
@@ -373,7 +373,7 @@ async def get_user_diff(
373373
users = await ldap.find_users()
374374
ldap_discord_id_map = {user.employee_number: user for user in users}
375375

376-
enrolled_roles = set(LDAP_ROLE_MAPPING.values())
376+
enrolled_roles = {mapping["discord_role_id"] for mapping in LDAP_ROLE_MAPPING.values()}
377377

378378
base_role = guild.get_role(LDAP_BASE_STAFF_ROLE)
379379

0 commit comments

Comments
 (0)