Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
os: [ubuntu-20.04]
python-version: ['3.8']
toxenv: [quality, docs, pii_check, django32, django40]
toxenv: [quality, docs, pii_check, django42]

steps:
- uses: actions/checkout@v3
Expand All @@ -37,7 +37,7 @@ jobs:
run: tox

- name: Run coverage
if: matrix.python-version == '3.8' && matrix.toxenv == 'django32'
if: matrix.python-version == '3.8'
uses: codecov/codecov-action@v4
with:
flags: unittests
Expand Down
2 changes: 2 additions & 0 deletions forum.egg-info/entry_points.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[lms.djangoapp]
forum = forum.apps:ForumConfig
18 changes: 17 additions & 1 deletion forum/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,20 @@ class ForumConfig(AppConfig):
Configuration for the forum Django application.
"""

name = 'forum'
name = "forum"

plugin_app = {
"url_config": {
"lms.djangoapp": {
"namespace": "forum",
"regex": r"^forum",
"relative_path": "urls",
}
},
"settings_config": {
"lms.djangoapp": {
"common": {"relative_path": "settings.common"},
"production": {"relative_path": "settings.production"},
}
},
}
Empty file added forum/settings/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions forum/settings/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Common settings for forum app.
"""


def plugin_settings(settings):
"""
Common settings for forum app
Set these variables in the Tutor Config or lms.yml for local testing
"""
settings.FORUM_PORT = "4567"
10 changes: 10 additions & 0 deletions forum/settings/production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Production settings for forum app.
"""


def plugin_settings(settings):
"""
Production settings for forum app
"""
settings.FORUM_PORT = settings.ENV_TOKENS.get("FORUM_PORT", settings.FORUM_PORT)
9 changes: 5 additions & 4 deletions forum/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""
URLs for forum.
"""
from django.urls import re_path # pylint: disable=unused-import
from django.views.generic import TemplateView # pylint: disable=unused-import

from django.urls import path

from forum.views import ForumProxyAPIView

urlpatterns = [
# TODO: Fill in URL patterns and views here.
# re_path(r'', TemplateView.as_view(template_name="forum/base.html")),
path("/forum_proxy<path:suffix>/", ForumProxyAPIView.as_view(), name="forum_proxy"),
]
143 changes: 143 additions & 0 deletions forum/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
"""Forum Views."""

import logging

import requests
from django.conf import settings
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView

logger = logging.getLogger(__name__)


class ForumProxyAPIView(APIView):
"""
An Proxy API View to Redirect All API requests to forum/cs_comments_service urls.
"""

permission_classes = (AllowAny,)
COMMENTS_SERVICE_URL = f"http://forum:{settings.FORUM_PORT}"

def post(self, request, suffix):
"""
Catches post requests and sends it to forum/cs_comments_service post urls.
"""
request_headers = {
"X-Edx-Api-Key": request.headers.get("X-Edx-Api-Key"),
"Accept-Language": request.headers.get("Accept-Language"),
}
request_data = request.data
url = self.COMMENTS_SERVICE_URL + suffix

"""
Will be removed once start migrating the endpoints.
login on postman before using this curl request.
sample curl request to /:commentable_id/threads POST:
curl --location 'http://local.edly.io:8000/forum/forum_proxy/api/v1/course123/threads/' \
--header 'X-Csrftoken: kjGJPW6nPDGpHd23bBtlPhlQYooctsDDuH9SycovPI7vdWODBAstmbT1HaGWgX7Z' \
--header 'X-Edx-Api-Key: forumapikey' \
--header 'Accept-Language: en' \
--header 'Content-Type: application/json' \
--data '{
"body": "<p>test post request 1</p>",
"anonymous": false,
"anonymous_to_peers": false,
"course_id": "course-v1:Arbisoft+SE002+2024_S2",
"commentable_id": "course",
"thread_type": "discussion",
"title": "Test"
}'
Uncomment below lines of code if want to test above curl request,
when called from edx-platform suffix should have required params
"""
# user_id = request.user.id
# url = url + (f"&user_id={user_id}" if "?" in url else f"?user_id={user_id}")

logger.info(f"Post Request to cs_comments_service url: {url}")
response = requests.post(url, data=request_data, headers=request_headers)
return Response(data=response.json(), status=response.status_code)

def get(self, request, suffix):
"""
Catches get requests and sends it to forum/cs_comments_service get urls.
"""
request_headers = {
"X-Edx-Api-Key": request.headers.get("X-Edx-Api-Key"),
"Accept-Language": request.headers.get("Accept-Language"),
}
request_data = request.data
url = self.COMMENTS_SERVICE_URL + suffix

