-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return actual value for roster last_updated #6913
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
from marshmallow import fields, validate | ||
from pyramid.view import view_config | ||
from sqlalchemy import Select | ||
|
||
from lms.js_config_types import ( | ||
AnnotationMetrics, | ||
|
@@ -84,7 +85,7 @@ def __init__(self, request) -> None: | |
schema=ListUsersSchema, | ||
) | ||
def students(self) -> APIStudents: | ||
students_query = self._students_query( | ||
_, students_query = self._students_query( | ||
assignment_ids=self.request.parsed_params.get("assignment_ids"), | ||
segment_authority_provided_ids=self.request.parsed_params.get( | ||
"segment_authority_provided_ids" | ||
|
@@ -141,7 +142,7 @@ def students_metrics(self) -> APIRoster: | |
stats_by_user = {s["userid"]: s for s in stats} | ||
students: list[RosterEntry] = [] | ||
|
||
users_query = self._students_query( | ||
roster_last_updated, users_query = self._students_query( | ||
assignment_ids=[assignment.id], | ||
segment_authority_provided_ids=request_segment_authority_provided_ids, | ||
h_userids=request_h_userids, | ||
|
@@ -179,9 +180,7 @@ def students_metrics(self) -> APIRoster: | |
if assignment.auto_grading_config: | ||
students = self._add_auto_grading_data(assignment, students) | ||
|
||
# We are not exposing the roster info here yet, just making the API changes to better coordinate with the frontend | ||
# For now we mark every roster entry as active and we don't include any last_activity. | ||
return APIRoster(students=students, last_updated=None) | ||
return APIRoster(students=students, last_updated=roster_last_updated) | ||
|
||
def _add_auto_grading_data( | ||
self, assignment: Assignment, api_students: list[RosterEntry] | ||
|
@@ -211,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]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This type anno helped find where we need to start returning a tuple |
||
course_ids = self.request.parsed_params.get("course_ids") | ||
# Single assigment fetch | ||
if ( | ||
|
@@ -234,7 +233,7 @@ def _students_query( | |
self.request, course_id=course_ids[0] | ||
) | ||
|
||
return self.user_service.get_users_for_course( | ||
return None, self.user_service.get_users_for_course( | ||
role_scope=RoleScope.COURSE, | ||
role_type=RoleType.LEARNER, | ||
course_id=course.id, | ||
|
@@ -246,7 +245,7 @@ def _students_query( | |
) | ||
# Full organization fetch | ||
if not course_ids and not assignment_ids and not segment_authority_provided_ids: | ||
return self.user_service.get_users_for_organization( | ||
return None, self.user_service.get_users_for_organization( | ||
role_scope=RoleScope.COURSE, | ||
role_type=RoleType.LEARNER, | ||
h_userids=h_userids, | ||
|
@@ -257,7 +256,7 @@ def _students_query( | |
admin_organization_ids=[org.id for org in admin_organizations], | ||
) | ||
|
||
return self.user_service.get_users( | ||
return None, self.user_service.get_users( | ||
role_scope=RoleScope.COURSE, | ||
role_type=RoleType.LEARNER, | ||
course_ids=self.request.parsed_params.get("course_ids"), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,46 +217,53 @@ def test_get_request_admin_organizations_for_staff( | |
|
||
assert svc.get_request_admin_organizations(pyramid_request) == [organization] | ||
|
||
@pytest.mark.parametrize("rosters_enabled", [True, False]) | ||
@pytest.mark.parametrize("roster_available", [True, False]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combined a couple of test into this one, adding all the combinations of enabled/disabled with the data available/missing. |
||
def test_get_assignment_roster_with_roster_disabled( | ||
self, svc, application_instance, user_service | ||
): | ||
assignment = factories.Assignment( | ||
course=factories.Course(application_instance=application_instance) | ||
) | ||
|
||
roster = svc.get_assignment_roster(assignment, sentinel.h_userids) | ||
|
||
user_service.get_users_for_assignment.assert_called_once_with( | ||
role_scope=RoleScope.COURSE, | ||
role_type=RoleType.LEARNER, | ||
assignment_id=assignment.id, | ||
h_userids=sentinel.h_userids, | ||
) | ||
assert ( | ||
roster | ||
== user_service.get_users_for_assignment.return_value.add_columns.return_value.order_by.return_value | ||
) | ||
|
||
def test_get_assignment_roster_with( | ||
self, svc, application_instance, roster_service | ||
self, | ||
svc, | ||
application_instance, | ||
user_service, | ||
roster_service, | ||
rosters_enabled, | ||
roster_available, | ||
): | ||
application_instance.settings.set("dashboard", "rosters", True) | ||
application_instance.settings.set("dashboard", "rosters", rosters_enabled) | ||
assignment = factories.Assignment( | ||
course=factories.Course(application_instance=application_instance) | ||
) | ||
|
||
roster = svc.get_assignment_roster(assignment, sentinel.h_userids) | ||
|
||
roster_service.get_assignment_roster.assert_called_once_with( | ||
assignment, | ||
role_scope=RoleScope.COURSE, | ||
role_type=RoleType.LEARNER, | ||
h_userids=sentinel.h_userids, | ||
) | ||
assert ( | ||
roster | ||
== roster_service.get_assignment_roster.return_value.order_by.return_value | ||
) | ||
if not roster_available: | ||
roster_service.assignment_roster_last_updated.return_value = None | ||
|
||
last_updated, roster = svc.get_assignment_roster(assignment, sentinel.h_userids) | ||
|
||
if not roster_available or not rosters_enabled: | ||
user_service.get_users_for_assignment.assert_called_once_with( | ||
role_scope=RoleScope.COURSE, | ||
role_type=RoleType.LEARNER, | ||
assignment_id=assignment.id, | ||
h_userids=sentinel.h_userids, | ||
) | ||
assert not last_updated | ||
assert ( | ||
roster | ||
== user_service.get_users_for_assignment.return_value.add_columns.return_value.order_by.return_value | ||
) | ||
else: | ||
roster_service.get_assignment_roster.assert_called_once_with( | ||
assignment, | ||
role_scope=RoleScope.COURSE, | ||
role_type=RoleType.LEARNER, | ||
h_userids=sentinel.h_userids, | ||
) | ||
assert ( | ||
last_updated | ||
== roster_service.assignment_roster_last_updated.return_value | ||
) | ||
assert ( | ||
roster | ||
== roster_service.get_assignment_roster.return_value.order_by.return_value | ||
) | ||
|
||
@pytest.fixture() | ||
def svc( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't care about last_udpated for the dropdowns, ignoring the value there.