fix: allow discussion moderators to unreport their content (#30938)

Co-authored-by: SaadYousaf <saadyousaf@A006-00314.local>
This commit is contained in:
Saad Yousaf
2022-09-05 18:39:46 +05:00
committed by GitHub
parent 22b378e605
commit fb716a76d9
3 changed files with 21 additions and 14 deletions

View File

@@ -23,7 +23,6 @@ from rest_framework.exceptions import PermissionDenied
from rest_framework.response import Response
from rest_framework.request import Request
from lms.djangoapps.discussion.views import is_privileged_user
from xmodule.course_module import CourseBlock
from xmodule.modulestore.django import modulestore
from xmodule.tabs import CourseTabList
@@ -34,6 +33,7 @@ from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
from lms.djangoapps.discussion.toggles import ENABLE_LEARNERS_TAB_IN_DISCUSSIONS_MFE, \
ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE
from lms.djangoapps.discussion.toggles_utils import reported_content_email_notification_enabled
from lms.djangoapps.discussion.views import is_user_moderator
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, DiscussionTopicLink, Provider
from openedx.core.djangoapps.discussions.utils import get_accessible_discussion_xblocks
from openedx.core.djangoapps.django_comment_common import comment_client
@@ -1190,8 +1190,7 @@ def _handle_abuse_flagged_field(form_value, user, cc_content):
else:
comment_flagged.send(sender='flag_abuse_for_comment', user=user, post=cc_content)
else:
remove_all = bool(user.id != cc_content["user_id"] and is_privileged_user(course_key,
User.objects.get(id=user.id)))
remove_all = bool(is_user_moderator(course_key, User.objects.get(id=user.id)))
cc_content.unFlagAbuse(user, cc_content, remove_all)

View File

@@ -2826,7 +2826,7 @@ class UpdateThreadTest(
@ddt.data(
(False, True),
(True, False),
(True, True),
)
@ddt.unpack
def test_thread_un_abuse_flag_for_moderator_role(self, is_author, remove_all):
@@ -2837,10 +2837,6 @@ class UpdateThreadTest(
pass the "all" flag to the api. This will indicate
to the api to clear all abuse_flaggers, and mark the
thread as unreported.
If moderator is author of a thread, we want to restrict
the usage of the remove_all flag, so it cant be used
to remove all abuse_flaggers from a moderator post
by the moderator itself.
"""
_assign_role_to_user(user=self.user, course_id=self.course.id, role=FORUM_ROLE_ADMINISTRATOR)
self.register_get_user_response(self.user)
@@ -3311,7 +3307,7 @@ class UpdateCommentTest(
@ddt.data(
(False, True),
(True, False),
(True, True),
)
@ddt.unpack
def test_comment_un_abuse_flag_for_moderator_role(self, is_author, remove_all):
@@ -3322,10 +3318,6 @@ class UpdateCommentTest(
pass the "all" flag to the api. This will indicate
to the api to clear all abuse_flaggers, and mark the
comment as unreported.
If moderator is author of a comment, we want to restrict
the usage of the remove_all flag, so it cant be used
to remove all abuse_flaggers from a moderator post
by the moderator itself.
"""
_assign_role_to_user(user=self.user, course_id=self.course.id, role=FORUM_ROLE_ADMINISTRATOR)
self.register_get_user_response(self.user)

View File

@@ -829,7 +829,8 @@ def is_course_staff(course_key: CourseKey, user: User):
def is_privileged_user(course_key: CourseKey, user: User):
"""
Returns True if user has one of following course role
Administrator, Moderator, Group Moderator, Community TA
Administrator, Moderator, Group Moderator, Community TA,
Global Staff, Course Instructor or Course Staff.
"""
forum_roles = [
FORUM_ROLE_COMMUNITY_TA,
@@ -841,6 +842,21 @@ def is_privileged_user(course_key: CourseKey, user: User):
return GlobalStaff().has_user(user) or is_course_staff(course_key, user) or has_course_role
def is_user_moderator(course_key: CourseKey, user: User):
"""
Returns True if user has one of following course role
Administrator, Moderator, Group Moderator, Community TA.
"""
forum_roles = [
FORUM_ROLE_COMMUNITY_TA,
FORUM_ROLE_GROUP_MODERATOR,
FORUM_ROLE_MODERATOR,
FORUM_ROLE_ADMINISTRATOR
]
has_course_role = Role.user_has_role_for_course(user, course_key, forum_roles)
return has_course_role
class DiscussionBoardFragmentView(EdxFragmentView):
"""
Component implementation of the discussion board.