From 5b35ab3668755dffd55a3ef22437cb74742ffa93 Mon Sep 17 00:00:00 2001 From: christopher lee Date: Tue, 11 Aug 2015 16:56:35 -0400 Subject: [PATCH] Added optional mark_as_read field to comments in Discussion API Currently when GETting comments, the thread of the comment will be marked as read. This change makes this effect optional as well as setting the default to not mark the thread as read. --- lms/djangoapps/discussion_api/api.py | 6 ++++-- lms/djangoapps/discussion_api/forms.py | 1 + lms/djangoapps/discussion_api/tests/test_api.py | 2 +- lms/djangoapps/discussion_api/tests/test_forms.py | 1 + lms/djangoapps/discussion_api/tests/test_views.py | 4 ++-- lms/djangoapps/discussion_api/views.py | 6 +++++- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lms/djangoapps/discussion_api/api.py b/lms/djangoapps/discussion_api/api.py index 4831bce834..e0b8a9596a 100644 --- a/lms/djangoapps/discussion_api/api.py +++ b/lms/djangoapps/discussion_api/api.py @@ -337,7 +337,7 @@ def get_thread_list( return ret -def get_comment_list(request, thread_id, endorsed, page, page_size): +def get_comment_list(request, thread_id, endorsed, page, page_size, mark_as_read=False): """ Return the list of comments in the given thread. @@ -356,6 +356,8 @@ def get_comment_list(request, thread_id, endorsed, page, page_size): page_size: The number of comments to retrieve per page + mark_as_read: Marks the thread of the comment list as read. + Returns: A paginated result containing a list of comments; see @@ -368,7 +370,7 @@ def get_comment_list(request, thread_id, endorsed, page, page_size): retrieve_kwargs={ "recursive": True, "user_id": request.user.id, - "mark_as_read": True, + "mark_as_read": mark_as_read, "response_skip": response_skip, "response_limit": page_size, } diff --git a/lms/djangoapps/discussion_api/forms.py b/lms/djangoapps/discussion_api/forms.py index c2a1be5a6e..62c902bd65 100644 --- a/lms/djangoapps/discussion_api/forms.py +++ b/lms/djangoapps/discussion_api/forms.py @@ -121,6 +121,7 @@ class CommentListGetForm(_PaginationForm): # TODO: should we use something better here? This only accepts "True", # "False", "1", and "0" endorsed = NullBooleanField(required=False) + mark_as_read = BooleanField(required=False) class CommentActionsForm(Form): diff --git a/lms/djangoapps/discussion_api/tests/test_api.py b/lms/djangoapps/discussion_api/tests/test_api.py index ec4f7c1875..2b85f3661a 100644 --- a/lms/djangoapps/discussion_api/tests/test_api.py +++ b/lms/djangoapps/discussion_api/tests/test_api.py @@ -1083,7 +1083,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase): { "recursive": ["True"], "user_id": [str(self.user.id)], - "mark_as_read": ["True"], + "mark_as_read": ["False"], "resp_skip": ["70"], "resp_limit": ["14"], } diff --git a/lms/djangoapps/discussion_api/tests/test_forms.py b/lms/djangoapps/discussion_api/tests/test_forms.py index 92af348cdd..e6ea3931cb 100644 --- a/lms/djangoapps/discussion_api/tests/test_forms.py +++ b/lms/djangoapps/discussion_api/tests/test_forms.py @@ -186,6 +186,7 @@ class CommentListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase): "endorsed": False, "page": 2, "page_size": 13, + "mark_as_read": False } ) diff --git a/lms/djangoapps/discussion_api/tests/test_views.py b/lms/djangoapps/discussion_api/tests/test_views.py index 9113001ed0..166940ad26 100644 --- a/lms/djangoapps/discussion_api/tests/test_views.py +++ b/lms/djangoapps/discussion_api/tests/test_views.py @@ -698,7 +698,7 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): "resp_skip": ["0"], "resp_limit": ["10"], "user_id": [str(self.user.id)], - "mark_as_read": ["True"], + "mark_as_read": ["False"], } ) @@ -732,7 +732,7 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): "resp_skip": ["68"], "resp_limit": ["4"], "user_id": [str(self.user.id)], - "mark_as_read": ["True"], + "mark_as_read": ["False"], } ) diff --git a/lms/djangoapps/discussion_api/views.py b/lms/djangoapps/discussion_api/views.py index 3663a8cb24..38bc5ee784 100644 --- a/lms/djangoapps/discussion_api/views.py +++ b/lms/djangoapps/discussion_api/views.py @@ -314,6 +314,9 @@ class CommentViewSet(_ViewMixin, DeveloperErrorViewMixin, ViewSet): * page_size: The number of items per page (default is 10, max is 100) + * mark_as_read: Will mark the thread of the comments as read. (default + is False) + **POST Parameters**: * thread_id (required): The thread to post the comment in @@ -404,7 +407,8 @@ class CommentViewSet(_ViewMixin, DeveloperErrorViewMixin, ViewSet): form.cleaned_data["thread_id"], form.cleaned_data["endorsed"], form.cleaned_data["page"], - form.cleaned_data["page_size"] + form.cleaned_data["page_size"], + form.cleaned_data["mark_as_read"] ) )