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

Merge latest devs on nutmeg to redwood #52

Merged
merged 5 commits into from
Oct 8, 2024
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ clean: ## delete most git-ignored files
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
rm -rf venv +
echo "cleaned"
# rm -rf venv +

virtual_environment: ## create virtual environment
test -d venv || virtualenv venv --python=python3
Expand Down
3 changes: 1 addition & 2 deletions nau_openedx_extensions/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def ready(self):
"""
Method to perform actions after apps registry is ended
"""
from nau_openedx_extensions import signals # pylint: disable=import-outside-toplevel,unused-import # noqa
from nau_openedx_extensions.permissions import \
load_permissions # pylint: disable=import-outside-toplevel,unused-import # noqa

# load_permissions()
72 changes: 72 additions & 0 deletions nau_openedx_extensions/certificates/context_overrides.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""
This file defines overrides of the context render of course certificates using an Open edX Filters pipeline step.
"""

import logging

from openedx_filters import PipelineStep

from nau_openedx_extensions.edxapp_wrapper.cohort import get_cohort

log = logging.getLogger(__name__)


class CertificatesContextCohortOverride(PipelineStep):
"""
Override the certificates render template context with information from the student cohort.
If user has a cohort and that cohort has custom certificate overrides, then override the root context variables
with the cohorted ones.

Example usage:
Add the following configurations to your configuration file:
"OPEN_EDX_FILTERS_CONFIG": {
"org.openedx.learning.certificate.render.started.v1": {
"fail_silently": false,
"pipeline": [
"nau_openedx_extensions.certificates.context_overrides.CertificatesContextCohortOverride"
]
}
}

Configure course on field "Certificate Web/HTML View Overrides" with:
{
"footer_additional_logo": "https://lms.example.com/some_logo.png",
"cohort_overrides": {
"test": {
"footer_additional_logo": "https://lms.example.com/override_logo.png"
}
}
}
"""

def run_filter(self, context, custom_template): # pylint: disable=arguments-differ
"""
The filter logic.
"""
username = context["username"]
course_key = context["course_id"]
if "cohort_overrides" in context:
cohort = get_cohort(username, course_key)
if cohort:
if cohort.name in context["cohort_overrides"]:
cohort_override_dict = context["cohort_overrides"][cohort.name]
context.update(cohort_override_dict)
else:
log.info(
"The user '%s' enrollment on course '%s' doesn't have a cohort "
"certificate context overrides configured for the cohort '%s'.",
username,
course_key,
cohort.name,
)
else:
log.info(
"User '%s' not in a cohort on course '%s'", username, course_key
)
else:
log.info(
"No Certificates context cohort_overrides defined on course '%s'",
course_key,
)

return {"context": context, "custom_template": custom_template}
14 changes: 14 additions & 0 deletions nau_openedx_extensions/edxapp_wrapper/backends/cohort_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Cohort abstraction backend
"""
from common.djangoapps.student.models import get_user_by_username_or_email # pylint: disable=import-error
from openedx.core.djangoapps.course_groups.cohorts import \
get_cohort as edxapp_get_cohort # pylint: disable=import-error


def get_cohort(username, course_key):
"""
Get the Course Cohort for the User that belongs the username if available other case return None.
"""
user = get_user_by_username_or_email(username)
return edxapp_get_cohort(user, course_key, assign=False, use_cached=False)
10 changes: 10 additions & 0 deletions nau_openedx_extensions/edxapp_wrapper/backends/cohort_v1_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Cohort abstraction backend
"""


def get_cohort(username, course_key): # pylint: disable=unused-argument
"""
For tests.
"""
return None
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Real implementation of user id verifications service.
"""
from django.contrib.auth import get_user_model
from lms.djangoapps.verify_student.models import ManualVerification # pylint: disable=import-error


def get_user_id_verifications(user_id, *args, **kwargs):
"""
Read the user's `ManualVerification` from the edx-platform.

Args:
user: The user id to read the Id Verifications.

Returns:
An enumeration of those Id Verifications
"""
user = get_user_model().objects.get(id=user_id)
return ManualVerification.objects.filter(user=user).order_by('-created_at')


def create_user_id_verification(user_id, *args, **kwargs):
"""
Create a new `ManualVerification` on the edx-platform.

Args:
user: The user id that this Id verification should be created.

Returns:
The object created
"""
user = get_user_model().objects.get(id=user_id)
ManualVerification(user=user, name=user.profile.name, *args, **kwargs).save()
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Real implementation of user id verifications service.
"""


def get_user_id_verifications(user_id, *args, **kwargs): # pylint: disable=unused-argument
"""
Read the user's `ManualVerification` from the edx-platform.

Args:
user_id: The user id to read the Id Verifications.

Returns:
An enumeration of those Id Verifications
"""
return []

def create_user_id_verification(user_id, *args, **kwargs): # pylint: disable=unused-argument
"""
Create a new `ManualVerification` on the edx-platform.

Args:
user_id: The user id that this Id verification should be created.

