From ac2436f5204a952fb09e6d643ada787cfe5fab6d Mon Sep 17 00:00:00 2001 From: Waqas Khalid Date: Tue, 2 Sep 2014 17:42:04 +0500 Subject: [PATCH] User can flag the post whether thread is closed or open When the thread is closed user can't able to report the thread and it gives the error. User can now report thread even it is closed. TNL-151 --- .../django_comment_client/base/tests.py | 40 +++++++++++++++---- .../django_comment_client/permissions.py | 8 ++-- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/lms/djangoapps/django_comment_client/base/tests.py b/lms/djangoapps/django_comment_client/base/tests.py index 34ede494d7..bbb3c3d13a 100644 --- a/lms/djangoapps/django_comment_client/base/tests.py +++ b/lms/djangoapps/django_comment_client/base/tests.py @@ -422,7 +422,13 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin): data={"body": updated_body} ) - def test_flag_thread(self, mock_request): + def test_flag_thread_open(self, mock_request): + self.flag_thread(mock_request, False) + + def test_flag_thread_close(self, mock_request): + self.flag_thread(mock_request, True) + + def flag_thread(self, mock_request, is_closed): mock_request.return_value.status_code = 200 self._set_mock_request_data(mock_request, { "title": "Hello", @@ -434,7 +440,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin): "created_at": "2013-05-10T18:53:43Z", "updated_at": "2013-05-10T18:53:43Z", "at_position_list": [], - "closed": False, + "closed": is_closed, "id": "518d4237b023791dca00000d", "user_id": "1","username": "robot", "votes": { @@ -490,7 +496,13 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin): assert_equal(response.status_code, 200) - def test_un_flag_thread(self, mock_request): + def test_un_flag_thread_open(self, mock_request): + self.un_flag_thread(mock_request, False) + + def test_un_flag_thread_close(self, mock_request): + self.un_flag_thread(mock_request, True) + + def un_flag_thread(self, mock_request, is_closed): mock_request.return_value.status_code = 200 self._set_mock_request_data(mock_request, { "title": "Hello", @@ -502,7 +514,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin): "created_at": "2013-05-10T18:53:43Z", "updated_at": "2013-05-10T18:53:43Z", "at_position_list": [], - "closed": False, + "closed": is_closed, "id": "518d4237b023791dca00000d", "user_id": "1", "username": "robot", @@ -559,7 +571,13 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin): assert_equal(response.status_code, 200) - def test_flag_comment(self, mock_request): + def test_flag_comment_open(self, mock_request): + self.flag_comment(mock_request, False) + + def test_flag_comment_close(self, mock_request): + self.flag_comment(mock_request, True) + + def flag_comment(self, mock_request, is_closed): mock_request.return_value.status_code = 200 self._set_mock_request_data(mock_request, { "body": "this is a comment", @@ -570,7 +588,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin): "created_at": "2013-05-10T18:53:43Z", "updated_at": "2013-05-10T18:53:43Z", "at_position_list": [], - "closed": False, + "closed": is_closed, "id": "518d4237b023791dca00000d", "user_id": "1", "username": "robot", @@ -622,7 +640,13 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin): assert_equal(response.status_code, 200) - def test_un_flag_comment(self, mock_request): + def test_un_flag_comment_open(self, mock_request): + self.un_flag_comment(mock_request, False) + + def test_un_flag_comment_close(self, mock_request): + self.un_flag_comment(mock_request, True) + + def un_flag_comment(self, mock_request, is_closed): mock_request.return_value.status_code = 200 self._set_mock_request_data(mock_request, { "body": "this is a comment", @@ -633,7 +657,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin): "created_at": "2013-05-10T18:53:43Z", "updated_at": "2013-05-10T18:53:43Z", "at_position_list": [], - "closed": False, + "closed": is_closed, "id": "518d4237b023791dca00000d", "user_id": "1", "username": "robot", diff --git a/lms/djangoapps/django_comment_client/permissions.py b/lms/djangoapps/django_comment_client/permissions.py index 0826e3d469..30d2639144 100644 --- a/lms/djangoapps/django_comment_client/permissions.py +++ b/lms/djangoapps/django_comment_client/permissions.py @@ -106,10 +106,10 @@ VIEW_PERMISSIONS = { 'vote_for_comment': [['vote', 'is_open']], 'undo_vote_for_comment': [['unvote', 'is_open']], 'vote_for_thread': [['vote', 'is_open']], - 'flag_abuse_for_thread': [['vote', 'is_open']], - 'un_flag_abuse_for_thread': [['vote', 'is_open']], - 'flag_abuse_for_comment': [['vote', 'is_open']], - 'un_flag_abuse_for_comment': [['vote', 'is_open']], + 'flag_abuse_for_thread': ['vote'], + 'un_flag_abuse_for_thread': ['vote'], + 'flag_abuse_for_comment': ['vote'], + 'un_flag_abuse_for_comment': ['vote'], 'undo_vote_for_thread': [['unvote', 'is_open']], 'pin_thread': ['openclose_thread'], 'un_pin_thread': ['openclose_thread'],