From ad56a63c8eaea49e1173e621496f16fe78ed15ad Mon Sep 17 00:00:00 2001 From: Marcos Prieto Date: Fri, 22 Nov 2024 15:35:55 +0100 Subject: [PATCH] Expose assignment.is_gradable in the dashboard API This will allow the FE to base the decision to show the "sync grades" button both on the feature flag (part of the JSConfig dictionary) and the current assignment's `is_gradable` value. --- lms/js_config_types.py | 2 ++ lms/views/dashboard/api/assignment.py | 3 +++ .../unit/lms/views/dashboard/api/assignment_test.py | 13 ++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lms/js_config_types.py b/lms/js_config_types.py index 3572435436..b9795cb55a 100644 --- a/lms/js_config_types.py +++ b/lms/js_config_types.py @@ -96,6 +96,8 @@ class APIAssignment(TypedDict): id: int title: str created: str + is_gradable: bool + course: NotRequired[APICourse] sections: NotRequired[list[APISegment]] diff --git a/lms/views/dashboard/api/assignment.py b/lms/views/dashboard/api/assignment.py index 05d62e1f01..32e3e3f653 100644 --- a/lms/views/dashboard/api/assignment.py +++ b/lms/views/dashboard/api/assignment.py @@ -86,6 +86,7 @@ def assignments(self) -> APIAssignments: id=assignment.id, title=assignment.title, created=assignment.created, + is_gradable=assignment.is_gradable, ) for assignment in assignments ], @@ -106,6 +107,7 @@ def assignment(self) -> APIAssignment: id=assignment.id, title=assignment.title, created=assignment.created, + is_gradable=assignment.is_gradable, course=APICourse( id=assignment.course.id, title=assignment.course.lms_name, @@ -189,6 +191,7 @@ def course_assignments_metrics(self) -> APIAssignments: APIAssignment( id=assignment.id, title=assignment.title, + is_gradable=assignment.is_gradable, created=assignment.created, course=api_course, annotation_metrics=metrics, diff --git a/tests/unit/lms/views/dashboard/api/assignment_test.py b/tests/unit/lms/views/dashboard/api/assignment_test.py index 023a58a644..f95e8b7d95 100644 --- a/tests/unit/lms/views/dashboard/api/assignment_test.py +++ b/tests/unit/lms/views/dashboard/api/assignment_test.py @@ -40,7 +40,12 @@ def test_get_assignments( ) assert response == { "assignments": [ - {"id": a.id, "title": a.title, "created": a.created} + { + "id": a.id, + "title": a.title, + "is_gradable": a.is_gradable, + "created": a.created, + } for a in assignments ], "pagination": sentinel.pagination, @@ -70,6 +75,7 @@ def test_assignment( assert response == { "id": assignment.id, "title": assignment.title, + "is_gradable": assignment.is_gradable, "created": assignment.created, "course": {"id": assignment.course.id, "title": assignment.course.lms_name}, } @@ -98,6 +104,7 @@ def test_assignment_with_auto_grading( "id": assignment.id, "title": assignment.title, "created": assignment.created, + "is_gradable": assignment.is_gradable, "course": {"id": assignment.course.id, "title": assignment.course.lms_name}, "groups": [], "auto_grading_config": { @@ -127,6 +134,7 @@ def test_assignment_with_groups( "id": assignment.id, "title": assignment.title, "created": assignment.created, + "is_gradable": assignment.is_gradable, "course": {"id": assignment.course.id, "title": assignment.course.lms_name}, "groups": [ {"h_authority_provided_id": g.authority_provided_id, "name": g.lms_name} @@ -154,6 +162,7 @@ def test_assignment_with_sections( "id": assignment.id, "title": assignment.title, "created": assignment.created, + "is_gradable": assignment.is_gradable, "course": {"id": assignment.course.id, "title": assignment.course.lms_name}, "sections": [ {"h_authority_provided_id": g.authority_provided_id, "name": g.lms_name} @@ -211,6 +220,7 @@ def test_course_assignments( { "id": assignment.id, "title": assignment.title, + "is_gradable": assignment.is_gradable, "created": assignment.created, "course": { "id": course.id, @@ -225,6 +235,7 @@ def test_course_assignments( { "id": assignment_with_no_annos.id, "title": assignment_with_no_annos.title, + "is_gradable": assignment.is_gradable, "created": assignment_with_no_annos.created, "course": { "id": course.id,