File tree Expand file tree Collapse file tree 2 files changed +72
-0
lines changed
Expand file tree Collapse file tree 2 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -1445,3 +1445,41 @@ def run_filter(cls, schedules: QuerySet) -> QuerySet | None:
14451445 """
14461446 data = super ().run_pipeline (schedules = schedules )
14471447 return data .get ("schedules" )
1448+
1449+
1450+ class AccountSettingsReadOnlyFieldsRequested (OpenEdxPublicFilter ):
1451+ """
1452+ Filter used to expand the set of read-only fields on the account settings API.
1453+
1454+ Purpose:
1455+ This filter is triggered when the account settings API validates which fields
1456+ may be updated for a given user. Pipeline steps may add field names to
1457+ ``readonly_fields`` to mark those fields as read-only for the requesting user.
1458+
1459+ Filter Type:
1460+ org.openedx.learning.account.settings.read_only_fields.requested.v1
1461+
1462+ Trigger:
1463+ - Repository: openedx/edx-platform
1464+ - Path: openedx/core/djangoapps/user_api/accounts/api.py
1465+ - Function or Method: _validate_read_only_fields
1466+ """
1467+
1468+ filter_type = "org.openedx.learning.account.settings.read_only_fields.requested.v1"
1469+
1470+ @classmethod
1471+ def run_filter (cls , readonly_fields : set , user : Any ) -> set :
1472+ """
1473+ Process the readonly_fields set using the configured pipeline steps.
1474+
1475+ Arguments:
1476+ readonly_fields (set): the set of field names the caller considers read-only.
1477+ Pipeline steps add field names to this set to mark additional fields as
1478+ read-only.
1479+ user (User): the Django User whose account settings are being updated.
1480+
1481+ Returns:
1482+ set: the (possibly expanded) set of read-only field names.
1483+ """
1484+ data = super ().run_pipeline (readonly_fields = readonly_fields , user = user )
1485+ return data .get ("readonly_fields" )
Original file line number Diff line number Diff line change @@ -801,3 +801,37 @@ def test_schedule_requested(self):
801801 result = ScheduleQuerySetRequested .run_filter (schedules )
802802
803803 self .assertEqual (schedules , result )
804+
805+
806+ class TestAccountSettingsReadOnlyFieldsRequestedFilter (TestCase ):
807+ """
808+ Tests for the AccountSettingsReadOnlyFieldsRequested filter.
809+ """
810+
811+ def test_run_filter_returns_empty_set_unchanged_when_no_pipeline (self ):
812+ """
813+ When no pipeline steps are configured, run_filter returns the original readonly_fields.
814+ """
815+ from unittest .mock import Mock , patch
816+ from openedx_filters .learning .filters import AccountSettingsReadOnlyFieldsRequested
817+
818+ readonly_fields = set ()
819+ user = Mock ()
820+
821+ with patch .object (
822+ AccountSettingsReadOnlyFieldsRequested ,
823+ "run_pipeline" ,
824+ return_value = {"readonly_fields" : readonly_fields },
825+ ):
826+ result = AccountSettingsReadOnlyFieldsRequested .run_filter (
827+ readonly_fields = readonly_fields , user = user
828+ )
829+
830+ self .assertEqual (result , readonly_fields )
831+
832+ def test_filter_type (self ):
833+ from openedx_filters .learning .filters import AccountSettingsReadOnlyFieldsRequested
834+ self .assertEqual (
835+ AccountSettingsReadOnlyFieldsRequested .filter_type ,
836+ "org.openedx.learning.account.settings.read_only_fields.requested.v1" ,
837+ )
You can’t perform that action at this time.
0 commit comments