From 8c13fae0ff552f01e46c7cb54185a9d2f241843d Mon Sep 17 00:00:00 2001 From: Muhammad Adeel Tajamul <77053848+muhammadadeeltajamul@users.noreply.github.com> Date: Mon, 12 Sep 2022 12:31:57 +0500 Subject: [PATCH] feat: backend change for copy post functionality for discussions post (#30941) Co-authored-by: adeel.tajamul --- lms/djangoapps/discussion/rest_api/permissions.py | 2 ++ lms/djangoapps/discussion/rest_api/tests/test_api.py | 7 ++++--- .../discussion/rest_api/tests/test_permissions.py | 5 +++-- .../discussion/rest_api/tests/test_serializers.py | 2 +- .../discussion/rest_api/tests/test_views.py | 12 ++++++------ lms/djangoapps/discussion/rest_api/tests/utils.py | 1 + 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lms/djangoapps/discussion/rest_api/permissions.py b/lms/djangoapps/discussion/rest_api/permissions.py index 671c36b94c..01fcfaff8e 100644 --- a/lms/djangoapps/discussion/rest_api/permissions.py +++ b/lms/djangoapps/discussion/rest_api/permissions.py @@ -110,6 +110,8 @@ def get_editable_fields(cc_content: Union[Thread, Comment], context: Dict) -> Se "pinned": is_thread and is_privileged, "read": is_thread, } + if is_thread: + editable_fields.update({"copy_link": True}) if is_thread_closed: # Return only editable fields diff --git a/lms/djangoapps/discussion/rest_api/tests/test_api.py b/lms/djangoapps/discussion/rest_api/tests/test_api.py index dd81828838..20d76c56b1 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_api.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_api.py @@ -802,7 +802,7 @@ class GetThreadListTest(ForumsEnableMixin, CommentsServiceMockMixin, UrlResetMix "comment_count": 6, "unread_comment_count": 3, "comment_list_url": "http://testserver/api/discussion/v1/comments/?thread_id=test_thread_id_0", - "editable_fields": ["abuse_flagged", "following", "read", "voted"], + "editable_fields": ["abuse_flagged", "copy_link", "following", "read", "voted"], "has_endorsed": True, "read": True, "created_at": "2015-04-28T00:00:00Z", @@ -832,7 +832,7 @@ class GetThreadListTest(ForumsEnableMixin, CommentsServiceMockMixin, UrlResetMix "non_endorsed_comment_list_url": ( "http://testserver/api/discussion/v1/comments/?thread_id=test_thread_id_1&endorsed=False" ), - "editable_fields": ["abuse_flagged", "following", "read", "voted"], + "editable_fields": ["abuse_flagged", "copy_link", "following", "read", "voted"], "abuse_flagged_count": None, "can_delete": False, }), @@ -1893,6 +1893,7 @@ class CreateThreadTest( "anonymous", "close_reason_code", "closed", + "copy_link", "edit_reason_code", "following", "pinned", @@ -3718,7 +3719,7 @@ class RetrieveThreadTest( self.request.user = non_author_user assert get_thread(self.request, self.thread_id) == self.expected_thread_data({ 'can_delete': False, - 'editable_fields': ['abuse_flagged', 'following', 'read', 'voted'], + 'editable_fields': ['abuse_flagged', 'copy_link', 'following', 'read', 'voted'], 'unread_comment_count': 1 }) assert httpretty.last_request().method == 'GET' diff --git a/lms/djangoapps/discussion/rest_api/tests/test_permissions.py b/lms/djangoapps/discussion/rest_api/tests/test_permissions.py index d457b03371..4c2a4deed9 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_permissions.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_permissions.py @@ -63,7 +63,8 @@ class GetInitializableFieldsTest(ModuleStoreTestCase): ) actual = get_initializable_thread_fields(context) expected = { - "abuse_flagged", "course_id", "following", "raw_body", "read", "title", "topic_id", "type", "voted" + "abuse_flagged", "copy_link", "course_id", "following", "raw_body", + "read", "title", "topic_id", "type", "voted" } if is_privileged: expected |= {"closed", "pinned", "close_reason_code", "edit_reason_code"} @@ -116,7 +117,7 @@ class GetEditableFieldsTest(ModuleStoreTestCase): allow_anonymous_to_peers=allow_anonymous_to_peers, ) actual = get_editable_fields(thread, context) - expected = {"abuse_flagged", "following", "read", "voted"} + expected = {"abuse_flagged", "copy_link", "following", "read", "voted"} if is_privileged: expected |= {"closed", "pinned", "close_reason_code", "edit_reason_code"} if is_author or is_privileged: diff --git a/lms/djangoapps/discussion/rest_api/tests/test_serializers.py b/lms/djangoapps/discussion/rest_api/tests/test_serializers.py index 6fbedb4ff4..a4cfd93406 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_serializers.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_serializers.py @@ -186,7 +186,7 @@ class ThreadSerializerSerializationTest(SerializerTestMixin, SharedModuleStoreTe "comment_count": 6, "unread_comment_count": 3, "pinned": True, - "editable_fields": ["abuse_flagged", "following", "read", "voted"], + "editable_fields": ["abuse_flagged", "copy_link", "following", "read", "voted"], "abuse_flagged_count": None, }) assert self.serialize(thread) == expected diff --git a/lms/djangoapps/discussion/rest_api/tests/test_views.py b/lms/djangoapps/discussion/rest_api/tests/test_views.py index 0ed789eff9..b856efeb83 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_views.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_views.py @@ -929,7 +929,7 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro "unread_comment_count": 3, "voted": True, "author": self.author.username, - "editable_fields": ["abuse_flagged", "following", "read", "voted"], + "editable_fields": ["abuse_flagged", "copy_link", "following", "read", "voted"], "abuse_flagged_count": None, })] self.register_get_threads_response(source_threads, page=1, num_pages=2) @@ -1304,7 +1304,7 @@ class ThreadViewSetPartialUpdateTest(DiscussionAPIViewTestMixin, ModuleStoreTest 'rendered_body': '

Edited body

', 'preview_body': 'Edited body', 'editable_fields': [ - 'abuse_flagged', 'anonymous', 'following', 'raw_body', 'read', + 'abuse_flagged', 'anonymous', 'copy_link', 'following', 'raw_body', 'read', 'title', 'topic_id', 'type', 'voted' ], 'created_at': 'Test Created Date', @@ -1357,7 +1357,7 @@ class ThreadViewSetPartialUpdateTest(DiscussionAPIViewTestMixin, ModuleStoreTest 'read': True, 'closed': True, 'abuse_flagged': value, - 'editable_fields': ['abuse_flagged', 'read'], + 'editable_fields': ['abuse_flagged', 'copy_link', 'read'], 'comment_count': 1, 'unread_comment_count': 0 }) @@ -1388,7 +1388,7 @@ class ThreadViewSetPartialUpdateTest(DiscussionAPIViewTestMixin, ModuleStoreTest 'comment_count': 1, 'read': True, 'editable_fields': [ - 'abuse_flagged', 'anonymous', 'following', 'raw_body', 'read', + 'abuse_flagged', 'anonymous', 'copy_link', 'following', 'raw_body', 'read', 'title', 'topic_id', 'type', 'voted' ], 'response_count': 2 @@ -1415,7 +1415,7 @@ class ThreadViewSetPartialUpdateTest(DiscussionAPIViewTestMixin, ModuleStoreTest 'comment_count': 1, 'can_delete': False, 'read': True, - 'editable_fields': ['abuse_flagged', 'following', 'read', 'voted'], + 'editable_fields': ['abuse_flagged', 'copy_link', 'following', 'read', 'voted'], 'response_count': 2 }) @@ -1493,7 +1493,7 @@ class LearnerThreadViewAPITest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): { "key": "editable_fields", "value": [ - 'abuse_flagged', 'anonymous', 'following', 'raw_body', + 'abuse_flagged', 'anonymous', 'copy_link', 'following', 'raw_body', 'read', 'title', 'topic_id', 'type', 'voted' ] }, diff --git a/lms/djangoapps/discussion/rest_api/tests/utils.py b/lms/djangoapps/discussion/rest_api/tests/utils.py index 8fdf26c3d6..e4b5285324 100644 --- a/lms/djangoapps/discussion/rest_api/tests/utils.py +++ b/lms/djangoapps/discussion/rest_api/tests/utils.py @@ -470,6 +470,7 @@ class CommentsServiceMockMixin: "editable_fields": [ "abuse_flagged", "anonymous", + "copy_link", "following", "raw_body", "read",