Commit f774ccf3 by Robert Raposa

Remove support for sort_order (order_direction).

- Default of "desc" is all that is in use, and remains as-is.
- Discussion API keeps order_direction param, to minimize changes,
but it only accepts "desc".
- Discussion webapp simply no longer sends in the sort order.
parent 2abe3f7e
...@@ -69,22 +69,21 @@ def get_threads(request, course, user_info, discussion_id=None, per_page=THREADS ...@@ -69,22 +69,21 @@ def get_threads(request, course, user_info, discussion_id=None, per_page=THREADS
if something goes wrong, or ValueError if the group_id is invalid. if something goes wrong, or ValueError if the group_id is invalid.
Arguments: Arguments:
request: The user request. request (WSGIRequest): The user request.
course: The course object. course (CourseDescriptorWithMixins): The course object.
user_info: The comment client User object as a dict. user_info (dict): The comment client User object as a dict.
discussion_id: Optional discussion id/commentable id for context. discussion_id (unicode): Optional discussion id/commentable id for context.
per_page: Optional number of threads per page. per_page (int): Optional number of threads per page.
Returns: Returns:
A tuple of the threads and the query parameters used for the search. (tuple of list, dict): A tuple of the list of threads and a dict of the
:return: query parameters used for the search.
""" """
default_query_params = { default_query_params = {
'page': 1, 'page': 1,
'per_page': per_page, 'per_page': per_page,
'sort_key': 'activity', 'sort_key': 'activity',
'sort_order': 'desc',
'text': '', 'text': '',
'course_id': unicode(course.id), 'course_id': unicode(course.id),
'user_id': request.user.id, 'user_id': request.user.id,
...@@ -122,7 +121,6 @@ def get_threads(request, course, user_info, discussion_id=None, per_page=THREADS ...@@ -122,7 +121,6 @@ def get_threads(request, course, user_info, discussion_id=None, per_page=THREADS
[ [
'page', 'page',
'sort_key', 'sort_key',
'sort_order',
'text', 'text',
'commentable_ids', 'commentable_ids',
'flagged', 'flagged',
...@@ -483,7 +481,6 @@ def followed_threads(request, course_key, user_id): ...@@ -483,7 +481,6 @@ def followed_threads(request, course_key, user_id):
'page': 1, 'page': 1,
'per_page': THREADS_PER_PAGE, # more than threads_per_page to show more activities 'per_page': THREADS_PER_PAGE, # more than threads_per_page to show more activities
'sort_key': 'date', 'sort_key': 'date',
'sort_order': 'desc',
} }
query_params = merge_dict( query_params = merge_dict(
...@@ -494,7 +491,6 @@ def followed_threads(request, course_key, user_id): ...@@ -494,7 +491,6 @@ def followed_threads(request, course_key, user_id):
[ [
'page', 'page',
'sort_key', 'sort_key',
'sort_order',
'flagged', 'flagged',
'unread', 'unread',
'unanswered', 'unanswered',
......
...@@ -498,8 +498,9 @@ def get_thread_list( ...@@ -498,8 +498,9 @@ def get_thread_list(
order_by: The key in which to sort the threads by. The only values are order_by: The key in which to sort the threads by. The only values are
"last_activity_at", "comment_count", and "vote_count". The default is "last_activity_at", "comment_count", and "vote_count". The default is
"last_activity_at". "last_activity_at".
order_direction: The direction in which to sort the threads by. The only order_direction: The direction in which to sort the threads by. The default
values are "asc" or "desc". The default is "desc". and only value is "desc". This will be removed in a future major
version.
requested_fields: Indicates which additional fields to return requested_fields: Indicates which additional fields to return
for each thread. (i.e. ['profile_image']) for each thread. (i.e. ['profile_image'])
...@@ -528,9 +529,9 @@ def get_thread_list( ...@@ -528,9 +529,9 @@ def get_thread_list(
"order_by": "order_by":
["Invalid value. '{}' must be 'last_activity_at', 'comment_count', or 'vote_count'".format(order_by)] ["Invalid value. '{}' must be 'last_activity_at', 'comment_count', or 'vote_count'".format(order_by)]
}) })
if order_direction not in ["asc", "desc"]: if order_direction != "desc":
raise ValidationError({ raise ValidationError({
"order_direction": ["Invalid value. '{}' must be 'asc' or 'desc'".format(order_direction)] "order_direction": ["Invalid value. '{}' must be 'desc'".format(order_direction)]
}) })
course = _get_course(course_key, request.user) course = _get_course(course_key, request.user)
...@@ -546,7 +547,6 @@ def get_thread_list( ...@@ -546,7 +547,6 @@ def get_thread_list(
"per_page": page_size, "per_page": page_size,
"text": text_search, "text": text_search,
"sort_key": cc_map.get(order_by), "sort_key": cc_map.get(order_by),
"sort_order": order_direction,
} }
if view: if view:
......
...@@ -48,7 +48,7 @@ class ThreadListGetForm(_PaginationForm): ...@@ -48,7 +48,7 @@ class ThreadListGetForm(_PaginationForm):
required=False required=False
) )
order_direction = ChoiceField( order_direction = ChoiceField(
choices=[(choice, choice) for choice in ["asc", "desc"]], choices=[(choice, choice) for choice in ["desc"]],
required=False required=False
) )
requested_fields = MultiValueField(required=False) requested_fields = MultiValueField(required=False)
......
...@@ -627,7 +627,6 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -627,7 +627,6 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
"user_id": [unicode(self.user.id)], "user_id": [unicode(self.user.id)],
"course_id": [unicode(self.course.id)], "course_id": [unicode(self.course.id)],
"sort_key": ["activity"], "sort_key": ["activity"],
"sort_order": ["desc"],
"page": ["1"], "page": ["1"],
"per_page": ["1"], "per_page": ["1"],
"commentable_ids": ["topic_x,topic_meow"] "commentable_ids": ["topic_x,topic_meow"]
...@@ -639,7 +638,6 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -639,7 +638,6 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
"user_id": [unicode(self.user.id)], "user_id": [unicode(self.user.id)],
"course_id": [unicode(self.course.id)], "course_id": [unicode(self.course.id)],
"sort_key": ["activity"], "sort_key": ["activity"],
"sort_order": ["desc"],
"page": ["6"], "page": ["6"],
"per_page": ["14"], "per_page": ["14"],
}) })
...@@ -851,7 +849,6 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -851,7 +849,6 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
"user_id": [unicode(self.user.id)], "user_id": [unicode(self.user.id)],
"course_id": [unicode(self.course.id)], "course_id": [unicode(self.course.id)],
"sort_key": ["activity"], "sort_key": ["activity"],
"sort_order": ["desc"],
"page": ["1"], "page": ["1"],
"per_page": ["10"], "per_page": ["10"],
"text": ["test search string"], "text": ["test search string"],
...@@ -883,7 +880,6 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -883,7 +880,6 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
"user_id": [unicode(self.user.id)], "user_id": [unicode(self.user.id)],
"course_id": [unicode(self.course.id)], "course_id": [unicode(self.course.id)],
"sort_key": ["activity"], "sort_key": ["activity"],
"sort_order": ["desc"],
"page": ["1"], "page": ["1"],
"per_page": ["11"], "per_page": ["11"],
}) })
...@@ -915,7 +911,6 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -915,7 +911,6 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
"user_id": [unicode(self.user.id)], "user_id": [unicode(self.user.id)],
"course_id": [unicode(self.course.id)], "course_id": [unicode(self.course.id)],
"sort_key": ["activity"], "sort_key": ["activity"],
"sort_order": ["desc"],
"page": ["1"], "page": ["1"],
"per_page": ["11"], "per_page": ["11"],
query: ["true"], query: ["true"],
...@@ -957,20 +952,22 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -957,20 +952,22 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
"user_id": [unicode(self.user.id)], "user_id": [unicode(self.user.id)],
"course_id": [unicode(self.course.id)], "course_id": [unicode(self.course.id)],
"sort_key": [cc_query], "sort_key": [cc_query],
"sort_order": ["desc"],
"page": ["1"], "page": ["1"],
"per_page": ["11"], "per_page": ["11"],
}) })
@ddt.data("asc", "desc") def test_order_direction(self):
def test_order_direction_query(self, http_query): """
Only "desc" is supported for order. Also, since it is simply swallowed,
it isn't included in the params.
"""
self.register_get_threads_response([], page=1, num_pages=0) self.register_get_threads_response([], page=1, num_pages=0)
result = get_thread_list( result = get_thread_list(
self.request, self.request,
self.course.id, self.course.id,
page=1, page=1,
page_size=11, page_size=11,
order_direction=http_query, order_direction="desc",
).data ).data
expected_result = make_paginated_api_response( expected_result = make_paginated_api_response(
...@@ -986,11 +983,25 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -986,11 +983,25 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
"user_id": [unicode(self.user.id)], "user_id": [unicode(self.user.id)],
"course_id": [unicode(self.course.id)], "course_id": [unicode(self.course.id)],
"sort_key": ["activity"], "sort_key": ["activity"],
"sort_order": [http_query],
"page": ["1"], "page": ["1"],
"per_page": ["11"], "per_page": ["11"],
}) })
def test_invalid_order_direction(self):
"""
Test with invalid order_direction (e.g. "asc")
"""
with self.assertRaises(ValidationError) as assertion:
self.register_get_threads_response([], page=1, num_pages=0)
get_thread_list( # pylint: disable=expression-not-assigned
self.request,
self.course.id,
page=1,
page_size=11,
order_direction="asc",
).data
self.assertIn("order_direction", assertion.exception.message_dict)
@attr(shard=2) @attr(shard=2)
@ddt.ddt @ddt.ddt
......
...@@ -147,7 +147,6 @@ class ThreadListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase): ...@@ -147,7 +147,6 @@ class ThreadListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase):
("order_by", "last_activity_at"), ("order_by", "last_activity_at"),
("order_by", "comment_count"), ("order_by", "comment_count"),
("order_by", "vote_count"), ("order_by", "vote_count"),
("order_direction", "asc"),
("order_direction", "desc"), ("order_direction", "desc"),
) )
@ddt.unpack @ddt.unpack
......
...@@ -428,7 +428,6 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro ...@@ -428,7 +428,6 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro
"user_id": [unicode(self.user.id)], "user_id": [unicode(self.user.id)],
"course_id": [unicode(self.course.id)], "course_id": [unicode(self.course.id)],
"sort_key": ["activity"], "sort_key": ["activity"],
"sort_order": ["desc"],
"page": ["1"], "page": ["1"],
"per_page": ["10"], "per_page": ["10"],
}) })
...@@ -449,7 +448,6 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro ...@@ -449,7 +448,6 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro
"user_id": [unicode(self.user.id)], "user_id": [unicode(self.user.id)],
"course_id": [unicode(self.course.id)], "course_id": [unicode(self.course.id)],
"sort_key": ["activity"], "sort_key": ["activity"],
"sort_order": ["desc"],
"page": ["1"], "page": ["1"],
"per_page": ["10"], "per_page": ["10"],
query: ["true"], query: ["true"],
...@@ -471,7 +469,6 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro ...@@ -471,7 +469,6 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro
"user_id": [unicode(self.user.id)], "user_id": [unicode(self.user.id)],
"course_id": [unicode(self.course.id)], "course_id": [unicode(self.course.id)],
"sort_key": ["activity"], "sort_key": ["activity"],
"sort_order": ["desc"],
"page": ["18"], "page": ["18"],
"per_page": ["4"], "per_page": ["4"],
}) })
...@@ -497,7 +494,6 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro ...@@ -497,7 +494,6 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro
"user_id": [unicode(self.user.id)], "user_id": [unicode(self.user.id)],
"course_id": [unicode(self.course.id)], "course_id": [unicode(self.course.id)],
"sort_key": ["activity"], "sort_key": ["activity"],
"sort_order": ["desc"],
"page": ["1"], "page": ["1"],
"per_page": ["10"], "per_page": ["10"],
"text": ["test search string"], "text": ["test search string"],
...@@ -589,14 +585,16 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro ...@@ -589,14 +585,16 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro
self.assert_last_query_params({ self.assert_last_query_params({
"user_id": [unicode(self.user.id)], "user_id": [unicode(self.user.id)],
"course_id": [unicode(self.course.id)], "course_id": [unicode(self.course.id)],
"sort_order": ["desc"],
"page": ["1"], "page": ["1"],
"per_page": ["10"], "per_page": ["10"],
"sort_key": [cc_query], "sort_key": [cc_query],
}) })
@ddt.data("asc", "desc") def test_order_direction(self):
def test_order_direction(self, query): """
Test order direction, of which "desc" is the only valid option. The
option actually just gets swallowed, so it doesn't affect the params.
"""
threads = [make_minimal_cs_thread()] threads = [make_minimal_cs_thread()]
self.register_get_user_response(self.user) self.register_get_user_response(self.user)
self.register_get_threads_response(threads, page=1, num_pages=1) self.register_get_threads_response(threads, page=1, num_pages=1)
...@@ -604,7 +602,7 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro ...@@ -604,7 +602,7 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro
self.url, self.url,
{ {
"course_id": unicode(self.course.id), "course_id": unicode(self.course.id),
"order_direction": query, "order_direction": "desc",
} }
) )
self.assert_last_query_params({ self.assert_last_query_params({
...@@ -613,7 +611,6 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro ...@@ -613,7 +611,6 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro
"sort_key": ["activity"], "sort_key": ["activity"],
"page": ["1"], "page": ["1"],
"per_page": ["10"], "per_page": ["10"],
"sort_order": [query],
}) })
def test_mutually_exclusive(self): def test_mutually_exclusive(self):
......
...@@ -155,8 +155,9 @@ class ThreadViewSet(DeveloperErrorViewMixin, ViewSet): ...@@ -155,8 +155,9 @@ class ThreadViewSet(DeveloperErrorViewMixin, ViewSet):
"vote_count". The key to sort the threads by. The default is "vote_count". The key to sort the threads by. The default is
"last_activity_at". "last_activity_at".
* order_direction: Must be "asc" or "desc". The direction in which to * order_direction: Must be "desc". The direction in which to sort the
sort the threads by. The default is "desc". threads by. The default and only value is "desc". This will be
removed in a future major version.
* following: If true, retrieve only threads the requesting user is * following: If true, retrieve only threads the requesting user is
following following
...@@ -164,6 +165,7 @@ class ThreadViewSet(DeveloperErrorViewMixin, ViewSet): ...@@ -164,6 +165,7 @@ class ThreadViewSet(DeveloperErrorViewMixin, ViewSet):
* view: "unread" for threads the requesting user has not read, or * view: "unread" for threads the requesting user has not read, or
"unanswered" for question threads with no marked answer. Only one "unanswered" for question threads with no marked answer. Only one
can be selected. can be selected.
* requested_fields: (list) Indicates which additional fields to return * requested_fields: (list) Indicates which additional fields to return
for each thread. (supports 'profile_image') for each thread. (supports 'profile_image')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment