From 6204e5bcec350291d750a46b988751074519ffd3 Mon Sep 17 00:00:00 2001 From: Matjaz Gregoric Date: Thu, 24 Dec 2020 08:55:25 +0100 Subject: [PATCH] Fix URL in forum notification post. urljoin('my.domain.com', '/my/path') returns '/my/path'. We have to make sure to use the full base url (starting with http(s)://) and not just the site's domain. --- lms/djangoapps/discussion/tasks.py | 4 +++- lms/djangoapps/discussion/tests/test_tasks.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/discussion/tasks.py b/lms/djangoapps/discussion/tasks.py index 4f5d731445..388db1cdcb 100644 --- a/lms/djangoapps/discussion/tasks.py +++ b/lms/djangoapps/discussion/tasks.py @@ -167,10 +167,12 @@ def _build_message_context(context): # lint-amnesty, pylint: disable=missing-fu 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) thread_content = { 'type': 'thread', 'course_id': context['course_id'], 'commentable_id': context['thread_commentable_id'], 'id': context['thread_id'], } - return urljoin(context['site'].domain, permalink(thread_content)) + return urljoin(base_url, permalink(thread_content)) diff --git a/lms/djangoapps/discussion/tests/test_tasks.py b/lms/djangoapps/discussion/tests/test_tasks.py index 7d54d177ad..3a6c10fa7a 100644 --- a/lms/djangoapps/discussion/tests/test_tasks.py +++ b/lms/djangoapps/discussion/tests/test_tasks.py @@ -212,7 +212,7 @@ class TaskTestCase(ModuleStoreTestCase): # lint-amnesty, pylint: disable=missin 'thread_title': 'thread-title', 'thread_username': self.thread_author.username, 'thread_commentable_id': self.thread['commentable_id'], - 'post_link': self.mock_permalink.return_value, + 'post_link': 'https://{}{}'.format(site.domain, self.mock_permalink.return_value), 'site': site, 'site_id': site.id })