lms.model.users
1import enum 2import typing 3 4import lms.model.base 5import lms.model.query 6 7class UserQuery(lms.model.query.BaseQuery): 8 """ 9 A class for the different ways one can attempt to reference an LMS user. 10 In general, a user can be queried by: 11 - LMS User ID (`id`) 12 - Email (`email`) 13 - Full Name (`name`) 14 - f"{email} ({id})" 15 - f"{name} ({id})" 16 """ 17 18 _include_email = True 19 20class ResolvedUserQuery(lms.model.query.ResolvedBaseQuery, UserQuery): 21 """ 22 A UserQuery that has been resolved (verified) from a real user instance. 23 """ 24 25 _include_email = True 26 27 def __init__(self, 28 user: 'ServerUser', 29 **kwargs: typing.Any) -> None: 30 super().__init__(id = user.id, name = user.name, email = user.email, **kwargs) 31 32class CourseRole(enum.Enum): 33 """ 34 Different roles a user can have in a course. 35 LMSs represent this information very differently, so this is only a general collection of roles. 36 """ 37 38 OTHER = 'other' 39 STUDENT = 'student' 40 GRADER = 'grader' 41 ADMIN = 'admin' 42 OWNER = 'owner' 43 44 def __str__(self) -> str: 45 return str(self.value) 46 47class ServerUser(lms.model.base.BaseType): 48 """ 49 A user associated with an LMS server. 50 """ 51 52 CORE_FIELDS = ['id', 'name', 'email'] 53 """ The common fields shared across backends for this type. """ 54 55 def __init__(self, 56 id: typing.Union[str, int, None] = None, 57 email: typing.Union[str, None] = None, 58 name: typing.Union[str, None] = None, 59 **kwargs: typing.Any) -> None: 60 super().__init__(**kwargs) 61 62 if (id is None): 63 raise ValueError("User must have an id.") 64 65 self.id: str = str(id) 66 """ The LMS's identifier for this user. """ 67 68 self.name: typing.Union[str, None] = name 69 """ The display name of this user. """ 70 71 self.email: typing.Union[str, None] = email 72 """ The email address of this user. """ 73 74 def to_query(self) -> ResolvedUserQuery: 75 """ Get a query representation of this user. """ 76 77 return ResolvedUserQuery(self) 78 79class CourseUser(ServerUser): 80 """ 81 A user associated with a course, e.g., an instructor or student. 82 """ 83 84 CORE_FIELDS = ServerUser.CORE_FIELDS + ['role'] 85 """ The common fields shared across backends for this type. """ 86 87 def __init__(self, 88 role: typing.Union[CourseRole, None] = None, 89 raw_role: typing.Union[str, None] = None, 90 **kwargs: typing.Any) -> None: 91 super().__init__(**kwargs) 92 93 self.role: typing.Union[CourseRole, None] = role 94 """ The role of this user within this course (e.g., owner, student). """ 95 96 self.raw_role: typing.Union[str, None] = raw_role 97 """ 98 The raw role string from the LMS. 99 This may not translate nicely into one of our known roles. 100 """ 101 102 def is_student(self) -> bool: 103 """ 104 Check if this course user is a student (and therefore be included in graded components like gradebooks). 105 Backends should implement this method. 106 """ 107 108 return (self.role == CourseRole.STUDENT)
8class UserQuery(lms.model.query.BaseQuery): 9 """ 10 A class for the different ways one can attempt to reference an LMS user. 11 In general, a user can be queried by: 12 - LMS User ID (`id`) 13 - Email (`email`) 14 - Full Name (`name`) 15 - f"{email} ({id})" 16 - f"{name} ({id})" 17 """ 18 19 _include_email = True
A class for the different ways one can attempt to reference an LMS user. In general, a user can be queried by:
21class ResolvedUserQuery(lms.model.query.ResolvedBaseQuery, UserQuery): 22 """ 23 A UserQuery that has been resolved (verified) from a real user instance. 24 """ 25 26 _include_email = True 27 28 def __init__(self, 29 user: 'ServerUser', 30 **kwargs: typing.Any) -> None: 31 super().__init__(id = user.id, name = user.name, email = user.email, **kwargs)
A UserQuery that has been resolved (verified) from a real user instance.
ResolvedUserQuery(user: ServerUser, **kwargs: Any)
Inherited Members
class
CourseRole(enum.Enum):
33class CourseRole(enum.Enum): 34 """ 35 Different roles a user can have in a course. 36 LMSs represent this information very differently, so this is only a general collection of roles. 37 """ 38 39 OTHER = 'other' 40 STUDENT = 'student' 41 GRADER = 'grader' 42 ADMIN = 'admin' 43 OWNER = 'owner' 44 45 def __str__(self) -> str: 46 return str(self.value)
Different roles a user can have in a course. LMSs represent this information very differently, so this is only a general collection of roles.
OTHER =
<CourseRole.OTHER: 'other'>
STUDENT =
<CourseRole.STUDENT: 'student'>
GRADER =
<CourseRole.GRADER: 'grader'>
ADMIN =
<CourseRole.ADMIN: 'admin'>
OWNER =
<CourseRole.OWNER: 'owner'>
48class ServerUser(lms.model.base.BaseType): 49 """ 50 A user associated with an LMS server. 51 """ 52 53 CORE_FIELDS = ['id', 'name', 'email'] 54 """ The common fields shared across backends for this type. """ 55 56 def __init__(self, 57 id: typing.Union[str, int, None] = None, 58 email: typing.Union[str, None] = None, 59 name: typing.Union[str, None] = None, 60 **kwargs: typing.Any) -> None: 61 super().__init__(**kwargs) 62 63 if (id is None): 64 raise ValueError("User must have an id.") 65 66 self.id: str = str(id) 67 """ The LMS's identifier for this user. """ 68 69 self.name: typing.Union[str, None] = name 70 """ The display name of this user. """ 71 72 self.email: typing.Union[str, None] = email 73 """ The email address of this user. """ 74 75 def to_query(self) -> ResolvedUserQuery: 76 """ Get a query representation of this user. """ 77 78 return ResolvedUserQuery(self)
A user associated with an LMS server.
ServerUser( id: Union[str, int, NoneType] = None, email: Optional[str] = None, name: Optional[str] = None, **kwargs: Any)
56 def __init__(self, 57 id: typing.Union[str, int, None] = None, 58 email: typing.Union[str, None] = None, 59 name: typing.Union[str, None] = None, 60 **kwargs: typing.Any) -> None: 61 super().__init__(**kwargs) 62 63 if (id is None): 64 raise ValueError("User must have an id.") 65 66 self.id: str = str(id) 67 """ The LMS's identifier for this user. """ 68 69 self.name: typing.Union[str, None] = name 70 """ The display name of this user. """ 71 72 self.email: typing.Union[str, None] = email 73 """ The email address of this user. """
80class CourseUser(ServerUser): 81 """ 82 A user associated with a course, e.g., an instructor or student. 83 """ 84 85 CORE_FIELDS = ServerUser.CORE_FIELDS + ['role'] 86 """ The common fields shared across backends for this type. """ 87 88 def __init__(self, 89 role: typing.Union[CourseRole, None] = None, 90 raw_role: typing.Union[str, None] = None, 91 **kwargs: typing.Any) -> None: 92 super().__init__(**kwargs) 93 94 self.role: typing.Union[CourseRole, None] = role 95 """ The role of this user within this course (e.g., owner, student). """ 96 97 self.raw_role: typing.Union[str, None] = raw_role 98 """ 99 The raw role string from the LMS. 100 This may not translate nicely into one of our known roles. 101 """ 102 103 def is_student(self) -> bool: 104 """ 105 Check if this course user is a student (and therefore be included in graded components like gradebooks). 106 Backends should implement this method. 107 """ 108 109 return (self.role == CourseRole.STUDENT)
A user associated with a course, e.g., an instructor or student.
CourseUser( role: Optional[CourseRole] = None, raw_role: Optional[str] = None, **kwargs: Any)
88 def __init__(self, 89 role: typing.Union[CourseRole, None] = None, 90 raw_role: typing.Union[str, None] = None, 91 **kwargs: typing.Any) -> None: 92 super().__init__(**kwargs) 93 94 self.role: typing.Union[CourseRole, None] = role 95 """ The role of this user within this course (e.g., owner, student). """ 96 97 self.raw_role: typing.Union[str, None] = raw_role 98 """ 99 The raw role string from the LMS. 100 This may not translate nicely into one of our known roles. 101 """
CORE_FIELDS =
['id', 'name', 'email', 'role']
The common fields shared across backends for this type.
raw_role: Optional[str]
The raw role string from the LMS. This may not translate nicely into one of our known roles.
def
is_student(self) -> bool:
103 def is_student(self) -> bool: 104 """ 105 Check if this course user is a student (and therefore be included in graded components like gradebooks). 106 Backends should implement this method. 107 """ 108 109 return (self.role == CourseRole.STUDENT)
Check if this course user is a student (and therefore be included in graded components like gradebooks). Backends should implement this method.