Skip to content

Commit

Permalink
Fix issue while trying to fetch multiple groups rosters
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Dec 19, 2024
1 parent f760778 commit 3ca2b4f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
12 changes: 7 additions & 5 deletions lms/views/dashboard/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from marshmallow import fields, validate
from pyramid.view import view_config
from sqlalchemy import Select
from sqlalchemy import Select, true

from lms.js_config_types import (
AnnotationMetrics,
Expand All @@ -13,7 +13,7 @@
AutoGradingGrade,
RosterEntry,
)
from lms.models import Assignment, RoleScope, RoleType, User
from lms.models import Assignment, LMSUser, RoleScope, RoleType, User
from lms.security import Permissions
from lms.services import UserService
from lms.services.auto_grading import AutoGradingService
Expand Down Expand Up @@ -210,7 +210,7 @@ def _students_query(
assignment_ids: list[int],
segment_authority_provided_ids: list[str],
h_userids: list[str] | None = None,
) -> tuple[datetime | None, Select]:
) -> tuple[datetime | None, Select[tuple[LMSUser | User, bool]]]:
course_ids = self.request.parsed_params.get("course_ids")
# Single assigment fetch
if (
Expand Down Expand Up @@ -254,7 +254,8 @@ def _students_query(
if self.request.user
else None,
admin_organization_ids=[org.id for org in admin_organizations],
)
# For launch data we always add the "active" column as true for compatibility with the roster query.
).add_columns(true())

return None, self.user_service.get_users(
role_scope=RoleScope.COURSE,
Expand All @@ -270,4 +271,5 @@ def _students_query(
h_userids=h_userids,
# Only users belonging to these segments
segment_authority_provided_ids=segment_authority_provided_ids,
)
# For launch data we always add the "active" column as true for compatibility with the roster query.
).add_columns(true())
4 changes: 2 additions & 2 deletions lms/views/dashboard/pagination.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import logging
from types import NoneType
from typing import TypeVar
from typing import Any, TypeVar
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse

from marshmallow import ValidationError, fields, post_load, validate
Expand Down Expand Up @@ -39,7 +39,7 @@ def _get_next_url(current_url, cursor_value) -> str:


def get_page(
request, items_query: Select[tuple[T]], cursor_columns: list
request, items_query: Select[tuple[T, *tuple[Any]]], cursor_columns: list
) -> tuple[list[T], Pagination]:
"""Return the first page and pagination metadata from a query."""

Expand Down
24 changes: 10 additions & 14 deletions tests/unit/lms/views/dashboard/api/user_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_get_students(self, user_service, pyramid_request, views, get_page):
)
get_page.assert_called_once_with(
pyramid_request,
user_service.get_users.return_value,
user_service.get_users.return_value.add_columns.return_value,
[User.display_name, User.id],
)
assert response == {
Expand Down Expand Up @@ -92,21 +92,17 @@ def test_students_metrics(
pyramid_request.parsed_params["segment_authority_provided_ids"] = [
g.authority_provided_id for g in segments
]
user_service.get_users.return_value = (
select(User)
.where(
User.id.in_(
[
u.id
for u in [
student,
student_no_annos,
student_no_annos_no_name,
]
user_service.get_users.return_value = select(User).where(
User.id.in_(
[
u.id
for u in [
student,
student_no_annos,
student_no_annos_no_name,
]
)
]
)
.add_columns(True)
)
else:
db_session.flush()
Expand Down

0 comments on commit 3ca2b4f

Please sign in to comment.