Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
fix: Update LTIAuthenticator setup course hook (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgwerner authored Oct 29, 2021
1 parent ca58cea commit 03770b3
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 362 deletions.
17 changes: 11 additions & 6 deletions src/illumidesk/illumidesk/authenticators/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@
raise EnvironmentError("ORGANIZATION_NAME env-var is not set")


class AddJupyterHubUserException(Exception):
"""Custom exception that is raised when adding a user to the JupyterHub database."""

pass


async def setup_course_hook_lti11(
self,
handler: RequestHandler,
authentication: Dict[str, str],
) -> Dict[str, str]:
Expand All @@ -56,7 +61,7 @@ async def setup_course_hook_lti11(

# normalize the name and course_id strings in authentication dictionary
username = authentication["name"]
lms_user_id = authentication["auth_state"]["lms_user_id"]
lms_user_id = authentication["auth_state"]["user_id"]
user_role = authentication["auth_state"]["roles"].split(",")[0]
course_id = lti_utils.normalize_string(
authentication["auth_state"]["context_label"]
Expand All @@ -70,7 +75,7 @@ async def setup_course_hook_lti11(
try:
# assign the user to 'nbgrader-<course_id>' group in jupyterhub and gradebook
await jupyterhub_api.add_student_to_jupyterhub_group(course_id, username)
except Exception as e:
except AddJupyterHubUserException as e:
logger.error(
"An error when adding student username: %s to course_id: %s with exception %s",
(username, course_id, e),
Expand All @@ -79,7 +84,7 @@ async def setup_course_hook_lti11(
try:
# assign the user in 'formgrade-<course_id>' group
await jupyterhub_api.add_instructor_to_jupyterhub_group(course_id, username)
except Exception as e:
except AddJupyterHubUserException as e:
logger.error(
"An error when adding instructor username: %s to course_id: %s with exception %s",
(username, course_id, e),
Expand Down Expand Up @@ -134,7 +139,7 @@ async def setup_course_hook(
try:
# assign the user to 'nbgrader-<course_id>' group in jupyterhub and gradebook
await jupyterhub_api.add_student_to_jupyterhub_group(course_id, username)
except Exception as e:
except AddJupyterHubUserException as e:
logger.error(
"An error when adding student username: %s to course_id: %s with exception %s",
(username, course_id, e),
Expand All @@ -143,7 +148,7 @@ async def setup_course_hook(
try:
# assign the user in 'formgrade-<course_id>' group
await jupyterhub_api.add_instructor_to_jupyterhub_group(course_id, username)
except Exception as e:
except AddJupyterHubUserException as e:
logger.error(
"An error when adding instructor username: %s to course_id: %s with exception %s",
(username, course_id, e),
Expand Down
Loading

0 comments on commit 03770b3

Please sign in to comment.