File tree Expand file tree Collapse file tree 4 files changed +35
-17
lines changed
openwisp_controller/config Expand file tree Collapse file tree 4 files changed +35
-17
lines changed Original file line number Diff line number Diff line change @@ -337,6 +337,7 @@ def enable_cache_invalidation(self):
337337 dispatch_uid = "vpn.invalidate_checksum_cache" ,
338338 )
339339
340+
340341 def register_dashboard_charts (self ):
341342 register_dashboard_chart (
342343 position = 1 ,
Original file line number Diff line number Diff line change @@ -152,3 +152,23 @@ def organization_disabled_handler(instance, **kwargs):
152152 # No change in is_active
153153 return
154154 tasks .invalidate_controller_views_cache .delay (str (instance .id ))
155+
156+
157+ def organization_config_settings_change_handler (instance , ** kwargs ):
158+ """
159+ Invalidates VPN cache when OrganizationConfigSettings context changes.
160+ """
161+ if instance ._state .adding :
162+ return
163+
164+ try :
165+ db_instance = instance .__class__ .objects .only ("context" ).get (id = instance .id )
166+ if db_instance .context != instance .context :
167+ from . import tasks
168+ transaction .on_commit (
169+ lambda : tasks .invalidate_organization_vpn_cache .delay (
170+ str (instance .organization_id )
171+ )
172+ )
173+ except instance .__class__ .DoesNotExist :
174+ pass
Original file line number Diff line number Diff line change @@ -100,6 +100,20 @@ def invalidate_vpn_server_devices_cache_change(vpn_pk):
100100 VpnClient .invalidate_clients_cache (vpn )
101101
102102
103+ @shared_task (soft_time_limit = 7200 )
104+ def invalidate_organization_vpn_cache (organization_id ):
105+ """
106+ Invalidates VPN cache for all VPNs in an organization when
107+ organization configuration variables change.
108+ """
109+ Vpn = load_model ("config" , "Vpn" )
110+
111+ for vpn in Vpn .objects .filter (organization_id = organization_id ).iterator ():
112+ from .controller .views import GetVpnView
113+ GetVpnView .invalidate_get_vpn_cache (vpn )
114+ vpn .invalidate_checksum_cache ()
115+
116+
103117@shared_task (soft_time_limit = 7200 )
104118def invalidate_devicegroup_cache_delete (instance_id , model_name , ** kwargs ):
105119 from .api .views import DeviceGroupCommonName
Original file line number Diff line number Diff line change @@ -18,20 +18,3 @@ def test_organization_disabled_handler(self, mocked_task):
1818 org .is_active = False
1919 org .save ()
2020 mocked_task .assert_called_once ()
21-
22- mocked_task .reset_mock ()
23- with self .subTest ("Test task not executed on saving inactive org" ):
24- org .name = "Changed named"
25- org .save ()
26- mocked_task .assert_not_called ()
27-
28- with self .subTest ("Test task not executed on creating inactive org" ):
29- inactive_org = self ._create_org (
30- is_active = False , name = "inactive" , slug = "inactive"
31- )
32- mocked_task .assert_not_called ()
33-
34- with self .subTest ("Test task not executed on changing inactive to active org" ):
35- inactive_org .is_active = True
36- inactive_org .save ()
37- mocked_task .assert_not_called ()
You can’t perform that action at this time.
0 commit comments