diff --git a/lms/js_config_types.py b/lms/js_config_types.py index ee1929c023..2ec04b3658 100644 --- a/lms/js_config_types.py +++ b/lms/js_config_types.py @@ -63,6 +63,8 @@ class DashboardRoutes(TypedDict): course: str course_assignment_stats: str + organization_courses: str + class User(TypedDict): is_staff: bool diff --git a/lms/resources/_js_config/__init__.py b/lms/resources/_js_config/__init__.py index de919c7d63..c434223d39 100644 --- a/lms/resources/_js_config/__init__.py +++ b/lms/resources/_js_config/__init__.py @@ -5,7 +5,7 @@ from lms.error_code import ErrorCode from lms.events import LTIEvent -from lms.js_config_types import DashboardConfig, DashboardRoutes +from lms.js_config_types import DashboardConfig, DashboardRoutes, User from lms.models import Assignment, Course, Grouping from lms.product.blackboard import Blackboard from lms.product.canvas import Canvas @@ -251,11 +251,12 @@ def enable_error_dialog_mode(self, error_code, error_details=None, message=None) ) ) - def enable_dashboard_mode(self): + def enable_dashboard_mode(self) -> None: self._config.update( { "mode": JSConfig.Mode.DASHBOARD, "dashboard": DashboardConfig( + user=self._get_user_info(), routes=DashboardRoutes( assignment=self._to_frontend_template( "api.dashboard.assignment" @@ -274,8 +275,6 @@ def enable_dashboard_mode(self): ), } ) - if user_info := self._get_user_info(): - self._config["dashboard"]["user"] = user_info def enable_lti_launch_mode(self, course, assignment: Assignment): """ @@ -578,21 +577,6 @@ def _config(self): return config - def _get_user_info(self) -> dict | None: - if self._lti_user: - return { - "display_name": self._lti_user.display_name, - "is_staff": False, - } - - if self._request.has_permission(Permissions.STAFF): - return { - "display_name": self._request.identity.userid, - "is_staff": True, - } - - return None - def _get_product_info(self): """Return product (Canvas, BB, D2L..) configuration.""" product = self._request.product @@ -726,6 +710,18 @@ def _configure_groups(self, course, assignment): }, } + def _get_user_info(self) -> User: + if self._request.has_permission(Permissions.STAFF): + return { + "display_name": self._request.identity.userid, + "is_staff": True, + } + + return { + "display_name": self._lti_user.display_name, + "is_staff": False, + } + def _get_lti_launch_debug_values( self, course: Course, assignment: Assignment | None ): diff --git a/tests/unit/lms/resources/_js_config/__init___test.py b/tests/unit/lms/resources/_js_config/__init___test.py index f82b5fbce6..b1b02dd4ae 100644 --- a/tests/unit/lms/resources/_js_config/__init___test.py +++ b/tests/unit/lms/resources/_js_config/__init___test.py @@ -788,6 +788,7 @@ def pyramid_request(pyramid_request): ) pyramid_request.lti_params = LTIParams.from_request(pyramid_request) pyramid_request.product.route = Routes(oauth2_authorize="welcome") + return pyramid_request