Skip to content

Commit

Permalink
feat: allow staff and admin to pin posts (#34169)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadadeeltajamul authored Feb 12, 2024
1 parent 5023e69 commit b28db57
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lms/djangoapps/discussion/rest_api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions lms/djangoapps/discussion/rest_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}


Expand Down
10 changes: 8 additions & 2 deletions lms/djangoapps/discussion/rest_api/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}


Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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:
Expand Down

0 comments on commit b28db57

Please sign in to comment.