Skip to content
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 simple api to drf compatible ( 3rd api ) list_email_content #35111

Merged
merged 9 commits into from
Aug 22, 2024
38 changes: 25 additions & 13 deletions lms/djangoapps/instructor/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2172,23 +2172,35 @@ def list_background_email_tasks(request, course_id):
return JsonResponse(response_payload)


@require_POST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing that this is a POST request in the first place given that it is not sending any data in the POST body and not making any modifications. But that change was made in #12719 for reasons that are unclear to us now so we'll leave it as is for now and we can re-visit if/when we want to revamp the instructor APIs further.

This will at-least make these APIs all visible in our openapi spec and make the APIs usable by other token types than just session.

(Not something you need to do anything about, just leaving a not for future investigators.)

@ensure_csrf_cookie
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
@require_course_permission(permissions.EMAIL)
def list_email_content(request, course_id):
@method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch')
class ListEmailContent(APIView):
"""
List the content of bulk emails sent
"""
course_id = CourseKey.from_string(course_id)
task_type = InstructorTaskTypes.BULK_COURSE_EMAIL
# First get tasks list of bulk emails sent
emails = task_api.get_instructor_task_history(course_id, task_type=task_type)
permission_classes = (IsAuthenticated, permissions.InstructorPermission)
permission_name = permissions.EMAIL

response_payload = {
'emails': list(map(extract_email_features, emails)),
}
return JsonResponse(response_payload)
@method_decorator(ensure_csrf_cookie)
def post(self, request, course_id):
"""
List the content of bulk emails sent for a specific course.

Args:
request (HttpRequest): The HTTP request object.
course_id (str): The ID of the course for which to list the bulk emails.

Returns:
HttpResponse: A response object containing the list of bulk email contents.
"""
course_id = CourseKey.from_string(course_id)
task_type = InstructorTaskTypes.BULK_COURSE_EMAIL
# First get tasks list of bulk emails sent
emails = task_api.get_instructor_task_history(course_id, task_type=task_type)

response_payload = {
'emails': list(map(extract_email_features, emails)),
}
return JsonResponse(response_payload)


class InstructorTaskSerializer(serializers.Serializer): # pylint: disable=abstract-method
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/instructor/views/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
name='mark_student_can_skip_entrance_exam'),
path('list_instructor_tasks', api.list_instructor_tasks, name='list_instructor_tasks'),
path('list_background_email_tasks', api.list_background_email_tasks, name='list_background_email_tasks'),
path('list_email_content', api.list_email_content, name='list_email_content'),
path('list_email_content', api.ListEmailContent.as_view(), name='list_email_content'),
path('list_forum_members', api.list_forum_members, name='list_forum_members'),
path('update_forum_role_membership', api.update_forum_role_membership, name='update_forum_role_membership'),
path('send_email', api.send_email, name='send_email'),
Expand Down
Loading