From 65cf7a9288b7d3e1050814d19d41aed816e06212 Mon Sep 17 00:00:00 2001 From: Ali Salman <88362079+Ali-Salman29@users.noreply.github.com> Date: Mon, 24 Mar 2025 14:26:22 +0500 Subject: [PATCH] fix: legacy discussion issues (#36433) Explicitly passed course_id to all views --- .../discussion/django_comment_client/base/views.py | 12 ++++++------ .../django_comment_common/comment_client/thread.py | 10 +++++----- .../django_comment_common/comment_client/user.py | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lms/djangoapps/discussion/django_comment_client/base/views.py b/lms/djangoapps/discussion/django_comment_client/base/views.py index 55057060d3..238ef02712 100644 --- a/lms/djangoapps/discussion/django_comment_client/base/views.py +++ b/lms/djangoapps/discussion/django_comment_client/base/views.py @@ -715,7 +715,7 @@ def delete_thread(request, course_id, thread_id): course_key = CourseKey.from_string(course_id) course = get_course_with_access(request.user, 'load', course_key) thread = cc.Thread.find(thread_id) - thread.delete() + thread.delete(course_id=course_id) thread_deleted.send(sender=None, user=request.user, post=thread) track_thread_deleted_event(request, course, thread) @@ -781,7 +781,7 @@ def openclose_thread(request, course_id, thread_id): thread = cc.Thread.find(thread_id) close_thread = request.POST.get('closed', 'false').lower() == 'true' thread.closed = close_thread - thread.save() + thread.save(params={"course_id": course_id}) track_thread_lock_unlock_event(request, course, thread, None, close_thread) return JsonResponse({ @@ -976,7 +976,7 @@ def pin_thread(request, course_id, thread_id): course_key = CourseKey.from_string(course_id) user = cc.User.from_django_user(request.user) thread = cc.Thread.find(thread_id) - thread.pin(user, thread_id) + thread.pin(user, thread_id, course_id) return JsonResponse(prepare_content(thread.to_dict(), course_key)) @@ -992,7 +992,7 @@ def un_pin_thread(request, course_id, thread_id): course_key = CourseKey.from_string(course_id) user = cc.User.from_django_user(request.user) thread = cc.Thread.find(thread_id) - thread.un_pin(user, thread_id) + thread.un_pin(user, thread_id, course_id) return JsonResponse(prepare_content(thread.to_dict(), course_key)) @@ -1021,7 +1021,7 @@ def follow_commentable(request, course_id, commentable_id): # lint-amnesty, pyl """ user = cc.User.from_django_user(request.user) commentable = cc.Commentable.find(commentable_id) - user.follow(commentable) + user.follow(commentable, course_id=course_id) return JsonResponse({}) @@ -1053,7 +1053,7 @@ def unfollow_commentable(request, course_id, commentable_id): # lint-amnesty, p """ user = cc.User.from_django_user(request.user) commentable = cc.Commentable.find(commentable_id) - user.unfollow(commentable) + user.unfollow(commentable, course_id=course_id) return JsonResponse({}) diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/thread.py b/openedx/core/djangoapps/django_comment_common/comment_client/thread.py index 0313d29daa..b5f227f7cc 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/thread.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/thread.py @@ -222,7 +222,7 @@ class Thread(models.Model): url = _url_for_unflag_abuse_thread(voteable.id) else: raise utils.CommentClientRequestError("Can only flag/unflag for threads or comments") - course_key = utils.get_course_key(self.attributes.get("course_id")) + course_key = utils.get_course_key(self.attributes.get("course_id") or course_id) if is_forum_v2_enabled(course_key): response = forum_api.update_thread_flag( thread_id=voteable.id, @@ -246,8 +246,8 @@ class Thread(models.Model): ) voteable._update_from_response(response) - def pin(self, user, thread_id): - course_key = utils.get_course_key(self.attributes.get("course_id")) + def pin(self, user, thread_id, course_id=None): + course_key = utils.get_course_key(self.attributes.get("course_id") or course_id) if is_forum_v2_enabled(course_key): response = forum_api.pin_thread( user_id=user.id, @@ -266,8 +266,8 @@ class Thread(models.Model): ) self._update_from_response(response) - def un_pin(self, user, thread_id): - course_key = utils.get_course_key(self.attributes.get("course_id")) + def un_pin(self, user, thread_id, course_id): + course_key = utils.get_course_key(self.attributes.get("course_id") or course_id) if is_forum_v2_enabled(course_key): response = forum_api.unpin_thread( user_id=user.id, diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/user.py b/openedx/core/djangoapps/django_comment_common/comment_client/user.py index 4fd8bac182..eaac6b4086 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/user.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/user.py @@ -127,7 +127,7 @@ class User(models.Model): url = _url_for_vote_comment(voteable.id) else: raise utils.CommentClientRequestError("Can only vote / unvote for threads or comments") - course_key = utils.get_course_key(self.attributes.get("course_id")) + course_key = utils.get_course_key(self.attributes.get("course_id") or course_id) if is_forum_v2_enabled(course_key): if voteable.type == 'thread': response = forum_api.delete_thread_vote(