"""
Will be removed once start migrating the endpoints.
sample curl request to /:commentable_id/threads GET:
curl --location --request GET 'http://local.edly.io:8000/forum/forum_proxy/api/v1/course123/threads/' \
--header 'X-Edx-Api-Key: forumapikey' \
--header 'Accept-Language: en' \
--header 'Content-Type: application/json' \
--data '{
"course_id": "course-v1:Arbisoft+SE002+2024_S2",
"commentable_id": "course123"
}'
Uncomment below lines of code if want to test above curl request,
when called from edx-platform suffix should have required params
"""
# course_id = request_data.get("course_id")
# url = url + (f"&course_id={course_id}" if "?" in url else f"?course_id={course_id}")

logger.info(f"Get Request to cs_comments_service url: {url}")
response = requests.get(url, data=request_data, headers=request_headers)
return Response(data=response.json(), status=response.status_code)

def delete(self, request, suffix):
"""
Catches delete requests and sends it to forum/cs_comments_service delete urls.
"""
request_headers = {
"X-Edx-Api-Key": request.headers.get("X-Edx-Api-Key"),
"Accept-Language": request.headers.get("Accept-Language"),
}
request_data = request.data
url = self.COMMENTS_SERVICE_URL + suffix

"""
Will be removed once start migrating the endpoints.
sample curl request to /:commentable_id/threads DELETE:
curl --location --request DELETE 'http://local.edly.io:8000/forum/forum_proxy/api/v1/course123/threads/' \
--header 'X-Edx-Api-Key: forumapikey' \
--header 'Accept-Language: en' \
--data ''
"""

logger.info(f"Get Request to cs_comments_service url: {url}")
response = requests.delete(url, data=request_data, headers=request_headers)
return Response(data=response.json(), status=response.status_code)

def put(self, request, suffix):
"""
Catches post requests and sends it to forum/cs_comments_service post urls.
"""
request_headers = {
"X-Edx-Api-Key": request.headers.get("X-Edx-Api-Key"),
"Accept-Language": request.headers.get("Accept-Language"),
}
request_data = request.data
url = self.COMMENTS_SERVICE_URL + suffix

"""
Will be removed once start migrating the endpoints.
sample curl request to /threads/:thread_id PUT:
curl --location --request PUT
'http://local.edly.io:8000/forum/forum_proxy/api/v1/threads/66a9d1cca99edf001d4c5f77/' \
--header 'X-Edx-Api-Key: forumapikey' \
--header 'Accept-Language: en' \
--header 'Content-Type: application/json' \
--data '{
"body": "<p>test post request 11</p>"
}'
"""

logger.info(f"Put Request to cs_comments_service url: {url}")
response = requests.put(url, data=request_data, headers=request_headers)
return Response(data=response.json(), status=response.status_code)
6 changes: 4 additions & 2 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ load-plugins = edx_lint.pylint,pylint_django,pylint_celery
[MESSAGES CONTROL]
enable =
blacklisted-name,
line-too-long,

abstract-class-instantiated,
abstract-method,
Expand Down Expand Up @@ -149,7 +148,6 @@ enable =
not-context-manager,
not-in-loop,
pointless-statement,
pointless-string-statement,
raising-bad-type,
raising-non-exception,
redefined-builtin,
Expand Down Expand Up @@ -266,8 +264,10 @@ disable =
fixme,
global-statement,
invalid-name,
line-too-long,
locally-disabled,
no-else-return,
pointless-string-statement,
suppressed-message,
too-few-public-methods,
too-many-ancestors,
Expand All @@ -291,6 +291,8 @@ disable =
django-not-configured,
consider-using-with,
bad-option-value,
missing-timeout,
useless-suppression,

[REPORTS]
output-format = text
Expand Down
2 changes: 2 additions & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
Django # Web application framework


djangorestframework
openedx-atlas
requests
17 changes: 16 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,29 @@
asgiref==3.8.1
# via django
backports-zoneinfo==0.2.1
# via django
# via
# django
# djangorestframework
certifi==2024.7.4
# via requests
charset-normalizer==3.3.2
# via requests
django==4.2.14
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
# -r requirements/base.in
# djangorestframework
djangorestframework==3.15.2
# via -r requirements/base.in
idna==3.7
# via requests
openedx-atlas==0.6.1
# via -r requirements/base.in
requests==2.32.3
# via -r requirements/base.in
sqlparse==0.5.1
# via django
typing-extensions==4.12.2
# via asgiref
urllib3==2.2.2
# via requests
Loading