STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
admins.py
Go to the documentation of this file.
1
"""Who is an admin: a fixed list, checked against the caller's identity.
2
3
Admins may choose the team's main design and are the only ones who may change
4
it (see :mod:`stardesign.documents`). The list is in code on purpose: changing
5
who can rewrite the main design should be a reviewed commit, not a button.
6
7
Identity is the ``X-Auth-Email`` Caddy sets after verifying the session, and
8
Caddy strips any copy the client sent (see deploy/caddy/Caddyfile), so the
9
comparison below is against an email the caller cannot choose.
10
11
``STAR_ADMINS`` (comma-separated emails) adds to the list without a commit. It
12
exists for dev, where there is no Caddy and every request is the ``local`` user
13
(``STAR_ADMINS=local``).
14
"""
15
16
from
__future__
import
annotations
17
18
import
os
19
20
from
fastapi
import
Request
21
22
from
stardesign.userdata
import
UserData, slug_user
23
24
#: Compared as path slugs, the same normalisation ``current_user`` applies.
25
ADMIN_EMAILS = (
26
"aahilsyed72@berkeley.edu"
,
27
"carlosbautista@berkeley.edu"
,
28
"aidanrickert@berkeley.edu"
,
29
"manank_doshi@berkeley.edu"
,
30
)
31
32
33
def
admin_slugs
() -> set[str]:
34
extra = os.environ.get(
"STAR_ADMINS"
,
""
)
35
return
{slug_user(e)
for
e
in
(*ADMIN_EMAILS, *extra.split(
","
))
if
e.strip()}
36
37
38
def
is_admin
(request: Request, ud: UserData) -> bool:
39
"""Whether the caller is a STAR admin."""
40
return
ud.current_user(request)
in
admin_slugs
()
stardesign.admins.admin_slugs
set[str] admin_slugs()
Definition
admins.py:33
stardesign.admins.is_admin
bool is_admin(Request request, UserData ud)
Definition
admins.py:38
stardesign.userdata
Definition
userdata.py:1
lib
stardesign
stardesign
admins.py
Generated by
1.15.0