Skip to content

Commit cd14a07

Browse files
committed
squash!: Format code, bump version
1 parent 58a5a8b commit cd14a07

7 files changed

Lines changed: 13 additions & 16 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Change Log
1414
Unreleased
1515
**********
1616

17-
0.15.1 - 2025-11-12
17+
0.16.0 - 2025-11-13
1818
********************
1919

2020
Added

openedx_authz/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
import os
66

7-
__version__ = "0.15.1"
7+
__version__ = "0.16.0"
88

99
ROOT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))

openedx_authz/engine/enforcer.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ def configure_enforcer_auto_save_and_load(cls):
149149
Returns:
150150
None
151151
"""
152-
auto_load_policy_interval = getattr(
153-
settings, "CASBIN_AUTO_LOAD_POLICY_INTERVAL", 0)
152+
auto_load_policy_interval = getattr(settings, "CASBIN_AUTO_LOAD_POLICY_INTERVAL", 0)
154153
auto_save_policy = getattr(settings, "CASBIN_AUTO_SAVE_POLICY", True)
155154

156155
# TODO: remove autoload in favor of cache invalidation?
@@ -166,7 +165,7 @@ def load_policy_if_needed(cls):
166165
"""Load policy if the last load timestamp indicates it's needed.
167166
168167
This method checks if the policy needs to be reloaded comparing
169-
the last load timestamp with the last modified timestamp in cache
168+
the last load timestamp with the last modified timestamp in cache
170169
and reloads it if necessary.
171170
172171
Returns:
@@ -179,13 +178,9 @@ def load_policy_if_needed(cls):
179178
if last_modified_timestamp is None:
180179
# No timestamp in cache; initialize it
181180
cache.set(cls.CACHE_KEY, current_timestamp, None)
182-
logger.info(
183-
f">>>> Initialized policy last modified timestamp in cache. {current_timestamp}")
181+
logger.info(f">>>> Initialized policy last modified timestamp in cache. {current_timestamp}")
184182

185-
if (
186-
cls._last_policy_load_timestamp is None or
187-
last_modified_timestamp > cls._last_policy_load_timestamp
188-
):
183+
if cls._last_policy_load_timestamp is None or last_modified_timestamp > cls._last_policy_load_timestamp:
189184
# Policy has been modified since last load; reload it
190185
cls._enforcer.load_policy()
191186
cls._last_policy_load_timestamp = current_timestamp
@@ -263,13 +258,11 @@ def _initialize_enforcer(cls) -> SyncedEnforcer:
263258
# issues when the app is not fully loaded (e.g., while pulling translations, etc.).
264259
initialize_enforcer(db_alias)
265260
except Exception as e:
266-
logger.error(
267-
f"Failed to initialize Casbin enforcer with DB alias '{db_alias}': {e}")
261+
logger.error(f"Failed to initialize Casbin enforcer with DB alias '{db_alias}': {e}")
268262
raise
269263

270264
adapter = ExtendedAdapter()
271265
enforcer = SyncedEnforcer(settings.CASBIN_MODEL, adapter)
272-
enforcer.add_function("is_staff_or_superuser",
273-
is_admin_or_superuser_check)
266+
enforcer.add_function("is_staff_or_superuser", is_admin_or_superuser_check)
274267

275268
return enforcer

openedx_authz/models/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def get_registry(cls) -> dict[str, type["BaseRegistryModel"]]:
4444
"""
4545
return cls._registry
4646

47+
4748
class ScopeManager(models.Manager):
4849
"""Custom manager for Scope model that handles polymorphic behavior."""
4950

openedx_authz/settings/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def plugin_settings(settings):
3131
# Set default CASBIN_AUTO_LOAD_POLICY_INTERVAL if not already set.
3232
# This setting defines how often (in seconds) the Casbin enforcer should
3333
# automatically reload policies from the database.
34+
# By default, we set it to 0, which disables the auto-reload.
35+
# As it shouldn't be needed thanks to cache invalidation.
3436
if not hasattr(settings, "CASBIN_AUTO_LOAD_POLICY_INTERVAL"):
3537
settings.CASBIN_AUTO_LOAD_POLICY_INTERVAL = 0
3638

openedx_authz/tests/api/test_roles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ def test_assign_role_creates_extended_casbin_rule(self):
968968
new_count = ExtendedCasbinRule.objects.count()
969969
self.assertEqual(new_count, initial_count + 1)
970970

971-
extended_rule = ExtendedCasbinRule.objects.order_by('-id').first()
971+
extended_rule = ExtendedCasbinRule.objects.order_by("-id").first()
972972
self.assertIsNotNone(extended_rule)
973973
self.assertIsNotNone(extended_rule.casbin_rule)
974974
self.assertIsNotNone(extended_rule.subject)

openedx_authz/tests/test_enforcer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ def test_multiple_get_enforcer_calls_preserve_auto_save(self, mock_toggle):
825825
AuthzEnforcer.get_enforcer()
826826
self.assertTrue(AuthzEnforcer.is_auto_save_enabled())
827827

828+
828829
class TestEnforcerPolicyCacheBehavior(TransactionTestCase):
829830
"""Test cases for enforcer policy cache behavior.
830831

0 commit comments

Comments
 (0)