openedx-webhooks 22.0.0__tar.gz → 22.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/CHANGELOG.md +18 -0
- {openedx_webhooks-22.0.0/openedx_webhooks.egg-info → openedx_webhooks-22.1.1}/PKG-INFO +18 -1
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/README.md +17 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/__init__.py +1 -1
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/apps.py +6 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/filters.py +28 -27
- openedx_webhooks-22.1.1/openedx_webhooks/lookups.py +124 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/receivers.py +11 -10
- openedx_webhooks-22.1.1/openedx_webhooks/utils.py +195 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1/openedx_webhooks.egg-info}/PKG-INFO +18 -1
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks.egg-info/SOURCES.txt +5 -0
- openedx_webhooks-22.1.1/tests/test_cache_failures.py +32 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/tests/test_contracts.py +7 -1
- openedx_webhooks-22.1.1/tests/test_dashboard_benchmark.py +72 -0
- openedx_webhooks-22.1.1/tests/test_invalidation_failures.py +27 -0
- openedx_webhooks-22.1.1/tests/test_lookups.py +94 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/tests/test_receivers.py +29 -0
- openedx_webhooks-22.0.0/openedx_webhooks/utils.py +0 -124
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/LICENSE.txt +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/MANIFEST.in +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/admin.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/migrations/0001_initial.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/migrations/0002_webfilter.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/migrations/0003_auto_20230607_1246.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/migrations/0004_auto_20230613_1033.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/migrations/0005_alter_webfilter_event.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/migrations/0006_alter_webfilter_event.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/migrations/0007_alter_webfilter_event.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/migrations/0008_verawood.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/migrations/__init__.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/models.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/settings/__init__.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/settings/cms.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/settings/common.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/settings/test.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks/urls.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks.egg-info/dependency_links.txt +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks.egg-info/entry_points.txt +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks.egg-info/not-zip-safe +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks.egg-info/requires.txt +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/openedx_webhooks.egg-info/top_level.txt +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/requirements/base.in +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/requirements/constraints.txt +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/setup.cfg +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/setup.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/tests/test_filters.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/tests/test_migrations.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/tests/test_settings_plugins.py +0 -0
- {openedx_webhooks-22.0.0 → openedx_webhooks-22.1.1}/tests/test_utils.py +0 -0
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## Version 22.1.1 (2026-11-23)
|
|
4
|
+
|
|
5
|
+
- Cache enabled webhook and webfilter configuration lookups per event, including
|
|
6
|
+
empty results, to reduce repeated database queries. Reuse lookups within HTTP
|
|
7
|
+
requests and invalidate the shared cache after configuration saves or deletes.
|
|
8
|
+
Shared entries expire after 24 hours as a fallback.
|
|
9
|
+
|
|
10
|
+
## Version 22.1.0 (2026-10-28)
|
|
11
|
+
|
|
12
|
+
- Register LMS and Studio filter settings during production initialization.
|
|
13
|
+
- Serialize mappings, sequences, Django models, attrs classes, and dataclasses
|
|
14
|
+
without traversing arbitrary object attributes or loading deferred model fields.
|
|
15
|
+
Represent unsupported objects as strings and protect against cycles and deeply
|
|
16
|
+
nested structures.
|
|
17
|
+
- Apply a shared 10,000-node serialization budget to each signal payload,
|
|
18
|
+
preserve event metadata when data is truncated, and reuse the serialized
|
|
19
|
+
payload across configured endpoints.
|
|
20
|
+
|
|
3
21
|
## Version 22.0.0 (2026-10-02)
|
|
4
22
|
|
|
5
23
|
- Target Open edX Verawood: Python 3.12, Django 5.2, openedx-events 11.2.0,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: openedx_webhooks
|
|
3
|
-
Version: 22.
|
|
3
|
+
Version: 22.1.1
|
|
4
4
|
Summary: Webhooks for Open edX
|
|
5
5
|
Home-page: https://github.com/aulasneo/openedx-webhooks
|
|
6
6
|
Author: Aulasneo
|
|
@@ -109,6 +109,23 @@ webhook to define the URLs that will be called after each event is received.
|
|
|
109
109
|
More than one URL can be configured for each event. In that case, all URLs are
|
|
110
110
|
called.
|
|
111
111
|
|
|
112
|
+
### Configuration Cache
|
|
113
|
+
|
|
114
|
+
Enabled webhook and webfilter configurations, including empty results, are
|
|
115
|
+
cached per event in Django's default cache for up to 24 hours. HTTP requests
|
|
116
|
+
also reuse each lookup for the duration of the request. Saving or deleting a
|
|
117
|
+
configuration in Django admin invalidates the shared cache after the database
|
|
118
|
+
transaction commits. An in-progress request may continue using its earlier
|
|
119
|
+
lookup until it finishes.
|
|
120
|
+
|
|
121
|
+
Use a shared default cache across LMS, Studio, and workers for changes to be
|
|
122
|
+
visible across processes immediately. Tutor's standard configuration uses
|
|
123
|
+
Redis for this cache. With a process-local cache, other processes can retain
|
|
124
|
+
old configurations until their entries expire. Database updates that bypass
|
|
125
|
+
Django's save and delete signals also rely on expiry. If cache invalidation
|
|
126
|
+
fails, an old shared entry can remain until it expires after the cache recovers.
|
|
127
|
+
Cache lookup failures fall back to the database.
|
|
128
|
+
|
|
112
129
|
### Configuring Webhooks
|
|
113
130
|
|
|
114
131
|
The `Webhooks` Django admin panel has the following settings:
|
|
@@ -68,6 +68,23 @@ webhook to define the URLs that will be called after each event is received.
|
|
|
68
68
|
More than one URL can be configured for each event. In that case, all URLs are
|
|
69
69
|
called.
|
|
70
70
|
|
|
71
|
+
### Configuration Cache
|
|
72
|
+
|
|
73
|
+
Enabled webhook and webfilter configurations, including empty results, are
|
|
74
|
+
cached per event in Django's default cache for up to 24 hours. HTTP requests
|
|
75
|
+
also reuse each lookup for the duration of the request. Saving or deleting a
|
|
76
|
+
configuration in Django admin invalidates the shared cache after the database
|
|
77
|
+
transaction commits. An in-progress request may continue using its earlier
|
|
78
|
+
lookup until it finishes.
|
|
79
|
+
|
|
80
|
+
Use a shared default cache across LMS, Studio, and workers for changes to be
|
|
81
|
+
visible across processes immediately. Tutor's standard configuration uses
|
|
82
|
+
Redis for this cache. With a process-local cache, other processes can retain
|
|
83
|
+
old configurations until their entries expire. Database updates that bypass
|
|
84
|
+
Django's save and delete signals also rely on expiry. If cache invalidation
|
|
85
|
+
fails, an old shared entry can remain until it expires after the cache recovers.
|
|
86
|
+
Cache lookup failures fall back to the database.
|
|
87
|
+
|
|
71
88
|
### Configuring Webhooks
|
|
72
89
|
|
|
73
90
|
The `Webhooks` Django admin panel has the following settings:
|
|
@@ -91,6 +91,10 @@ class WebhooksConfig(AppConfig):
|
|
|
91
91
|
|
|
92
92
|
name = 'openedx_webhooks'
|
|
93
93
|
|
|
94
|
+
def ready(self):
|
|
95
|
+
"""Register configuration cache invalidation and request lifecycle receivers."""
|
|
96
|
+
from . import lookups # pylint: disable=import-outside-toplevel,unused-import
|
|
97
|
+
|
|
94
98
|
receivers = []
|
|
95
99
|
for signal_app, signal_list in signals.items():
|
|
96
100
|
for signal in signal_list:
|
|
@@ -103,10 +107,12 @@ class WebhooksConfig(AppConfig):
|
|
|
103
107
|
"settings_config": {
|
|
104
108
|
"lms.djangoapp": {
|
|
105
109
|
"common": {"relative_path": "settings.common"},
|
|
110
|
+
"production": {"relative_path": "settings.common"},
|
|
106
111
|
"test": {"relative_path": "settings.test"},
|
|
107
112
|
},
|
|
108
113
|
"cms.djangoapp": {
|
|
109
114
|
"common": {"relative_path": "settings.cms"},
|
|
115
|
+
"production": {"relative_path": "settings.cms"},
|
|
110
116
|
"test": {"relative_path": "settings.cms"},
|
|
111
117
|
},
|
|
112
118
|
},
|
|
@@ -46,6 +46,7 @@ from openedx_filters.learning.filters import (
|
|
|
46
46
|
VerticalBlockRenderCompleted,
|
|
47
47
|
)
|
|
48
48
|
|
|
49
|
+
from .lookups import get_active_endpoints
|
|
49
50
|
from .models import Webfilter
|
|
50
51
|
from .utils import SENSITIVE_FIELDS, object_serializer, redact_sensitive_fields, send
|
|
51
52
|
|
|
@@ -387,7 +388,7 @@ class StudentLoginRequestedWebFilter(PipelineStep):
|
|
|
387
388
|
"""Execute the filter."""
|
|
388
389
|
event = "StudentLoginRequested"
|
|
389
390
|
|
|
390
|
-
webfilters = Webfilter
|
|
391
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
391
392
|
|
|
392
393
|
if webfilters:
|
|
393
394
|
logger.info(f"Webfilter for {event} event for user {user}")
|
|
@@ -499,7 +500,7 @@ class StudentRegistrationRequestedWebFilter(PipelineStep):
|
|
|
499
500
|
def run_filter(self, form_data): # pylint: disable=arguments-differ
|
|
500
501
|
"""Execute the filter."""
|
|
501
502
|
event = "StudentRegistrationRequested"
|
|
502
|
-
webfilters = Webfilter
|
|
503
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
503
504
|
|
|
504
505
|
if webfilters:
|
|
505
506
|
from common.djangoapps.student.models import ( # pylint: disable=import-error,import-outside-toplevel
|
|
@@ -561,7 +562,7 @@ class AccountSettingsRenderStartedWebFilter(PipelineStep):
|
|
|
561
562
|
"""
|
|
562
563
|
event = "AccountSettingsRenderStarted"
|
|
563
564
|
|
|
564
|
-
webfilters = Webfilter
|
|
565
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
565
566
|
|
|
566
567
|
if webfilters:
|
|
567
568
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -683,7 +684,7 @@ class CourseEnrollmentStartedWebFilter(PipelineStep):
|
|
|
683
684
|
"""
|
|
684
685
|
event = "CourseEnrollmentStarted"
|
|
685
686
|
|
|
686
|
-
webfilters = Webfilter
|
|
687
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
687
688
|
|
|
688
689
|
if webfilters:
|
|
689
690
|
logger.info(f"Webfilter for {event} event. User: {user}, course: {course_key}, mode: {mode}.")
|
|
@@ -802,7 +803,7 @@ class CourseUnenrollmentStartedWebFilter(PipelineStep):
|
|
|
802
803
|
"""
|
|
803
804
|
event = "CourseUnenrollmentStarted"
|
|
804
805
|
|
|
805
|
-
webfilters = Webfilter
|
|
806
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
806
807
|
|
|
807
808
|
if webfilters:
|
|
808
809
|
logger.info(f"Webfilter for {event} event. Enrollment: {enrollment}")
|
|
@@ -948,7 +949,7 @@ class CertificateCreationRequestedWebFilter(PipelineStep):
|
|
|
948
949
|
"""
|
|
949
950
|
event = "CertificateCreationRequested"
|
|
950
951
|
|
|
951
|
-
webfilters = Webfilter
|
|
952
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
952
953
|
|
|
953
954
|
if webfilters:
|
|
954
955
|
user = data.get('user')
|
|
@@ -1094,7 +1095,7 @@ class CertificateRenderStartedWebFilter(PipelineStep):
|
|
|
1094
1095
|
"""
|
|
1095
1096
|
event = "CertificateRenderStarted"
|
|
1096
1097
|
|
|
1097
|
-
webfilters = Webfilter
|
|
1098
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
1098
1099
|
|
|
1099
1100
|
if webfilters:
|
|
1100
1101
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -1230,7 +1231,7 @@ class CohortChangeRequestedWebFilter(PipelineStep):
|
|
|
1230
1231
|
"""
|
|
1231
1232
|
event = "CohortChangeRequested"
|
|
1232
1233
|
|
|
1233
|
-
webfilters = Webfilter
|
|
1234
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
1234
1235
|
|
|
1235
1236
|
if webfilters:
|
|
1236
1237
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -1360,7 +1361,7 @@ class CohortAssignmentRequestedWebFilter(PipelineStep):
|
|
|
1360
1361
|
"""
|
|
1361
1362
|
event = "CohortAssignmentRequested"
|
|
1362
1363
|
|
|
1363
|
-
webfilters = Webfilter
|
|
1364
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
1364
1365
|
|
|
1365
1366
|
if webfilters:
|
|
1366
1367
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -1487,7 +1488,7 @@ class CourseAboutRenderStartedWebFilter(PipelineStep):
|
|
|
1487
1488
|
"""
|
|
1488
1489
|
event = "CourseAboutRenderStarted"
|
|
1489
1490
|
|
|
1490
|
-
webfilters = Webfilter
|
|
1491
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
1491
1492
|
|
|
1492
1493
|
if webfilters:
|
|
1493
1494
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -1621,7 +1622,7 @@ class DashboardRenderStartedWebFilter(PipelineStep):
|
|
|
1621
1622
|
"""
|
|
1622
1623
|
event = "DashboardRenderStarted"
|
|
1623
1624
|
|
|
1624
|
-
webfilters = Webfilter
|
|
1625
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
1625
1626
|
|
|
1626
1627
|
if webfilters:
|
|
1627
1628
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -1675,7 +1676,7 @@ class VerticalBlockChildRenderStartedWebFilter(PipelineStep):
|
|
|
1675
1676
|
event = type(self).__name__[:-9]
|
|
1676
1677
|
|
|
1677
1678
|
return_data = data.copy()
|
|
1678
|
-
webfilters = Webfilter
|
|
1679
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
1679
1680
|
|
|
1680
1681
|
if webfilters:
|
|
1681
1682
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -1719,7 +1720,7 @@ class CourseEnrollmentQuerysetRequestedWebFilter(PipelineStep):
|
|
|
1719
1720
|
event = type(self).__name__[:-9]
|
|
1720
1721
|
|
|
1721
1722
|
return_data = data.copy()
|
|
1722
|
-
webfilters = Webfilter
|
|
1723
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
1723
1724
|
|
|
1724
1725
|
if webfilters:
|
|
1725
1726
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -1766,7 +1767,7 @@ class RenderXBlockStartedWebFilter(PipelineStep):
|
|
|
1766
1767
|
event = type(self).__name__[:-9]
|
|
1767
1768
|
|
|
1768
1769
|
return_data = data.copy()
|
|
1769
|
-
webfilters = Webfilter
|
|
1770
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
1770
1771
|
|
|
1771
1772
|
if webfilters:
|
|
1772
1773
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -1825,7 +1826,7 @@ class VerticalBlockRenderCompletedWebFilter(PipelineStep):
|
|
|
1825
1826
|
event = type(self).__name__[:-9]
|
|
1826
1827
|
|
|
1827
1828
|
return_data = data.copy()
|
|
1828
|
-
webfilters = Webfilter
|
|
1829
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
1829
1830
|
|
|
1830
1831
|
if webfilters:
|
|
1831
1832
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -1869,7 +1870,7 @@ class CourseHomeUrlCreationStartedWebFilter(PipelineStep):
|
|
|
1869
1870
|
event = type(self).__name__[:-9]
|
|
1870
1871
|
|
|
1871
1872
|
return_data = data.copy()
|
|
1872
|
-
webfilters = Webfilter
|
|
1873
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
1873
1874
|
|
|
1874
1875
|
if webfilters:
|
|
1875
1876
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -1914,7 +1915,7 @@ class CourseEnrollmentAPIRenderStartedWebFilter(PipelineStep):
|
|
|
1914
1915
|
event = type(self).__name__[:-9]
|
|
1915
1916
|
|
|
1916
1917
|
return_data = data.copy()
|
|
1917
|
-
webfilters = Webfilter
|
|
1918
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
1918
1919
|
|
|
1919
1920
|
if webfilters:
|
|
1920
1921
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -1960,7 +1961,7 @@ class CourseRunAPIRenderStartedWebFilter(PipelineStep):
|
|
|
1960
1961
|
event = type(self).__name__[:-9]
|
|
1961
1962
|
|
|
1962
1963
|
return_data = data.copy()
|
|
1963
|
-
webfilters = Webfilter
|
|
1964
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
1964
1965
|
|
|
1965
1966
|
if webfilters:
|
|
1966
1967
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -1999,7 +2000,7 @@ class InstructorDashboardRenderStartedWebFilter(PipelineStep):
|
|
|
1999
2000
|
event = type(self).__name__[:-9]
|
|
2000
2001
|
|
|
2001
2002
|
return_data = data.copy()
|
|
2002
|
-
webfilters = Webfilter
|
|
2003
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
2003
2004
|
|
|
2004
2005
|
if webfilters:
|
|
2005
2006
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -2045,7 +2046,7 @@ class ORASubmissionViewRenderStartedWebFilter(PipelineStep):
|
|
|
2045
2046
|
event = type(self).__name__[:-9]
|
|
2046
2047
|
|
|
2047
2048
|
return_data = data.copy()
|
|
2048
|
-
webfilters = Webfilter
|
|
2049
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
2049
2050
|
|
|
2050
2051
|
if webfilters:
|
|
2051
2052
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -2089,7 +2090,7 @@ class IDVPageURLRequestedWebFilter(PipelineStep):
|
|
|
2089
2090
|
event = type(self).__name__[:-9]
|
|
2090
2091
|
|
|
2091
2092
|
return_data = data.copy()
|
|
2092
|
-
webfilters = Webfilter
|
|
2093
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
2093
2094
|
|
|
2094
2095
|
if webfilters:
|
|
2095
2096
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -2128,7 +2129,7 @@ class CourseAboutPageURLRequestedWebFilter(PipelineStep):
|
|
|
2128
2129
|
event = type(self).__name__[:-9]
|
|
2129
2130
|
|
|
2130
2131
|
return_data = data.copy()
|
|
2131
|
-
webfilters = Webfilter
|
|
2132
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
2132
2133
|
|
|
2133
2134
|
if webfilters:
|
|
2134
2135
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -2171,7 +2172,7 @@ class ScheduleQuerySetRequestedWebFilter(PipelineStep):
|
|
|
2171
2172
|
|
|
2172
2173
|
return_data = data.copy()
|
|
2173
2174
|
|
|
2174
|
-
webfilters = Webfilter
|
|
2175
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
2175
2176
|
|
|
2176
2177
|
if webfilters:
|
|
2177
2178
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -2213,7 +2214,7 @@ class LMSPageURLRequestedWebFilter(PipelineStep):
|
|
|
2213
2214
|
|
|
2214
2215
|
return_data = data.copy()
|
|
2215
2216
|
|
|
2216
|
-
webfilters = Webfilter
|
|
2217
|
+
webfilters = get_active_endpoints(Webfilter, event)
|
|
2217
2218
|
|
|
2218
2219
|
if webfilters:
|
|
2219
2220
|
logger.info(f"Webfilter for {event} event.")
|
|
@@ -2232,7 +2233,7 @@ class InstructorDashboardTabsRequestedWebFilter(PipelineStep):
|
|
|
2232
2233
|
|
|
2233
2234
|
def run_filter(self, tabs, user, course_key): # pylint: disable=arguments-differ
|
|
2234
2235
|
"""Accept a replacement tabs list or PreventTabsGeneration exception."""
|
|
2235
|
-
webfilters = Webfilter
|
|
2236
|
+
webfilters = get_active_endpoints(Webfilter, 'InstructorDashboardTabsRequested')
|
|
2236
2237
|
if not webfilters:
|
|
2237
2238
|
return {}
|
|
2238
2239
|
content, exceptions = _process_filter(
|
|
@@ -2251,7 +2252,7 @@ class AccountSettingsReadOnlyFieldsRequestedWebFilter(PipelineStep):
|
|
|
2251
2252
|
|
|
2252
2253
|
def run_filter(self, readonly_fields, user): # pylint: disable=arguments-differ
|
|
2253
2254
|
"""Convert returned JSON field names into the set required by the account API."""
|
|
2254
|
-
webfilters = Webfilter
|
|
2255
|
+
webfilters = get_active_endpoints(Webfilter, 'AccountSettingsReadOnlyFieldsRequested')
|
|
2255
2256
|
if not webfilters:
|
|
2256
2257
|
return {}
|
|
2257
2258
|
content, _ = _process_filter(webfilters, {'readonly_fields': sorted(readonly_fields), 'user': user})
|
|
@@ -2266,7 +2267,7 @@ class GradeEventContextRequestedWebFilter(PipelineStep):
|
|
|
2266
2267
|
|
|
2267
2268
|
def run_filter(self, context, user_id, course_id): # pylint: disable=arguments-differ
|
|
2268
2269
|
"""Merge additional context from configured endpoints."""
|
|
2269
|
-
webfilters = Webfilter
|
|
2270
|
+
webfilters = get_active_endpoints(Webfilter, 'GradeEventContextRequested')
|
|
2270
2271
|
if not webfilters:
|
|
2271
2272
|
return {}
|
|
2272
2273
|
content, _ = _process_filter(webfilters, {'context': context, 'user_id': user_id, 'course_id': course_id})
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""Cache ordered delivery configuration for Open edX filters and events."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from collections import namedtuple
|
|
5
|
+
from contextvars import ContextVar
|
|
6
|
+
from uuid import uuid4
|
|
7
|
+
|
|
8
|
+
from django.core.cache import cache
|
|
9
|
+
from django.core.signals import request_finished, request_started
|
|
10
|
+
from django.db import connections, router, transaction
|
|
11
|
+
from django.db.models.signals import post_delete, post_save
|
|
12
|
+
from django.dispatch import receiver
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
# Admin saves and deletes invalidate on commit. Expiry is a fallback.
|
|
17
|
+
_TTL = 24 * 60 * 60
|
|
18
|
+
_PREFIX = 'openedx_webhooks.active.v1'
|
|
19
|
+
_request_entries = ContextVar('openedx_webhooks_request_entries', default=None)
|
|
20
|
+
|
|
21
|
+
FilterEndpoint = namedtuple('FilterEndpoint', (
|
|
22
|
+
'event webhook_url use_www_form_encoding disable_filtering disable_halt '
|
|
23
|
+
'halt_on_4xx redirect_on_4xx halt_on_5xx redirect_on_5xx '
|
|
24
|
+
'halt_on_request_exception redirect_on_request_exception'
|
|
25
|
+
))
|
|
26
|
+
EventEndpoint = namedtuple('EventEndpoint', 'pk webhook_url use_www_form_encoding')
|
|
27
|
+
_FILTER = 'openedx_webhooks.Webfilter'
|
|
28
|
+
_HOOK = 'openedx_webhooks.Webhook'
|
|
29
|
+
_ENDPOINTS = {_FILTER: FilterEndpoint, _HOOK: EventEndpoint}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@receiver(request_started)
|
|
33
|
+
def _start_request(**kwargs):
|
|
34
|
+
"""Allocate a local tier only during an HTTP request."""
|
|
35
|
+
_request_entries.set({})
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@receiver(request_finished)
|
|
39
|
+
def _finish_request(**kwargs):
|
|
40
|
+
"""Release entries even on workers without the Open edX cache middleware."""
|
|
41
|
+
_request_entries.set(None)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _generation_key(model):
|
|
45
|
+
return f'{_PREFIX}.{model._meta.model_name}.generation'
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class _PendingChange:
|
|
49
|
+
"""Keep reads of uncommitted configuration scoped to the writing savepoint."""
|
|
50
|
+
|
|
51
|
+
def __init__(self, model):
|
|
52
|
+
self.model = model
|
|
53
|
+
self.entries = {}
|
|
54
|
+
# Django uses this attribute when logging failures of robust callbacks.
|
|
55
|
+
self.__qualname__ = type(self).__qualname__
|
|
56
|
+
|
|
57
|
+
def __call__(self):
|
|
58
|
+
"""Invalidate both tiers after commit, including keys for renamed events."""
|
|
59
|
+
entries = _request_entries.get()
|
|
60
|
+
if entries is not None:
|
|
61
|
+
entries.clear()
|
|
62
|
+
# An overlapping reader can only refill keys under its previous generation.
|
|
63
|
+
cache.delete(_generation_key(self.model))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@receiver(post_save, sender=_FILTER)
|
|
67
|
+
@receiver(post_delete, sender=_FILTER)
|
|
68
|
+
@receiver(post_save, sender=_HOOK)
|
|
69
|
+
@receiver(post_delete, sender=_HOOK)
|
|
70
|
+
def _configuration_changed(sender, using, **kwargs):
|
|
71
|
+
"""Invalidate committed configuration and mark pending writes for local readers."""
|
|
72
|
+
entries = _request_entries.get()
|
|
73
|
+
if entries is not None:
|
|
74
|
+
entries.clear()
|
|
75
|
+
transaction.on_commit(_PendingChange(sender), using=using, robust=True)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _read_rows(model, event, alias):
|
|
79
|
+
fields = _ENDPOINTS[model._meta.label]._fields
|
|
80
|
+
return tuple(model.objects.using(alias).filter(enabled=True, event=event).order_by('pk').values_list(*fields))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _endpoints(model, rows):
|
|
84
|
+
endpoint = _ENDPOINTS[model._meta.label]
|
|
85
|
+
return tuple(endpoint(*row) for row in rows)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def get_active_endpoints(model, event):
|
|
89
|
+
"""Read the ordered delivery fields, including caching the empty tuple on misses."""
|
|
90
|
+
alias = router.db_for_read(model)
|
|
91
|
+
connection = connections[alias]
|
|
92
|
+
# Django drops on_commit callbacks when their savepoint rolls back. While
|
|
93
|
+
# one of our invalidations is pending, only this transaction sees its writes.
|
|
94
|
+
if connection.in_atomic_block:
|
|
95
|
+
for _, callback, _ in reversed(connection.run_on_commit):
|
|
96
|
+
if isinstance(callback, _PendingChange) and callback.model is model:
|
|
97
|
+
if event not in callback.entries:
|
|
98
|
+
callback.entries[event] = _endpoints(model, _read_rows(model, event, alias))
|
|
99
|
+
return callback.entries[event]
|
|
100
|
+
|
|
101
|
+
entries = _request_entries.get()
|
|
102
|
+
local_key = (alias, model, event)
|
|
103
|
+
if entries is not None and local_key in entries:
|
|
104
|
+
return entries[local_key]
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
generation = cache.get_or_set(_generation_key(model), lambda: uuid4().hex, timeout=None)
|
|
108
|
+
key = f'{_PREFIX}.{model._meta.model_name}.{alias}.{generation}.{event}'
|
|
109
|
+
rows = cache.get(key)
|
|
110
|
+
except Exception: # pylint: disable=broad-except
|
|
111
|
+
logger.exception('Unable to read webhook configuration cache')
|
|
112
|
+
key = None
|
|
113
|
+
rows = None
|
|
114
|
+
if rows is None:
|
|
115
|
+
rows = _read_rows(model, event, alias)
|
|
116
|
+
if key is not None:
|
|
117
|
+
try:
|
|
118
|
+
cache.set(key, rows, timeout=_TTL)
|
|
119
|
+
except Exception: # pylint: disable=broad-except
|
|
120
|
+
logger.exception('Unable to write webhook configuration cache')
|
|
121
|
+
endpoints = _endpoints(model, rows)
|
|
122
|
+
if entries is not None:
|
|
123
|
+
entries[local_key] = endpoints
|
|
124
|
+
return endpoints
|
|
@@ -4,10 +4,10 @@ Open edX signal events handler functions.
|
|
|
4
4
|
import logging
|
|
5
5
|
|
|
6
6
|
import requests
|
|
7
|
-
from attrs import asdict
|
|
8
7
|
|
|
8
|
+
from .lookups import get_active_endpoints
|
|
9
9
|
from .models import Webhook
|
|
10
|
-
from .utils import
|
|
10
|
+
from .utils import object_serializer, send
|
|
11
11
|
|
|
12
12
|
logger = logging.getLogger(__name__)
|
|
13
13
|
|
|
@@ -17,21 +17,22 @@ def _process_event(event_name, data, **kwargs):
|
|
|
17
17
|
Process all events with user data.
|
|
18
18
|
"""
|
|
19
19
|
logger.debug(f"Processing event: {event_name}")
|
|
20
|
-
webhooks = Webhook
|
|
20
|
+
webhooks = get_active_endpoints(Webhook, event_name)
|
|
21
21
|
|
|
22
22
|
# Get the name of the data type
|
|
23
23
|
data_type = f"{type(data).__module__}.{type(data).__qualname__}"
|
|
24
24
|
|
|
25
|
+
payload = None
|
|
25
26
|
for webhook in webhooks:
|
|
26
27
|
logger.info(f"{event_name} webhook triggered to {webhook.webhook_url}")
|
|
27
28
|
|
|
28
|
-
payload
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
if payload is None:
|
|
30
|
+
# Serialize the entire envelope with one budget. Metadata comes first
|
|
31
|
+
# so it remains available if the event data exceeds the limit.
|
|
32
|
+
payload = object_serializer({
|
|
33
|
+
'event_metadata': kwargs.get('metadata') or {},
|
|
34
|
+
data_type: data,
|
|
35
|
+
})
|
|
35
36
|
try:
|
|
36
37
|
response = send(
|
|
37
38
|
webhook.webhook_url,
|