-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperms.py
More file actions
29 lines (23 loc) · 974 Bytes
/
perms.py
File metadata and controls
29 lines (23 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import asyncpg
from kittycat import PartialStaffPosition, StaffPermissions, Permission
async def get_user_staff_perms(pool: asyncpg.Pool, user_id: int) -> StaffPermissions:
user_poses = await pool.fetchrow("SELECT positions, perm_overrides FROM staff_members WHERE user_id = $1", str(user_id))
if not user_poses:
return StaffPermissions(
perm_overrides={},
user_positions=[]
)
position_data = await pool.fetch("SELECT id::text, index, perms FROM staff_positions WHERE id = ANY($1)", user_poses["positions"])
sp = StaffPermissions(
perm_overrides=Permission.from_str_list(user_poses["perm_overrides"]),
user_positions=[]
)
for pos in position_data:
sp.user_positions.append(
PartialStaffPosition(
id=pos["id"],
index=pos["index"],
perms=Permission.from_str_list(pos["perms"])
)
)
return sp