fix: legacy discussion issues (#36433)

Explicitly passed course_id to all views
This commit is contained in:
Ali Salman
2025-03-24 14:26:22 +05:00
committed by GitHub
parent eb03cfbe53
commit 65cf7a9288
3 changed files with 12 additions and 12 deletions

View File

@@ -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({})

View File

@@ -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,

View File

@@ -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(