diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/models.py b/openedx/core/djangoapps/django_comment_common/comment_client/models.py index 9276b5707b3..e2586e657d4 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/models.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/models.py @@ -3,6 +3,8 @@ import logging +from opaque_keys.edx.keys import CourseKey + from .utils import CommentClientRequestError, extract, perform_request from forum import api as forum_api from lms.djangoapps.discussion.toggles import is_forum_v2_enabled @@ -72,7 +74,9 @@ def retrieve(self, *args, **kwargs): def _retrieve(self, *args, **kwargs): response = None - if is_forum_v2_enabled(self.attributes.get("course_id")): + if course_id := self.attributes.get("course_id"): + course_id = CourseKey.from_string(course_id) + if is_forum_v2_enabled(course_id): if self.type == "comment": response = forum_api.get_parent_comment(self.attributes["id"]) if response is None: @@ -168,7 +172,9 @@ def save(self, params=None): def delete(self): response = None - if is_forum_v2_enabled(self.attributes.get("course_id")): + if course_id := self.attributes.get("course_id"): + course_id = CourseKey.from_string(course_id) + if is_forum_v2_enabled(course_id): if self.type == "comment": response = forum_api.delete_comment(self.attributes["id"]) if response is None: @@ -210,7 +216,9 @@ def handle_update(self, params=None): if params: request_params.update(params) response = None - if is_forum_v2_enabled(request_params.get("course_id")): + if course_id := self.attributes.get("course_id"): + course_id = CourseKey.from_string(course_id) + if is_forum_v2_enabled(course_id): if self.type == "comment": response = self.handle_update_comment(request_params) if response is None: @@ -263,7 +271,9 @@ def perform_http_post_request(self): def handle_create(self): response = None - if is_forum_v2_enabled(self.attributes.get("course_id")): + if course_id := self.attributes.get("course_id"): + course_id = CourseKey.from_string(course_id) + if is_forum_v2_enabled(course_id): if self.type == "comment": response = self.handle_create_comment() if response is None: 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 bc0362e505e..9f43c197126 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/user.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/user.py @@ -1,9 +1,11 @@ # pylint: disable=missing-docstring,protected-access """ User model wrapper for comment service""" +from opaque_keys.edx.keys import CourseKey from . import models, settings, utils from forum import api as forum_api +from forum.utils import str_to_bool from lms.djangoapps.discussion.toggles import is_forum_v2_enabled @@ -107,14 +109,28 @@ def active_threads(self, query_params=None): url = _url_for_user_active_threads(self.id) params = {'course_id': str(self.course_id)} params.update(query_params) - response = utils.perform_request( - 'get', - url, - params, - metric_action='user.active_threads', - metric_tags=self._metric_tags, - paged_results=True, - ) + if user_id := params.get("user_id"): + params["user_id"] = str(user_id) + if page := params.get("page"): + params["page"] = int(page) + if per_page := params.get("per_page"): + params["per_page"] = int(per_page) + if count_flagged := params.get("count_flagged", False): + params["count_flagged"] = str_to_bool(count_flagged) + + if course_id := self.attributes.get("course_id"): + course_id = CourseKey.from_string(course_id) + if is_forum_v2_enabled(course_id): + response = forum_api.get_user_active_threads(**params) + else: + response = utils.perform_request( + 'get', + url, + params, + metric_action='user.active_threads', + metric_tags=self._metric_tags, + paged_results=True, + ) return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1) def subscribed_threads(self, query_params=None):