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

perf: add palm support DS-703 #254

Merged
merged 12 commits into from
Nov 30, 2023
4 changes: 2 additions & 2 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
default_prerelease_bump: false
dry_run: true
- name: Set up Python 3.8
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Create bumpversion
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Commit bumpversion
id: bumpversion
if: steps.tag_version.outputs.new_version
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: ${{ github.ref }}
commit_message: "docs(bumpversion): ${{ steps.tag_version.outputs.previous_tag }} → ${{ steps.tag_version.outputs.new_version }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr_issue_assignment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 'Auto-assign PR-Issue'
uses: pozil/auto-assign-issue@v1.5.0
uses: pozil/auto-assign-issue@v1.13.0
with:
repo-token: ${{ secrets.DEDALO_PAT }}
teams: django-plugins-teco
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
Expand All @@ -34,7 +34,7 @@ jobs:
run: |
python -m build --sdist --wheel --outdir dist/ .
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
uses: pypa/gh-action-pypi-publish@v1.8.10
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
strategy:
max-parallel: 2
matrix:
python-version: ["3.8", "3.10"]
python-version: ["3.8"]
django: ["32"]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cache dependency
uses: actions/cache@v3
Expand All @@ -25,7 +25,7 @@ jobs:
restore-keys: |
${{ runner.os }}-pip-
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand Down
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ ignore = migrations,CVS
[MESSAGES CONTROL]
disable=
unused-argument,
no-self-use,
too-few-public-methods,
fixme,
line-too-long,
Expand Down
102 changes: 17 additions & 85 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,26 @@ endpoints in order to extend the functionality of the `edx-platform`_ and avoid
API endpoints includes bulk creation of pre-activated users (for example, skip sending an activation email), enrollments
and pre-enrollment operations.

Usage
=====
Installation
============

Open edX releases before juniper
--------------------------------
#. Add this plugin in your Tutor ``config.yml`` in the ``OPENEDX_EXTRA_PIP_REQUIREMENTS`` variable.
#. Save your configuration with ``tutor config save``.
#. Build your open edx image with ``tutor images build openedx``.
#. Launch your platform with ``tutor local launch``.

#. Create the oauth client at http://localhost:18000/admin/oauth2/client/add/, copy the client-id and client-secret.
**Note:** To use all the features, you need to have `the tutor-forum plugin <https://github.com/overhangio/tutor-forum>`_ and `the eox-tenant plugin <https://github.com/eduNEXT/eox-tenant>`_.

#. Generate an auth-token using that client-id and client-secret:
Features
=========
- Support redirections with middlewares.
- Add pipelines to be used with ``openedx-filters``.
- Add a group of APIs.

.. code-block:: bash
.. image:: docs/_images/eox-core-apis.png
:alt: Eox-core APIs

$ curl -X POST -d "client_id=<YOUR_CLIENT_ID>&client_secret=<YOUR_CLIENT_SECRET> &grant_type=client_credentials" http://localhost:18000/oauth2/access_token/

#. Use the token to call the API as you need:

* User creation API example

.. code-block:: bash

curl -X POST http://localhost:18000/eox-core/api/v1/user/ \
-H "Authorization: Bearer <YOUR_AUTH_TOKEN>" \
-H "Accept: application/json" \
-H "Content\-Type: application/json" \
--data '{"username": "jsmith", "email": "jhon@example.com", "password": "qwerty123", "fullname": "Jhon Smith"}'

* Enroll api example

.. code-block:: bash

curl -X POST http://localhost:18000/eox-core/api/v1/enrollment/ \
-H "Authorization: Bearer <YOUR_AUTH_TOKEN>" \
-H "Accept: application/json" \
-H "Content\-Type: application/json" \
--data '{"course_id": "course-v1:edX+DemoX+Demo_Course", "email": "edx@example.com", "mode": "audit", "force": 1}'


Open edX releases after juniper
-------------------------------

Instead of step 1, follow:

#. Create a Django Oauth Toolkit Application at http://localhost:18000/admin/oauth2_provider/application/add/,
copy the client-id and client-secret. Then follow 2 and 3.


Installation on Open edX Devstack
=================================

* Install either the Ironwood or Juniper version of the `Open edX devstack`_

* Clone the git repo:

.. code-block:: bash

cd ~/Documents/eoxstack/src/ # Assuming that devstack is in ~/Documents/eoxstack/devstack/
sudo mkdir edxapp
cd edxapp
git clone git@github.com:eduNEXT/eox-core.git

- Install plugin from your server (in this case the devstack docker lms shell):

.. code-block:: bash

cd ~/Documents/eoxstack/devstack # Change for your devstack path (if you are using devstack)
make lms-shell # Enter the devstack machine (or server where lms process lives)
cd /edx/src/edxapp/eox-core
pip install -e .
You can find more information in `Help for devs doc <https://github.com/eduNEXT/eox-core/blob/master/docs/help_for_devs/0001-include-test-cases-files.rst>`_.

