Skip to content

Commit

Permalink
feat: add discussion event coverage for legacy experience.
Browse files Browse the repository at this point in the history
  • Loading branch information
SaadYousaf authored and arbrandes committed Dec 8, 2022
1 parent dd68ade commit 1314cdb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lms/djangoapps/discussion/django_comment_client/base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def call_view(
"closed": False,
"type": "thread",
"commentable_id": "non_team_dummy_id",
"body": "test body"
"body": "test body",
}
)
request = RequestFactory().post("dummy_url", post_params or {})
Expand Down Expand Up @@ -412,7 +412,7 @@ def test_create_thread(self, mock_request):
self.create_thread_helper(mock_request)

@ddt.data(
(ModuleStoreEnum.Type.split, 3, 6, 38),
(ModuleStoreEnum.Type.split, 3, 6, 42),
)
@ddt.unpack
@count_queries
Expand Down Expand Up @@ -528,6 +528,7 @@ def test_delete_thread(self, mock_request):
self._set_mock_request_data(mock_request, {
"user_id": str(self.student.id),
"closed": False,
"body": "test body",
})
test_thread_id = "test_thread_id"
request = RequestFactory().post("dummy_url", {"id": test_thread_id})
Expand All @@ -546,6 +547,7 @@ def test_delete_comment(self, mock_request):
self._set_mock_request_data(mock_request, {
"user_id": str(self.student.id),
"closed": False,
"body": "test body",
})
test_comment_id = "test_comment_id"
request = RequestFactory().post("dummy_url", {"id": test_comment_id})
Expand Down Expand Up @@ -1595,7 +1597,8 @@ def test_delete_comment(self, user, comment_author, commentable_id, status_code,
"commentable_id": commentable_id,
"user_id": str(comment_author.id),
"username": comment_author.username,
"course_id": str(self.course.id)
"course_id": str(self.course.id),
"body": "test body",
})

response = self.client.post(
Expand Down
17 changes: 14 additions & 3 deletions lms/djangoapps/discussion/django_comment_client/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,11 @@ def update_thread(request, course_id, thread_id):
user = request.user
# The following checks should avoid issues we've seen during deploys, where end users are hitting an updated server
# while their browser still has the old client code. This will avoid erasing present values in those cases.
course = get_course_with_access(user, 'load', course_key)
if "thread_type" in request.POST:
thread.thread_type = request.POST["thread_type"]
if "commentable_id" in request.POST:
commentable_id = request.POST["commentable_id"]
course = get_course_with_access(user, 'load', course_key)
if thread_context == "course" and not discussion_category_id_access(course, user, commentable_id):
return JsonError(_("Topic doesn't exist"))
else:
Expand All @@ -538,6 +538,7 @@ def update_thread(request, course_id, thread_id):

thread_edited.send(sender=None, user=user, post=thread)

track_thread_edited_event(request, course, thread, None)
if request.is_ajax():
return ajax_content_response(request, course_key, thread.to_dict())
else:
Expand Down Expand Up @@ -616,9 +617,12 @@ def delete_thread(request, course_id, thread_id):
this is ajax only
"""
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_deleted.send(sender=None, user=request.user, post=thread)

track_thread_deleted_event(request, course, thread)
return JsonResponse(prepare_content(thread.to_dict(), course_key))


Expand All @@ -631,6 +635,7 @@ def update_comment(request, course_id, comment_id):
handles static and ajax submissions
"""
course_key = CourseKey.from_string(course_id)
course = get_course_with_access(request.user, 'load', course_key)
comment = cc.Comment.find(comment_id)
if 'body' not in request.POST or not request.POST['body'].strip():
return JsonError(_("Body can't be empty"))
Expand All @@ -639,6 +644,7 @@ def update_comment(request, course_id, comment_id):

comment_edited.send(sender=None, user=request.user, post=comment)

track_comment_edited_event(request, course, comment, None)
if request.is_ajax():
return ajax_content_response(request, course_key, comment.to_dict())
else:
Expand Down Expand Up @@ -672,10 +678,13 @@ def openclose_thread(request, course_id, thread_id):
ajax only
"""
course_key = CourseKey.from_string(course_id)
course = get_course_with_access(request.user, 'load', course_key)
thread = cc.Thread.find(thread_id)
thread.closed = request.POST.get('closed', 'false').lower() == 'true'
close_thread = request.POST.get('closed', 'false').lower() == 'true'
thread.closed = close_thread
thread.save()

track_thread_lock_unlock_event(request, course, thread, None, close_thread)
return JsonResponse({
'content': prepare_content(thread.to_dict(), course_key),
'ability': get_ability(course_key, thread.to_dict(), request.user),
Expand Down Expand Up @@ -704,9 +713,11 @@ def delete_comment(request, course_id, comment_id):
ajax only
"""
course_key = CourseKey.from_string(course_id)
course = get_course_with_access(request.user, 'load', course_key)
comment = cc.Comment.find(comment_id)
comment.delete()
comment_deleted.send(sender=None, user=request.user, post=comment)
track_comment_deleted_event(request, course, comment)
return JsonResponse(prepare_content(comment.to_dict(), course_key))


Expand Down Expand Up @@ -828,7 +839,7 @@ def flag_abuse_for_comment(request, course_id, comment_id):
course = get_course_by_id(course_key)
comment = cc.Comment.find(comment_id)
comment.flagAbuse(user, comment)
track_discussion_unreported_event(request, course, comment)
track_discussion_reported_event(request, course, comment)
return JsonResponse(prepare_content(comment.to_dict(), course_key))


Expand Down

0 comments on commit 1314cdb

Please sign in to comment.