feat: allow staff and admin to pin posts (#34169)
This commit is contained in:
committed by
GitHub
parent
5023e6901d
commit
b28db57d88
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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 @@ class GetInitializableFieldsTest(ModuleStoreTestCase):
|
||||
@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 @@ class GetEditableFieldsTest(ModuleStoreTestCase):
|
||||
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 @@ class GetEditableFieldsTest(ModuleStoreTestCase):
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user