Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: call python methods from forum v2 #35490

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9126017
feat: call python methods from forum v2
Sep 16, 2024
5ff3c66
feat: migrate some APIs to native python
Sep 18, 2024
896f9a1
feat: pass params to python native APIs
Sep 19, 2024
3a7b24b
feat: code refactor and migrate delete comment API
Sep 20, 2024
bf87423
fix: user tests
Ali-Salman29 Sep 24, 2024
b382053
feat: fix tests for get_user API
Sep 25, 2024
284e7da
feat: use new coursewaffle flag to run old code
Sep 27, 2024
cb58346
Merge branch 'master' into feat/migrate_APIs_from_http_to_python_call
Faraz32123 Sep 27, 2024
740b127
fix: resolve inconsistant python dependencies
Sep 27, 2024
8cdc9fc
fix: fix new failing tests
Sep 27, 2024
1447495
feat: migrate user active_thread api
Oct 2, 2024
634af22
feat: migrate fetch subscription
Ali-Salman29 Oct 2, 2024
e224041
feat: add python native APIs from forum v2
Oct 2, 2024
da19a4c
feat: update thread apis
Ali-Salman29 Oct 2, 2024
d5fadc5
feat: add threads api
Oct 2, 2024
d7d8228
fix: quality checks
Oct 3, 2024
e3d16c8
feat: migrate update_user api
Oct 3, 2024
5482991
feat: retrieve course_id
Ali-Salman29 Oct 3, 2024
efc1d60
fix: course_id issue for course_waffle flag
Oct 3, 2024
f93e079
fix: temp
Ali-Salman29 Oct 3, 2024
0d398a8
chore: code refactor, fix quality checks
Oct 4, 2024
a7053b9
feat: add tests for native APIs
Oct 7, 2024
7457944
feat: add group_id actions tests
Ali-Salman29 Oct 9, 2024
5f135e4
feat: new native APIs tests progress
Oct 9, 2024
40fdb15
Merge branch 'master' into feat/migrate_APIs_from_http_to_python_call
Faraz32123 Oct 9, 2024
b061b26
Merge branch 'master' into feat/migrate_APIs_from_http_to_python_call
Faraz32123 Oct 9, 2024
787d16c
chore: move native API tests to separate PR
Oct 9, 2024
922dfe6
fix: CI checks
Oct 9, 2024
a85d0e6
chore: change the forum branch to master
Oct 9, 2024
2586a8d
fix: older edx-platform tests that uses V1
Oct 10, 2024
5ef8196
Merge branch 'master' into feat/migrate_APIs_from_http_to_python_call
Faraz32123 Oct 10, 2024
5aa42da
feat: pass course_id to native APIs
Oct 10, 2024
c2111ef
Merge branch 'master' into feat/migrate_APIs_from_http_to_python_call
Faraz32123 Oct 11, 2024
3162554
fix: update functions to named arguments
Ali-Salman29 Oct 11, 2024
af8e057
fix: pylint issues
Oct 11, 2024
e956b63
Merge branch 'master' into feat/migrate_APIs_from_http_to_python_call
Faraz32123 Oct 11, 2024
4b26ebc
fix: tests, add mocks for getting course_id APIs
Oct 11, 2024
cc68bd7
Merge branch 'master' into feat/migrate_APIs_from_http_to_python_call
Faraz32123 Oct 11, 2024
4bcf51b
fix: failing unit tests
Oct 13, 2024
40ff7f1
refactor: remove unnecessary try catch
Oct 14, 2024
8dd878d
Merge branch 'master' into feat/migrate_APIs_from_http_to_python_call
Faraz32123 Oct 17, 2024
24a00ff
Merge branch 'master' into feat/migrate_APIs_from_http_to_python_call
Faraz32123 Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from edx_django_utils.monitoring import function_trace
from opaque_keys.edx.keys import CourseKey

