diff --git a/lms/djangoapps/discussion/rest_api/permissions.py b/lms/djangoapps/discussion/rest_api/permissions.py index dc888729bb9c..f8a5f6288c51 100644 --- a/lms/djangoapps/discussion/rest_api/permissions.py +++ b/lms/djangoapps/discussion/rest_api/permissions.py @@ -93,6 +93,7 @@ def get_editable_fields(cc_content: Union[Thread, Comment], context: Dict) -> Se is_thread = cc_content["type"] == "thread" is_comment = cc_content["type"] == "comment" has_moderation_privilege = context["has_moderation_privilege"] + is_staff_or_admin = context["is_staff_or_admin"] if is_thread: is_thread_closed = cc_content["closed"] @@ -107,7 +108,7 @@ def get_editable_fields(cc_content: Union[Thread, Comment], context: Dict) -> Se "abuse_flagged": True, "closed": is_thread and has_moderation_privilege, "close_reason_code": is_thread and has_moderation_privilege, - "pinned": is_thread and has_moderation_privilege, + "pinned": is_thread and (has_moderation_privilege or is_staff_or_admin), "read": is_thread, } if is_thread: diff --git a/lms/djangoapps/discussion/rest_api/serializers.py b/lms/djangoapps/discussion/rest_api/serializers.py index 5f18281c422c..4ac573e76670 100644 --- a/lms/djangoapps/discussion/rest_api/serializers.py +++ b/lms/djangoapps/discussion/rest_api/serializers.py @@ -85,6 +85,7 @@ def get_context(course, request, thread=None): "cc_requester": cc_requester, "has_moderation_privilege": has_moderation_privilege, "is_global_staff": is_global_staff, + "is_staff_or_admin": requester.id in course_staff_user_ids, } diff --git a/lms/djangoapps/discussion/rest_api/tests/test_permissions.py b/lms/djangoapps/discussion/rest_api/tests/test_permissions.py index 5ad67619ef64..756229150e30 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_permissions.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_permissions.py @@ -27,6 +27,7 @@ def _get_context( allow_anonymous=True, allow_anonymous_to_peers=False, has_moderation_privilege=False, + is_staff_or_admin=False, ): """Return a context suitable for testing the permissions module""" return { @@ -39,6 +40,7 @@ def _get_context( "discussion_division_enabled": is_cohorted, "thread": thread, "has_moderation_privilege": has_moderation_privilege, + "is_staff_or_admin": is_staff_or_admin, } @@ -96,7 +98,7 @@ def test_comment(self, is_thread_author, thread_type, is_privileged): @ddt.ddt class GetEditableFieldsTest(ModuleStoreTestCase): """Tests for get_editable_fields""" - @ddt.data(*itertools.product(*[[True, False] for _ in range(5)])) + @ddt.data(*itertools.product(*[[True, False] for _ in range(6)])) @ddt.unpack def test_thread( self, @@ -105,6 +107,7 @@ def test_thread( allow_anonymous, allow_anonymous_to_peers, has_moderation_privilege, + is_staff_or_admin, ): thread = Thread(user_id="5" if is_author else "6", type="thread") context = _get_context( @@ -113,11 +116,14 @@ def test_thread( allow_anonymous=allow_anonymous, allow_anonymous_to_peers=allow_anonymous_to_peers, has_moderation_privilege=has_moderation_privilege, + is_staff_or_admin=is_staff_or_admin, ) actual = get_editable_fields(thread, context) expected = {"abuse_flagged", "copy_link", "following", "read", "voted"} if has_moderation_privilege: - expected |= {"closed", "pinned", "close_reason_code"} + expected |= {"closed", "close_reason_code"} + if has_moderation_privilege or is_staff_or_admin: + expected |= {"pinned"} if has_moderation_privilege and not is_author: expected |= {"edit_reason_code"} if is_author or has_moderation_privilege: