-
Notifications
You must be signed in to change notification settings - Fork 24
feat: add AccountSettingsReadOnlyFieldsRequested filter #334
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
Changes from 2 commits
a2bae8d
9d5be70
3547ad7
6aeb50d
d393a40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1445,3 +1445,41 @@ def run_filter(cls, schedules: QuerySet) -> QuerySet | None: | |
| """ | ||
| data = super().run_pipeline(schedules=schedules) | ||
| return data.get("schedules") | ||
|
|
||
|
|
||
| class AccountSettingsReadOnlyFieldsRequested(OpenEdxPublicFilter): | ||
| """ | ||
| Filter used to expand the set of read-only fields on the account settings API. | ||
|
|
||
| Purpose: | ||
| This filter is triggered when the account settings API validates which fields | ||
| may be updated for a given user. Pipeline steps may add field names to | ||
| ``readonly_fields`` to mark those fields as read-only for the requesting user. | ||
|
|
||
| Filter Type: | ||
| org.openedx.learning.account.settings.read_only_fields.requested.v1 | ||
|
|
||
| Trigger: | ||
| - Repository: openedx/openedx-platform | ||
| - Path: openedx/core/djangoapps/user_api/accounts/api.py | ||
| - Function or Method: _validate_read_only_fields | ||
| """ | ||
|
|
||
| filter_type = "org.openedx.learning.account.settings.read_only_fields.requested.v1" | ||
|
|
||
| @classmethod | ||
| def run_filter(cls, readonly_fields: set, user: Any) -> set: | ||
| """ | ||
| Process the readonly_fields set using the configured pipeline steps. | ||
|
|
||
| Arguments: | ||
| readonly_fields (set): the set of field names the caller considers read-only. | ||
| Pipeline steps add field names to this set to mark additional fields as | ||
| read-only. | ||
| user (User): the Django User whose account settings are being updated. | ||
|
|
||
| Returns: | ||
| set: the (possibly expanded) set of read-only field names. | ||
| """ | ||
| data = super().run_pipeline(readonly_fields=readonly_fields, user=user) | ||
| return data.get("readonly_fields", set()) | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| from django.test import TestCase | ||
|
|
||
| from openedx_filters.learning.filters import ( | ||
| AccountSettingsReadOnlyFieldsRequested, | ||
| AccountSettingsRenderStarted, | ||
| CertificateCreationRequested, | ||
| CertificateRenderStarted, | ||
|
|
@@ -801,3 +802,33 @@ def test_schedule_requested(self): | |
| result = ScheduleQuerySetRequested.run_filter(schedules) | ||
|
|
||
| self.assertEqual(schedules, result) | ||
|
|
||
|
|
||
| class TestAccountSettingsReadOnlyFieldsRequestedFilter(TestCase): | ||
| """ | ||
| Tests for the AccountSettingsReadOnlyFieldsRequested filter. | ||
| """ | ||
|
|
||
| def test_run_filter_returns_empty_set_unchanged_when_no_pipeline(self): | ||
|
||
| """ | ||
| When no pipeline steps are configured, run_filter returns the original readonly_fields. | ||
| """ | ||
| readonly_fields = set() | ||
| user = Mock() | ||
|
|
||
| with patch.object( | ||
| AccountSettingsReadOnlyFieldsRequested, | ||
| "run_pipeline", | ||
| return_value={"readonly_fields": readonly_fields}, | ||
| ): | ||
| result = AccountSettingsReadOnlyFieldsRequested.run_filter( | ||
| readonly_fields=readonly_fields, user=user | ||
| ) | ||
|
|
||
| self.assertEqual(result, readonly_fields) | ||
|
|
||
| def test_filter_type(self): | ||
| self.assertEqual( | ||
| AccountSettingsReadOnlyFieldsRequested.filter_type, | ||
| "org.openedx.learning.account.settings.read_only_fields.requested.v1", | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.