Skip to content

Commit

Permalink
Strengthen typing in auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
liffiton committed Jul 25, 2024
1 parent 65c0047 commit a8f3687
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/gened/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections.abc import Callable
from functools import wraps
from sqlite3 import Row
from typing import ParamSpec, TypedDict, TypeVar
from typing import Literal, ParamSpec, TypedDict, TypeVar

from flask import (
Blueprint,
Expand All @@ -28,21 +28,22 @@
# Constants
AUTH_SESSION_KEY = "__gened_auth"

ProviderType = Literal['local', 'lti', 'demo', 'google', 'github', 'microsoft']
RoleType = Literal['instructor', 'student']

class ClassDict(TypedDict):
class_id: int
class_name: str
role: str

role: RoleType

class AuthDict(TypedDict, total=False):
user_id: int | None
auth_provider: str
auth_provider: ProviderType
display_name: str
is_admin: bool
is_tester: bool
role_id: int | None # current role
role: str | None # current role name (e.g., 'instructor')
role: RoleType | None # current role name (e.g., 'instructor')
class_id: int | None # current class ID
class_name: str | None # current class name
class_experiments: list[str] # any experiments the current class is registered in
Expand Down

0 comments on commit a8f3687

Please sign in to comment.