Returns:
The object created
"""
return None
15 changes: 15 additions & 0 deletions nau_openedx_extensions/edxapp_wrapper/cohort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
""" CourseMetadata backend abstraction """

from importlib import import_module

from django.conf import settings


def get_cohort(*args, **kwargs):
"""
Get the Course Cohort for the User that belongs the username if available other case return None.
"""
backend_module = settings.NAU_COHORT_MODULE
backend = import_module(backend_module)

return backend.get_cohort(*args, **kwargs)
29 changes: 29 additions & 0 deletions nau_openedx_extensions/edxapp_wrapper/verify_student.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Student backend abstraction
"""
from __future__ import absolute_import, unicode_literals

from importlib import import_module

from django.conf import settings


def get_user_id_verifications(user_id, *args, **kwargs):
"""
Read the user's `ManualVerification` from the edx-platform.
"""

backend_module = settings.NAU_VERIFY_STUDENT_MODULE
backend = import_module(backend_module)

return backend.get_user_id_verifications(user_id, *args, **kwargs)


def create_user_id_verification(user_id, *args, **kwargs):
"""
Create an user Id Verification `ManualVerification` instance on the edx-platform.
"""
backend_module = settings.NAU_VERIFY_STUDENT_MODULE
backend = import_module(backend_module)

return backend.create_user_id_verification(user_id, *args, **kwargs)
Binary file modified nau_openedx_extensions/locale/en/LC_MESSAGES/django.mo
Binary file not shown.
6 changes: 3 additions & 3 deletions nau_openedx_extensions/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-05-10 14:45+0100\n"
"POT-Creation-Date: 2024-10-02 13:56+0100\n"
"PO-Revision-Date: 2021-02-15 15:56+0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
Expand Down Expand Up @@ -133,11 +133,11 @@ msgid ""
"out in order to obtain a certificate."
msgstr ""

#: nau_openedx_extensions/settings/common.py:86
#: nau_openedx_extensions/settings/common.py:35
msgid "Certificate"
msgstr ""

#: nau_openedx_extensions/settings/common.py:87
#: nau_openedx_extensions/settings/common.py:36
msgid "Certificate of Achievement"
msgstr ""

Expand Down
Binary file modified nau_openedx_extensions/locale/pt_PT/LC_MESSAGES/django.mo
Binary file not shown.
6 changes: 3 additions & 3 deletions nau_openedx_extensions/locale/pt_PT/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-05-10 14:45+0100\n"
"POT-Creation-Date: 2024-10-02 13:56+0100\n"
"PO-Revision-Date: 2021-02-15 15:56+0000\n"
"Last-Translator: Ivo Branco <[email protected]>\n"
"Language: pt_PT\n"
Expand Down Expand Up @@ -142,11 +142,11 @@ msgstr ""
"Este curso encontra-se arquivado e já não permite a realização de "
"atividades para obtenção de certificado."

#: nau_openedx_extensions/settings/common.py:86
#: nau_openedx_extensions/settings/common.py:35
msgid "Certificate"
msgstr "Certificado"

#: nau_openedx_extensions/settings/common.py:87
#: nau_openedx_extensions/settings/common.py:36
msgid "Certificate of Achievement"
msgstr "Certificado de Conclusão"

Expand Down
14 changes: 10 additions & 4 deletions nau_openedx_extensions/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def plugin_settings(settings):
See: https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/plugins/README.rst
"""

# Overwrite the default certificate name
settings.CERT_NAME_SHORT = _("Certificate")
settings.CERT_NAME_LONG = _("Certificate of Achievement")

settings.NAU_CUSTOM_SAML_IDENTITY_PROVIDERS = [
{
"provider_key": "nau_custom_saml_provider",
Expand Down Expand Up @@ -81,7 +85,9 @@ def plugin_settings(settings):
settings.NAU_STUDENT_MODULE = (
"nau_openedx_extensions.edxapp_wrapper.backends.student_l_v1"
)

# Overwrite the default certificate name
settings.CERT_NAME_SHORT = _("Certificate")
settings.CERT_NAME_LONG = _("Certificate of Achievement")
settings.NAU_COHORT_MODULE = (
"nau_openedx_extensions.edxapp_wrapper.backends.cohort_v1"
)
settings.NAU_VERIFY_STUDENT_MODULE = (
"nau_openedx_extensions.edxapp_wrapper.backends.verify_student_v1"
)
7 changes: 7 additions & 0 deletions nau_openedx_extensions/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@ class SettingsClass:
NAU_STUDENT_MODULE = (
"nau_openedx_extensions.edxapp_wrapper.backends.student_l_v1_tests"
)

NAU_COHORT_MODULE = (
"nau_openedx_extensions.edxapp_wrapper.backends.cohort_v1_tests"
)
NAU_VERIFY_STUDENT_MODULE = (
"nau_openedx_extensions.edxapp_wrapper.backends.verify_student_v1_tests"
)
7 changes: 7 additions & 0 deletions nau_openedx_extensions/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
File that contains the definition of all signals and its receivers.
"""

from nau_openedx_extensions.verify_student.id_verification import ( # pylint: disable=unused-import
event_receiver_no_id_verify_for_enrollment_modes,
)
Loading
Loading