Skip to content

Commit ca7d63b

Browse files
Merge pull request #242 from edx/COSMO2-853-thread-vote-unvote-instrumentation
feat: add forum telemetry for thread vote and unvote
2 parents 5521789 + f121a4f commit ca7d63b

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

  • lms/djangoapps/discussion/rest_api

lms/djangoapps/discussion/rest_api/views.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,15 @@ def partial_update(self, request, thread_id):
806806
Implements the PATCH method for the instance endpoint as described in
807807
the class docstring.
808808
"""
809-
set_custom_attribute("forum.operation", "thread.update")
809+
voted_value = request.data.get("voted") if "voted" in request.data else None
810+
if voted_value in (True, "true", "True", 1, "1"):
811+
operation = "thread.vote"
812+
elif voted_value in (False, "false", "False", 0, "0"):
813+
operation = "thread.unvote"
814+
else:
815+
operation = "thread.update"
816+
817+
set_custom_attribute("forum.operation", operation)
810818
set_custom_attribute("forum.entity_type", "thread")
811819
set_custom_attribute("forum.entity_id", thread_id)
812820
set_custom_attribute("forum.actor_id", str(getattr(request.user, "id", "")))
@@ -818,9 +826,11 @@ def partial_update(self, request, thread_id):
818826
set_custom_attribute("forum.course_id", str(course_id))
819827

820828
update_fields = [
821-
field for field, value in request.data.items() if value is not None
829+
field
830+
for field, value in request.data.items()
831+
if value is not None and field != "voted"
822832
]
823-
if update_fields:
833+
if update_fields and operation == "thread.update":
824834
set_custom_attribute("forum.update_fields", ",".join(update_fields))
825835

826836
if request.data.get("type"):

0 commit comments

Comments
 (0)