from forum import api as forum_api
from openedx.core.djangoapps.django_comment_common.comment_client import settings
from openedx.core.djangoapps.django_comment_common.comment_client.utils import perform_request

Expand All @@ -29,17 +30,8 @@ def get_course_commentable_counts(course_key: CourseKey) -> Dict[str, Dict[str,
}

"""
url = f"{settings.PREFIX}/commentables/{course_key}/counts"
response = perform_request(
'get',
url,
metric_tags=[
f"course_key:{course_key}",
"function:get_course_commentable_counts",
],
metric_action='commentable_stats.retrieve',
)
return response
commentable_stats = forum_api.retrieve_commentables_stats(str(course_key))
Faraz32123 marked this conversation as resolved.
Show resolved Hide resolved
return commentable_stats


@function_trace("get_course_user_stats")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from eventtracking import tracker

from . import models, settings, utils
from forum import api as forum_api

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -193,27 +194,11 @@ def unFlagAbuse(self, user, voteable, removeAll):
voteable._update_from_response(response)

def pin(self, user, thread_id):
url = _url_for_pin_thread(thread_id)
params = {'user_id': user.id}
response = utils.perform_request(
'put',
url,
params,
metric_tags=self._metric_tags,
metric_action='thread.pin'
)
self._update_from_response(response)
thread_data = forum_api.pin_thread(user.id, thread_id)
self._update_from_response(thread_data)
Faraz32123 marked this conversation as resolved.
Show resolved Hide resolved

def un_pin(self, user, thread_id):
url = _url_for_un_pin_thread(thread_id)
params = {'user_id': user.id}
response = utils.perform_request(
'put',
url,
params,
metric_tags=self._metric_tags,
metric_action='thread.unpin'
)
response = forum_api.unpin_thread(user.id, thread_id)
self._update_from_response(response)


Expand All @@ -223,11 +208,3 @@ def _url_for_flag_abuse_thread(thread_id):

def _url_for_unflag_abuse_thread(thread_id):
return f"{settings.PREFIX}/threads/{thread_id}/abuse_unflag"


def _url_for_pin_thread(thread_id):
return f"{settings.PREFIX}/threads/{thread_id}/pin"


def _url_for_un_pin_thread(thread_id):
return f"{settings.PREFIX}/threads/{thread_id}/unpin"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


from . import models, settings, utils
from forum import api as forum_api


class User(models.Model):
Expand Down Expand Up @@ -141,35 +142,13 @@ def subscribed_threads(self, query_params=None):
)

def _retrieve(self, *args, **kwargs):
url = self.url(action='get', params=self.attributes)
retrieve_params = self.default_retrieve_params.copy()
retrieve_params.update(kwargs)
if self.attributes.get('course_id'):
retrieve_params['course_id'] = str(self.course_id)
if self.attributes.get('group_id'):
retrieve_params['group_id'] = self.group_id
try:
response = utils.perform_request(
'get',
url,
retrieve_params,
metric_action='model.retrieve',
metric_tags=self._metric_tags,
)
except utils.CommentClientRequestError as e:
if e.status_code == 404:
# attempt to gracefully recover from a previous failure
# to sync this user to the comments service.
self.save()
response = utils.perform_request(
'get',
url,
retrieve_params,
metric_action='model.retrieve',
metric_tags=self._metric_tags,
)
else:
raise
response = forum_api.retrieve_user(self.attributes["id"], retrieve_params)
self._update_from_response(response)

def retire(self, retired_username):
Expand Down
11 changes: 10 additions & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ django==4.2.15
# enmerkar
# enmerkar-underscore
# event-tracking
# forum
Faraz32123 marked this conversation as resolved.
Show resolved Hide resolved
# help-tokens
# jsonfield
# lti-consumer-xblock
Expand Down Expand Up @@ -382,6 +383,7 @@ djangorestframework==3.14.0
# edx-organizations
# edx-proctoring
# edx-submissions
# forum
# openedx-learning
# ora2
# super-csv
Expand Down Expand Up @@ -549,6 +551,7 @@ elasticsearch==7.13.4
# via
# -c requirements/edx/../common_constraints.txt
# edx-search
# forum
enmerkar==0.7.1
# via enmerkar-underscore
enmerkar-underscore==2.3.1
Expand All @@ -566,6 +569,8 @@ filelock==3.15.4
# via snowflake-connector-python
firebase-admin==6.5.0
# via edx-ace
forum @ git+https://github.com/edly-io/forum.git@feat/migrate_from_http_to_python_call
# via -r requirements/edx/github.in
frozenlist==1.4.1
# via
# aiohttp
Expand Down Expand Up @@ -802,7 +807,9 @@ openai==0.28.1
# -c requirements/edx/../constraints.txt
# edx-enterprise
openedx-atlas==0.6.1
# via -r requirements/edx/kernel.in
# via
# -r requirements/edx/kernel.in
# forum
openedx-calc==3.1.0
# via -r requirements/edx/kernel.in
openedx-django-pyfs==3.6.0
Expand Down Expand Up @@ -956,6 +963,7 @@ pymongo==4.4.0
# -r requirements/edx/paver.txt
# edx-opaque-keys
# event-tracking
# forum
# mongoengine
# openedx-mongodbproxy
pynacl==1.5.0
Expand Down Expand Up @@ -1062,6 +1070,7 @@ requests==2.32.3
# edx-drf-extensions
# edx-enterprise
# edx-rest-api-client
# forum
# geoip2
# google-api-core
# google-cloud-storage
Expand Down
10 changes: 10 additions & 0 deletions requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ django==4.2.15
# enmerkar
# enmerkar-underscore
# event-tracking
# forum
# help-tokens
# jsonfield
# lti-consumer-xblock
Expand Down Expand Up @@ -615,6 +616,7 @@ djangorestframework==3.14.0
# edx-organizations
# edx-proctoring
# edx-submissions
# forum
# openedx-learning
# ora2
# super-csv
Expand Down Expand Up @@ -857,6 +859,7 @@ elasticsearch==7.13.4
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
# edx-search
# forum
enmerkar==0.7.1
# via
# -r requirements/edx/doc.txt
Expand Down Expand Up @@ -905,6 +908,10 @@ firebase-admin==6.5.0
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
# edx-ace
forum @ git+https://github.com/edly-io/forum.git@feat/migrate_from_http_to_python_call
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
freezegun==1.5.1
# via -r requirements/edx/testing.txt
frozenlist==1.4.1
Expand Down Expand Up @@ -1341,6 +1348,7 @@ openedx-atlas==0.6.1
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
# forum
openedx-calc==3.1.0
# via
# -r requirements/edx/doc.txt
Expand Down Expand Up @@ -1637,6 +1645,7 @@ pymongo==4.4.0
# -r requirements/edx/testing.txt
# edx-opaque-keys
# event-tracking
# forum
# mongoengine
# openedx-mongodbproxy
pynacl==1.5.0
Expand Down Expand Up @@ -1829,6 +1838,7 @@ requests==2.32.3
# edx-drf-extensions
# edx-enterprise
# edx-rest-api-client
# forum
# geoip2
# google-api-core
# google-cloud-storage
Expand Down
11 changes: 10 additions & 1 deletion requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ django==4.2.15
# enmerkar
# enmerkar-underscore
# event-tracking
# forum
# help-tokens
# jsonfield
# lti-consumer-xblock
Expand Down Expand Up @@ -452,6 +453,7 @@ djangorestframework==3.14.0
# edx-organizations
# edx-proctoring
# edx-submissions
# forum
# openedx-learning
# ora2
# super-csv
Expand Down Expand Up @@ -633,6 +635,7 @@ elasticsearch==7.13.4
# -c requirements/edx/../common_constraints.txt
# -r requirements/edx/base.txt
# edx-search
# forum
enmerkar==0.7.1
# via
# -r requirements/edx/base.txt
Expand All @@ -658,6 +661,8 @@ firebase-admin==6.5.0
# via
# -r requirements/edx/base.txt
# edx-ace
forum @ git+https://github.com/edly-io/forum.git@feat/migrate_from_http_to_python_call
# via -r requirements/edx/base.txt
frozenlist==1.4.1
# via
# -r requirements/edx/base.txt
Expand Down Expand Up @@ -960,7 +965,9 @@ openai==0.28.1
# -r requirements/edx/base.txt
# edx-enterprise
openedx-atlas==0.6.1
# via -r requirements/edx/base.txt
# via
# -r requirements/edx/base.txt
# forum
openedx-calc==3.1.0
# via -r requirements/edx/base.txt
openedx-django-pyfs==3.6.0
Expand Down Expand Up @@ -1150,6 +1157,7 @@ pymongo==4.4.0
# -r requirements/edx/base.txt
# edx-opaque-keys
# event-tracking
# forum
# mongoengine
# openedx-mongodbproxy
pynacl==1.5.0
Expand Down Expand Up @@ -1271,6 +1279,7 @@ requests==2.32.3
# edx-drf-extensions
# edx-enterprise
# edx-rest-api-client
# forum
# geoip2
# google-api-core
# google-cloud-storage
Expand Down
2 changes: 2 additions & 0 deletions requirements/edx/github.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@
# django42 support PR merged but new release is pending.
# https://github.com/openedx/edx-platform/issues/33431
-e git+https://github.com/anupdhabarde/edx-proctoring-proctortrack.git@31c6c9923a51c903ae83760ecbbac191363aa2a2#egg=edx_proctoring_proctortrack

git+https://github.com/edly-io/forum.git@feat/migrate_from_http_to_python_call#egg=forum
11 changes: 10 additions & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ django==4.2.15
# enmerkar
# enmerkar-underscore
# event-tracking
# forum
# help-tokens
# jsonfield
# lti-consumer-xblock
Expand Down Expand Up @@ -481,6 +482,7 @@ djangorestframework==3.14.0
# edx-organizations
# edx-proctoring
# edx-submissions
# forum
# openedx-learning
# ora2
# super-csv
Expand Down Expand Up @@ -659,6 +661,7 @@ elasticsearch==7.13.4
# -c requirements/edx/../common_constraints.txt
# -r requirements/edx/base.txt
# edx-search
# forum
enmerkar==0.7.1
# via
# -r requirements/edx/base.txt
Expand Down Expand Up @@ -694,6 +697,8 @@ firebase-admin==6.5.0
# via
# -r requirements/edx/base.txt
# edx-ace
forum @ git+https://github.com/edly-io/forum.git@feat/migrate_from_http_to_python_call
# via -r requirements/edx/base.txt
freezegun==1.5.1
# via -r requirements/edx/testing.in
frozenlist==1.4.1
Expand Down Expand Up @@ -1011,7 +1016,9 @@ openai==0.28.1
# -r requirements/edx/base.txt
# edx-enterprise
openedx-atlas==0.6.1
# via -r requirements/edx/base.txt
# via
# -r requirements/edx/base.txt
# forum
openedx-calc==3.1.0
# via -r requirements/edx/base.txt
openedx-django-pyfs==3.6.0
Expand Down Expand Up @@ -1235,6 +1242,7 @@ pymongo==4.4.0
# -r requirements/edx/base.txt
# edx-opaque-keys
# event-tracking
# forum
# mongoengine
# openedx-mongodbproxy
pynacl==1.5.0
Expand Down Expand Up @@ -1388,6 +1396,7 @@ requests==2.32.3
# edx-drf-extensions
# edx-enterprise
# edx-rest-api-client
# forum
# geoip2
# google-api-core
# google-cloud-storage
Expand Down
Loading