Skip to content

Commit

Permalink
Add missing key to dashboard routes type
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Jun 19, 2024
1 parent 2e70674 commit d365baa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
2 changes: 2 additions & 0 deletions lms/js_config_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class DashboardRoutes(TypedDict):
course: str
course_assignment_stats: str

organization_courses: str


class User(TypedDict):
is_staff: bool
Expand Down
34 changes: 15 additions & 19 deletions lms/resources/_js_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
):
Expand Down
1 change: 1 addition & 0 deletions tests/unit/lms/resources/_js_config/__init___test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit d365baa

Please sign in to comment.