Skip to content

Commit

Permalink
fix: fix links in reported content email to point to new MFE
Browse files Browse the repository at this point in the history
  • Loading branch information
SaadYousaf authored and saadyousafarbi committed Jun 24, 2022
1 parent 6ae7681 commit 20de3c7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
29 changes: 16 additions & 13 deletions lms/djangoapps/discussion/rest_api/api.py
Expand Up @@ -28,7 +28,8 @@
from lms.djangoapps.course_blocks.api import get_course_blocks
from lms.djangoapps.courseware.courses import get_course_with_access
from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
from lms.djangoapps.discussion.toggles import ENABLE_LEARNERS_TAB_IN_DISCUSSIONS_MFE
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 openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, DiscussionTopicLink, Provider
from openedx.core.djangoapps.discussions.utils import get_accessible_discussion_xblocks
Expand Down Expand Up @@ -188,9 +189,9 @@ def _get_thread_and_context(request, thread_id, retrieve_kwargs=None):

course_discussion_settings = CourseDiscussionSettings.get(course_key)
if (
not context["is_requester_privileged"] and
cc_thread["group_id"] and
is_commentable_divided(course.id, cc_thread["commentable_id"], course_discussion_settings)
not context["is_requester_privileged"] and
cc_thread["group_id"] and
is_commentable_divided(course.id, cc_thread["commentable_id"], course_discussion_settings)
):
requester_group_id = get_group_id_for_user(request.user, course_discussion_settings)
if requester_group_id is not None and cc_thread["group_id"] != requester_group_id:
Expand Down Expand Up @@ -608,9 +609,9 @@ def _get_users(discussion_entity_type, discussion_entity, username_profile_dict)
users[discussion_entity['author']] = _user_profile(username_profile_dict[discussion_entity['author']])

if (
discussion_entity_type == DiscussionEntity.comment
and discussion_entity['endorsed']
and discussion_entity['endorsed_by']
discussion_entity_type == DiscussionEntity.comment
and discussion_entity['endorsed']
and discussion_entity['endorsed_by']
):
users[discussion_entity['endorsed_by']] = _user_profile(username_profile_dict[discussion_entity['endorsed_by']])
return users
Expand Down Expand Up @@ -683,9 +684,9 @@ def _serialize_discussion_entities(request, context, discussion_entities, reques
if serialized_entity['author'] and serialized_entity['author'] not in usernames:
usernames.append(serialized_entity['author'])
if (
'endorsed' in serialized_entity and serialized_entity['endorsed'] and
'endorsed_by' in serialized_entity and
serialized_entity['endorsed_by'] and serialized_entity['endorsed_by'] not in usernames
'endorsed' in serialized_entity and serialized_entity['endorsed'] and
'endorsed_by' in serialized_entity and
serialized_entity['endorsed_by'] and serialized_entity['endorsed_by'] not in usernames
):
usernames.append(serialized_entity['endorsed_by'])

Expand Down Expand Up @@ -1155,9 +1156,11 @@ def _handle_following_field(form_value, user, cc_content):

def _handle_abuse_flagged_field(form_value, user, cc_content):
"""mark or unmark thread/comment as abused"""
course_key = CourseKey.from_string(cc_content.course_id)
if form_value:
cc_content.flagAbuse(user, cc_content)
if reported_content_email_notification_enabled(CourseKey.from_string(cc_content.course_id)):
if ENABLE_DISCUSSIONS_MFE_FOR_EVERYONE.is_enabled(course_key) and reported_content_email_notification_enabled(
course_key):
if cc_content.type == 'thread':
thread_flagged.send(sender='flag_abuse_for_thread', user=user, post=cc_content)
else:
Expand Down Expand Up @@ -1241,8 +1244,8 @@ def create_thread(request, thread_data):
_check_initializable_thread_fields(thread_data, context)
discussion_settings = CourseDiscussionSettings.get(course_key)
if (
"group_id" not in thread_data and
is_commentable_divided(course_key, thread_data.get("topic_id"), discussion_settings)
"group_id" not in thread_data and
is_commentable_divided(course_key, thread_data.get("topic_id"), discussion_settings)
):
thread_data = thread_data.copy()
thread_data["group_id"] = get_group_id_for_user(user, discussion_settings)
Expand Down
16 changes: 15 additions & 1 deletion lms/djangoapps/discussion/tasks.py
Expand Up @@ -11,6 +11,7 @@
from django.conf import settings # lint-amnesty, pylint: disable=unused-import
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.contrib.sites.models import Site
from django.urls import reverse
from edx_ace import ace
from edx_ace.recipient import Recipient
from edx_ace.utils import date
Expand Down Expand Up @@ -218,13 +219,26 @@ 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)

message_context.update({
'post_link': _get_thread_url(context),
'post_link': _get_mfe_thread_url(context),
'moderator_email': moderator.email,
})
return message_context


def _get_mfe_thread_url(context):
"""
Get thread url for new MFE
"""
scheme = 'https' if settings.HTTPS == 'on' else 'http'
forum_url = reverse('forum_form_discussion', args=[context['course_id']])
base_url = f"{scheme}://{context['site'].domain}{forum_url}"
mfe_post_link = f"?discussions_experience=new#posts/{context['thread_id']}"
post_link = urljoin(base_url, mfe_post_link)
return post_link


def _get_thread_url(context): # lint-amnesty, pylint: disable=missing-function-docstring
scheme = 'https' if settings.HTTPS == 'on' else 'http'
base_url = '{}://{}'.format(scheme, context['site'].domain)
Expand Down

0 comments on commit 20de3c7

Please sign in to comment.