Compatibility Notes
--------------------
Expand All @@ -98,6 +50,8 @@ Compatibility Notes
+------------------+--------------+
| Olive | >= 8.0 |
+------------------+--------------+
| Palm | >= 9.0 |
+------------------+--------------+

**NOTE**: The Maple version does not support Django 2.2 but it does support Django 3.2 as of eox-core 7.0.

Expand Down Expand Up @@ -182,28 +136,6 @@ The plugin offers some integrations listed below:
profiles_sample_rate: 0.5
another_client_parameter: 'value'



EOX core migration notes
========================

**Migrating to version 2.0.0**

From version **2.0.0**, middlewares **RedirectionsMiddleware** and **PathRedirectionMiddleware** are now included in
this plugin. These middlewares were moved from the **`eox-tenant`_** plugin.

if you installed **eox-core** alongside **eox-tenant** plugin, follow the steps below:

- Upgrade eox-tenant to version **1.0.0** (previous releases are not compatible with eox-core 2.0.0)
- Run the plugin migrations as indicated below:

.. code-block:: bash

$ python manage.py lms migrate eox_tenant --settings=<your app settings>
$ python manage.py lms migrate eox_core --fake-initial --settings=<your app settings>

In case eox-tenant is not installed on the platform, just run the eox-core migrations.


Auditing Django views
=====================
Expand Down
Binary file added docs/_images/eox-core-apis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion eox_core/edxapp_wrapper/backends/enrollment_l_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def _create_or_update_enrollment(username, course_id, mode, is_active, try_updat
if try_update:
enrollment = api._data_api().update_course_enrollment(username, course_id, mode, is_active)
else:
raise Exception(repr(err) + ", use force to update the existing enrollment") from err
raise APIException(repr(err) + ", use force to update the existing enrollment") from err
return enrollment


Expand Down
2 changes: 1 addition & 1 deletion eox_core/edxapp_wrapper/backends/enrollment_o_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def _create_or_update_enrollment(username, course_id, mode, is_active, try_updat
if try_update:
enrollment = api._data_api().update_course_enrollment(username, course_id, mode, is_active)
else:
raise Exception(repr(err) + ", use force to update the existing enrollment") from err
raise Exception(repr(err) + ", use force to update the existing enrollment") from err # pylint: disable=broad-exception-raised
return enrollment


Expand Down
8 changes: 1 addition & 7 deletions eox_core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@
from django.urls import reverse
from django.utils.deprecation import MiddlewareMixin
from requests.exceptions import HTTPError
from social_core.exceptions import AuthAlreadyAssociated, AuthFailed, AuthUnreachableProvider

from eox_core.edxapp_wrapper.configuration_helpers import get_configuration_helper
from eox_core.edxapp_wrapper.third_party_auth import get_tpa_exception_middleware
from eox_core.models import Redirection
from eox_core.utils import cache, fasthash

try:
from social_core.exceptions import AuthAlreadyAssociated, AuthFailed, AuthUnreachableProvider
except ImportError:
AuthUnreachableProvider = Exception
AuthAlreadyAssociated = Exception
AuthFailed = Exception

try:
from eox_tenant.pipeline import EoxTenantAuthException
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion eox_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Redirection(models.Model):
scheme = models.CharField(max_length=5, choices=SCHEME, default=HTTP)
status = models.IntegerField(choices=STATUS, default=301)

class Meta: # pylint: disable=no-init
class Meta:
"""
Model meta class.
"""
Expand Down
7 changes: 1 addition & 6 deletions eox_core/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from crum import get_current_request
from django.db.models.signals import post_save
from social_core.exceptions import AuthFailed, NotAllowedToDisconnect

from eox_core.edxapp_wrapper.users import (
generate_password,
Expand All @@ -14,12 +15,6 @@
)
from eox_core.logging import logging_pipeline_step

try:
from social_core.exceptions import AuthFailed, NotAllowedToDisconnect
except ImportError:
AuthFailed = object
NotAllowedToDisconnect = object

UserSignupSource = get_user_signup_source() # pylint: disable=invalid-name
LOG = logging.getLogger(__name__)

Expand Down
13 changes: 3 additions & 10 deletions eox_core/social_tpa_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,18 @@

from django.conf import settings
from django.contrib.auth import get_user_model
from social_core.backends.open_id_connect import OpenIdConnectAuth
from social_core.exceptions import AuthMissingParameter

from eox_core.edxapp_wrapper.configuration_helpers import get_configuration_helper

try:
from social_core.backends.open_id_connect import OpenIdConnectAuth
except ImportError:
OpenIdConnectAuth = object
try:
from social_core.exceptions import AuthMissingParameter
except ImportError:
AuthMissingParameter = Exception

configuration_helper = get_configuration_helper() # pylint: disable=invalid-name

LOG = logging.getLogger(__name__)
User = get_user_model() # pylint: disable=invalid-name


class ConfigurableOpenIdConnectAuth(OpenIdConnectAuth):
class ConfigurableOpenIdConnectAuth(OpenIdConnectAuth): # pylint: disable=abstract-method
"""
Generic backend that can be configured via the site settings
"""
Expand Down
Loading