Skip to content

Commit d85c7e6

Browse files
authored
feat: add EnterpriseEnrollmentViewProcessor pipeline step for CourseEnrollmentStarted filter
1 parent a5790ca commit d85c7e6

12 files changed

Lines changed: 367 additions & 9 deletions

File tree

CHANGELOG.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Unreleased
1717
----------
1818
* nothing unreleased
1919

20+
[8.1.3] - 2026-06-23
21+
---------------------
22+
* feat: add EnterpriseEnrollmentViewProcessor pipeline step for CourseEnrollmentViewStarted filter (ENT-11570)
23+
2024
[8.1.2] - 2026-06-23
2125
---------------------
2226
* fix: change enable_credit_and_industry_pathways default to true
@@ -45,7 +49,6 @@ Unreleased
4549
---------------------
4650
* feat: remove enterprise_invite_admins_enabled feature flag and related conditional behavior (ENT-11269)
4751

48-
4952
[8.0.15] - 2026-05-15
5053
---------------------
5154
* feat: add GradeEventContextEnricher pipeline step for grade analytics (ENT-11563)

enterprise/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Your project description goes here.
33
"""
44

5-
__version__ = "8.1.2"
5+
__version__ = "8.1.3"

enterprise/api_client/xpert_ai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def chat_completion(prompt, role):
2828
}
2929

3030
body = {
31-
'messages': [{'role': role, 'content': prompt},],
31+
'messages': [{'role': role, 'content': prompt}],
3232
'client_id': settings.ENTERPRISE_ANALYSIS_CLIENT_ID,
3333
'system_message': settings.ENTERPRISE_ANALYSIS_SYSTEM_PROMPT
3434
}

enterprise/filters/enrollment.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"""
2+
Pipeline steps for the course enrollment filter.
3+
"""
4+
import logging
5+
from typing import Any
6+
from requests.exceptions import HTTPError
7+
from crum import get_current_request
8+
9+
from openedx_filters.filters import PipelineStep
10+
from openedx_filters.learning.filters import CourseEnrollmentViewStarted
11+
12+
from django.contrib.auth.base_user import AbstractBaseUser
13+
14+
log = logging.getLogger(__name__)
15+
16+
try:
17+
from openedx.features.enterprise_support.api import (
18+
ConsentApiServiceClient, EnterpriseApiException, EnterpriseApiServiceClient
19+
)
20+
except ImportError:
21+
ConsentApiServiceClient = None
22+
EnterpriseApiException = None
23+
EnterpriseApiServiceClient = None
24+
25+
26+
class EnterpriseEnrollmentViewProcessor(PipelineStep):
27+
"""
28+
Enrollment pipeline step: notify enterprise API and record consent.
29+
30+
When an enterprise customer user enrolls in a course, this step calls the enterprise and consent
31+
API clients to post the enrollment and provide consent on behalf of the enterprise customer.
32+
33+
This step is intended to be registered as a pipeline step for the
34+
``org.openedx.learning.course.enrollment.view.started.v1`` filter.
35+
"""
36+
37+
def run_filter( # pylint: disable=arguments-differ
38+
self,
39+
user: AbstractBaseUser,
40+
course_key: Any,
41+
has_api_key_permissions: bool
42+
) -> dict[str, Any]:
43+
"""
44+
Post enterprise enrollment and consent if the user is an enterprise customer user.
45+
"""
46+
log.info(
47+
"EnterpriseEnrollmentViewProcessor running: user_id=%s, course_key=%s, api_permissions=%s",
48+
user.id,
49+
str(course_key),
50+
has_api_key_permissions,
51+
)
52+
53+
request = get_current_request()
54+
linked_enterprise = None
55+
if request and hasattr(request, 'data'):
56+
linked_enterprise = request.data.get("linked_enterprise_customer")
57+
58+
if linked_enterprise is None or not has_api_key_permissions:
59+
return {
60+
'user': user,
61+
'course_key': course_key,
62+
'has_api_key_permissions': has_api_key_permissions
63+
}
64+
65+
username = user.username
66+
course_id = str(course_key)
67+
68+
try:
69+
EnterpriseApiServiceClient().post_enterprise_course_enrollment(username, course_id)
70+
except EnterpriseApiException as exc:
71+
log.exception(
72+
"Failed to post enterprise course enrollment for user %s in course %s.",
73+
username, course_id,
74+
)
75+
raise CourseEnrollmentViewStarted.PreventEnrollment(
76+
f"Failed to post enterprise course enrollment for {username} in {course_id}."
77+
) from exc
78+
79+
try:
80+
ConsentApiServiceClient().provide_consent(
81+
username=username,
82+
course_id=course_id,
83+
enterprise_customer_uuid=str(linked_enterprise),
84+
)
85+
except HTTPError as exc:
86+
log.exception(
87+
"Failed to record enterprise consent for user %s in course %s.",
88+
username, course_id,
89+
)
90+
raise CourseEnrollmentViewStarted.PreventEnrollment(
91+
f"Failed to record enterprise consent for {username} in {course_id}."
92+
) from exc
93+
94+
95+
return {
96+
'user': user,
97+
'course_key': course_key,
98+
'has_api_key_permissions': has_api_key_permissions
99+
}

enterprise/settings/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"fail_silently": False,
2121
"pipeline": ["enterprise.filters.grades.GradeEventContextEnricher"],
2222
},
23+
"org.openedx.learning.course.enrollment.view.started.v1": {
24+
"fail_silently": False,
25+
"pipeline": ["enterprise.filters.enrollment.EnterpriseEnrollmentViewProcessor"],
26+
},
2327
"org.openedx.learning.course.start_date.validation_failed.v1": {
2428
"fail_silently": False,
2529
"pipeline": ["enterprise.filters.courseware.EnterpriseStartDateAccessFailureStep"],

requirements/dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ openedx-events==11.2.0
673673
# -r requirements/doc.txt
674674
# -r requirements/test-master.txt
675675
# -r requirements/test.txt
676-
openedx-filters==3.5.0
676+
openedx-filters==3.6.0
677677
# via
678678
# -r requirements/doc.txt
679679
# -r requirements/test-master.txt

requirements/doc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ openedx-atlas==0.7.0
402402
# via -r requirements/test-master.txt
403403
openedx-events==11.2.0
404404
# via -r requirements/test-master.txt
405-
openedx-filters==3.5.0
405+
openedx-filters==3.6.0
406406
# via -r requirements/test-master.txt
407407
packaging==26.2
408408
# via

requirements/edx-platform-constraints.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ openedx-events==11.2.0
858858
# openedx-authz
859859
# openedx-core
860860
# ora2
861-
openedx-filters==3.5.0
861+
openedx-filters==3.6.0
862862
# via
863863
# -r requirements/edx/kernel.in
864864
# edx-enterprise

requirements/test-master.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ openedx-events==11.2.0
420420
# via
421421
# -c requirements/edx-platform-constraints.txt
422422
# -r requirements/base.in
423-
openedx-filters==3.5.0
423+
openedx-filters==3.6.0
424424
# via
425425
# -c requirements/edx-platform-constraints.txt
426426
# -r requirements/base.in

requirements/test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ openedx-atlas==0.7.0
395395
# via -r requirements/test-master.txt
396396
openedx-events==11.2.0
397397
# via -r requirements/test-master.txt
398-
openedx-filters==3.5.0
398+
openedx-filters==3.6.0
399399
# via -r requirements/test-master.txt
400400
packaging==26.2
401401
# via

0 commit comments

Comments
 (0)