-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat: upgrading list_instructor_tasks to DRF ( 10th ) #35332
Changes from 10 commits
036ae63
a939e58
1b4712d
55dd99f
89741fc
0c17464
4003424
637599c
eaafd16
5f4307e
51800f7
d117849
ae2a768
5be8671
b28f5c6
4ddffd9
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 |
---|---|---|
|
@@ -105,7 +105,9 @@ | |
from lms.djangoapps.instructor_task.api_helper import AlreadyRunningError, QueueConnectionError | ||
from lms.djangoapps.instructor_task.data import InstructorTaskTypes | ||
from lms.djangoapps.instructor_task.models import ReportStore | ||
from lms.djangoapps.instructor.views.serializer import RoleNameSerializer, UserSerializer, AccessSerializer | ||
from lms.djangoapps.instructor.views.serializer import ( | ||
AccessSerializer, ListInstructorSerializer, RoleNameSerializer, UserSerializer | ||
) | ||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview | ||
from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort, is_course_cohorted | ||
from openedx.core.djangoapps.course_groups.models import CourseUserGroup | ||
|
@@ -2322,9 +2324,8 @@ def get(self, request, course_id): | |
return _list_instructor_tasks(request=request, course_id=course_id) | ||
|
||
|
||
@require_POST | ||
@ensure_csrf_cookie | ||
def list_instructor_tasks(request, course_id): | ||
@method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch') | ||
class ListInstructorTasks(APIView): | ||
""" | ||
List instructor tasks. | ||
|
||
|
@@ -2334,7 +2335,21 @@ def list_instructor_tasks(request, course_id): | |
- `problem_location_str` and `unique_student_identifier` lists task | ||
history for problem AND student (intersection) | ||
""" | ||
return _list_instructor_tasks(request=request, course_id=course_id) | ||
permission_classes = (IsAuthenticated, permissions.InstructorPermission) | ||
permission_name = permissions.SHOW_TASKS | ||
serializer_class = ListInstructorSerializer | ||
|
||
@method_decorator(ensure_csrf_cookie) | ||
def post(self, request, course_id): | ||
""" | ||
List instructor tasks. | ||
""" | ||
serializer = self.serializer_class(data=request.data) | ||
serializer.is_valid(raise_exception=True) | ||
|
||
return _list_instructor_tasks( | ||
request=request, course_id=course_id | ||
) | ||
|
||
|
||
@cache_control(no_cache=True, no_store=True, must_revalidate=True) | ||
|
@@ -2345,10 +2360,21 @@ def _list_instructor_tasks(request, course_id): | |
|
||
Internal function with common code for both DRF and and tradition views. | ||
""" | ||
# This method is also used by other APIs with the GET method. | ||
# The query_params attribute is utilized for GET requests, | ||
# where parameters are passed as query strings. | ||
|
||
course_id = CourseKey.from_string(course_id) | ||
params = getattr(request, 'query_params', request.POST) | ||
problem_location_str = strip_if_string(params.get('problem_location_str', False)) | ||
student = params.get('unique_student_identifier', None) | ||
|
||
# For the DRF POST method, retrieve the data from request.data | ||
if not student and not problem_location_str: | ||
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. Why not just pass the serializer from the 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. Done, now picking validated-data. |
||
params = getattr(request, 'data', request.POST) | ||
problem_location_str = strip_if_string(params.get('problem_location_str', False)) | ||
student = params.get('unique_student_identifier', None) | ||
|
||
if student is not None: | ||
student = get_student_from_identifier(student) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,40 @@ def validate_unique_student_identifier(self, value): | |
return None | ||
|
||
return user | ||
|
||
|
||
class ListInstructorSerializer(serializers.Serializer): # pylint: disable=abstract-method | ||
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. Suggestion: I think a better name for this would be the |
||
""" | ||
Serializer for handling the input data for the problem response report generation API. | ||
|
||
Attributes: | ||
unique_student_identifier (str): The email or username of the student. | ||
This field is optional, but if provided, the `problem_location_str` | ||
must also be provided. | ||
problem_location_str (str): The string representing the location of the problem within the course. | ||
This field is optional, unless `unique_student_identifier` is provided. | ||
""" | ||
unique_student_identifier = serializers.CharField( | ||
max_length=255, | ||
help_text="Email or username of student", | ||
required=False | ||
) | ||
problem_location_str = serializers.CharField( | ||
help_text="Problem location", | ||
required=False | ||
) | ||
|
||
def validate(self, data): | ||
""" | ||
Validate the data to ensure that if unique_student_identifier is provided, | ||
problem_location_str must also be provided. | ||
""" | ||
unique_student_identifier = data.get('unique_student_identifier') | ||
problem_location_str = data.get('problem_location_str') | ||
|
||
if unique_student_identifier and not problem_location_str: | ||
raise serializers.ValidationError( | ||
"unique_student_identifier must accompany problem_location_str" | ||
) | ||
|
||
return data |
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.
It looks like this API was previously a POST method but with query string input params, Can we just update the instructor dash to call this as a
GET
method instead since it doesn't actually modify any data?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.
They are not sending any data. Its a just a post call without any payload. I just maintained the behaviour. May be some other front-end is using it this way ?
Also another similar api exists with
GET
and its hitting same method for getting data. But its different version.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.
Interesting, okay seems like we have some redundancy that we should cleanup but that can be part of some future work. I don't want to blow up the scope of this change.