diff --git a/lms/djangoapps/discussion/django_comment_client/base/tests.py b/lms/djangoapps/discussion/django_comment_client/base/tests.py index bc4e702886..dbfab3a3f2 100644 --- a/lms/djangoapps/discussion/django_comment_client/base/tests.py +++ b/lms/djangoapps/discussion/django_comment_client/base/tests.py @@ -177,8 +177,10 @@ class ThreadActionGroupIdTestCase( self._assert_json_response_contains_group_info(response) def test_flag(self, mock_request): - response = self.call_view("flag_abuse_for_thread", mock_request) - self._assert_json_response_contains_group_info(response) + with mock.patch('openedx.core.djangoapps.django_comment_common.signals.thread_flagged.send') as signal_mock: + response = self.call_view("flag_abuse_for_thread", mock_request) + self._assert_json_response_contains_group_info(response) + self.assertEqual(signal_mock.call_count, 1) response = self.call_view("un_flag_abuse_for_thread", mock_request) self._assert_json_response_contains_group_info(response) @@ -1349,6 +1351,48 @@ class UpdateCommentUnicodeTestCase( assert mock_request.call_args[1]['data']['body'] == text +@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True) +class CommentActionTestCase( + MockRequestSetupMixin, + CohortedTestCase, + GroupIdAssertionMixin +): + def call_view( + self, + view_name, + mock_request, + user=None, + post_params=None, + view_args=None + ): + self._set_mock_request_data( + mock_request, + { + "user_id": str(self.student.id), + "group_id": self.student_cohort.id, + "closed": False, + "type": "thread", + "commentable_id": "non_team_dummy_id", + "body": "test body", + } + ) + request = RequestFactory().post("dummy_url", post_params or {}) + request.user = user or self.student + request.view_name = view_name + + return getattr(views, view_name)( + request, + course_id=str(self.course.id), + comment_id="dummy", + **(view_args or {}) + ) + + def test_flag(self, mock_request): + with mock.patch('openedx.core.djangoapps.django_comment_common.signals.comment_flagged.send') as signal_mock: + self.call_view("flag_abuse_for_comment", mock_request) + self.assertEqual(signal_mock.call_count, 1) + + @disable_signal(views, 'comment_created') class CreateSubCommentUnicodeTestCase( ForumsEnableMixin, diff --git a/lms/djangoapps/discussion/django_comment_client/base/views.py b/lms/djangoapps/discussion/django_comment_client/base/views.py index f81322a238..e3e52a5400 100644 --- a/lms/djangoapps/discussion/django_comment_client/base/views.py +++ b/lms/djangoapps/discussion/django_comment_client/base/views.py @@ -55,10 +55,12 @@ from openedx.core.djangoapps.django_comment_common.signals import ( comment_deleted, comment_edited, comment_endorsed, + comment_flagged, comment_voted, thread_created, thread_deleted, thread_edited, + thread_flagged, thread_followed, thread_unfollowed, thread_voted @@ -900,6 +902,7 @@ def flag_abuse_for_thread(request, course_id, thread_id): thread = cc.Thread.find(thread_id) thread.flagAbuse(user, thread) track_discussion_reported_event(request, course, thread) + thread_flagged.send(sender='flag_abuse_for_thread', user=request.user, post=thread) return JsonResponse(prepare_content(thread.to_dict(), course_key)) @@ -938,6 +941,7 @@ def flag_abuse_for_comment(request, course_id, comment_id): comment = cc.Comment.find(comment_id) comment.flagAbuse(user, comment) track_discussion_reported_event(request, course, comment) + comment_flagged.send(sender='flag_abuse_for_comment', user=request.user, post=comment) return JsonResponse(prepare_content(comment.to_dict(), course_key)) diff --git a/lms/djangoapps/discussion/tasks.py b/lms/djangoapps/discussion/tasks.py index 7c2e68f31d..7799d95bf2 100644 --- a/lms/djangoapps/discussion/tasks.py +++ b/lms/djangoapps/discussion/tasks.py @@ -100,8 +100,7 @@ def send_ace_message_for_reported_content(context): # lint-amnesty, pylint: dis context['course_name'] = modulestore().get_course(context['course_id']).display_name moderators = get_users_with_moderator_roles(context) - context['site'] = Site.objects.get(id=context['site_id'] - ) + context['site'] = Site.objects.get(id=context['site_id']) if not _is_content_still_reported(context): log.info('Reported content is no longer in reported state. Email to moderators will not be sent.') return @@ -225,9 +224,10 @@ def _build_message_context(context): # lint-amnesty, pylint: disable=missing-fu def _build_message_context_for_reported_content(context, moderator): # lint-amnesty, pylint: disable=missing-function-docstring message_context = get_base_template_context(context['site']) message_context.update(context) + use_mfe_url = ENABLE_DISCUSSIONS_MFE.is_enabled(context['course_id']) message_context.update({ - 'post_link': _get_mfe_thread_url(context), + 'post_link': _get_mfe_thread_url(context) if use_mfe_url else _get_thread_url(context, settings.LMS_BASE), 'moderator_email': moderator.email, }) return message_context @@ -242,9 +242,11 @@ def _get_mfe_thread_url(context): return urljoin(forum_url, mfe_post_link) -def _get_thread_url(context): # lint-amnesty, pylint: disable=missing-function-docstring +def _get_thread_url(context, domain_url=None): # lint-amnesty, pylint: disable=missing-function-docstring scheme = 'https' if settings.HTTPS == 'on' else 'http' - base_url = '{}://{}'.format(scheme, context['site'].domain) + if domain_url is None: + domain_url = context['site'].domain + base_url = '{}://{}'.format(scheme, domain_url) thread_content = { 'type': 'thread', 'course_id': context['course_id'],