def get_all_permissions(self, course_id: t.Union['Course', int] = None
) -> t.Mapping[str, bool]:
"""Get all global permissions (:class:`Permission`) of this user or all
course permissions of the user in a specific :class:`Course`.
:param course_id: The course or course id
:returns: A name boolean mapping where the name is the name of the
permission and the value indicates if this user has this
permission.
"""
if isinstance(course_id, Course):
course_id = course_id.id
if course_id is None:
return self.role.get_all_permissions()
elif course_id in self.courses:
return self.courses[course_id].get_all_permissions()
else:
perms: t.Sequence[Permission]
perms = Permission.query.filter_by( # type: ignore
course_permission=True).all()
return {perm.name: False for perm in perms}
评论列表
文章目录