Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Unreleased

*

0.19.2 - 2025-11-25
********************

Performance
===========

* Use a RequestCache for is_admin_or_superuser matcher to improve performance.

0.19.1 - 2025-11-25
********************

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ PIP_COMPILE = pip-compile $(PIP_COMPILE_OPTS)

compile-requirements: ## compile the requirements/*.txt files with the latest packages satisfying requirements/*.in
pip install -qr requirements/pip-tools.txt
pip install -qr requirements/pip.txt
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix we've been using elsewhere to deal with the current pip-tools compatibility issues with pip.

pip-compile -v ${COMPILE_OPTS} --allow-unsafe --rebuild -o requirements/pip.txt requirements/pip.in
pip-compile -v ${COMPILE_OPTS} -o requirements/pip-tools.txt requirements/pip-tools.in
pip install -qr requirements/pip.txt
Expand Down
2 changes: 1 addition & 1 deletion openedx_authz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

import os

__version__ = "0.19.1"
__version__ = "0.19.2"

ROOT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
2 changes: 0 additions & 2 deletions openedx_authz/engine/enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ def configure_enforcer_auto_save_and_load(cls):

if auto_load_policy_interval > 0:
cls.configure_enforcer_auto_loading(auto_load_policy_interval)
else:
logger.warning("CASBIN_AUTO_LOAD_POLICY_INTERVAL is not set or zero; auto-load is disabled.")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning was firing several times in a request, I don't think we need it anymore?


cls.configure_enforcer_auto_save(auto_save_policy)

Expand Down
24 changes: 18 additions & 6 deletions openedx_authz/engine/matcher.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Custom condition checker. Note only used for data_library scope"""

from django.contrib.auth import get_user_model
from edx_django_utils.cache import RequestCache

from openedx_authz.api.data import ContentLibraryData, ScopeData, UserData
from openedx_authz.rest_api.utils import get_user_by_username_or_email
Expand All @@ -26,15 +27,26 @@ def is_admin_or_superuser_check(request_user: str, request_action: str, request_
ContentLibraryData scopes), False otherwise (including when user
doesn't exist or scope type is not supported)
"""

scope = ScopeData(namespaced_key=request_scope)
username = UserData(namespaced_key=request_user).external_key
request_cache = RequestCache("rbac_is_admin_or_superuser")

# TODO: This special case for superuser and staff users is currently only for
# content libraries. See: https://github.com/openedx/openedx-authz/issues/87
if not isinstance(scope, ContentLibraryData):
return False

cached_response = request_cache.get_cached_response(username)
if cached_response.is_found:
return cached_response.value

try:
username = UserData(namespaced_key=request_user).external_key
user = get_user_by_username_or_email(username)
except User.DoesNotExist:
return False

scope = ScopeData(namespaced_key=request_scope)

if isinstance(scope, ContentLibraryData):
return user.is_staff or user.is_superuser
is_allowed = user.is_staff or user.is_superuser
request_cache.set(username, is_allowed)

return False
return is_allowed
1 change: 1 addition & 0 deletions openedx_authz/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def plugin_settings(settings): # pylint: disable=unused-argument
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"edx_django_utils.cache.middleware.RequestCacheMiddleware",
]

TEMPLATES = [
Expand Down
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pycasbin # Authorization library for implementing access cont
casbin-django-orm-adapter # Adapter for Django ORM for Casbin
edx-opaque-keys # Opaque keys for resource identification
edx-api-doc-tools # Tools for API documentation
edx-django-utils # Used for RequestCache
edx-drf-extensions # Extensions for Django Rest Framework used by Open edX
8 changes: 6 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ cffi==2.0.0
charset-normalizer==3.4.3
# via requests
click==8.3.0
# via edx-django-utils
# via
# -c requirements/constraints.txt
# edx-django-utils
cryptography==46.0.2
# via pyjwt
django==4.2.24
Expand Down Expand Up @@ -57,7 +59,9 @@ drf-yasg==1.21.11
edx-api-doc-tools==2.1.0
# via -r requirements/base.in
edx-django-utils==8.0.1
# via edx-drf-extensions
# via
# -r requirements/base.in
# edx-drf-extensions
edx-drf-extensions==10.6.0
# via -r requirements/base.in
edx-opaque-keys==3.0.0
Expand Down
3 changes: 3 additions & 0 deletions requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@

# Common constraints for edx repos
-c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt

# Different packages want different versions of click, we force the most compatible one here
click==8.3.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another pip-tools issue that was blocking make upgrade . pip-tools wanted 8.3.1, everything else wanted 8.3.0 so I've pinned it here for now.

3 changes: 2 additions & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ charset-normalizer==3.4.3
# requests
click==8.3.0
# via
# -c requirements/constraints.txt
# -r requirements/pip-tools.txt
# -r requirements/quality.txt
# click-log
Expand Down Expand Up @@ -196,7 +197,7 @@ packaging==25.0
# tox
path==16.16.0
# via edx-i18n-tools
pip-tools==7.5.1
pip-tools==7.5.2
# via -r requirements/pip-tools.txt
platformdirs==4.4.0
# via
Expand Down
1 change: 1 addition & 0 deletions requirements/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ charset-normalizer==3.4.3
# requests
click==8.3.0
# via
# -c requirements/constraints.txt
# -r requirements/test.txt
# code-annotations
# edx-django-utils
Expand Down
6 changes: 4 additions & 2 deletions requirements/pip-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
build==1.3.0
# via pip-tools
click==8.3.0
# via pip-tools
# via
# -c requirements/constraints.txt
# pip-tools
packaging==25.0
# via build
pip-tools==7.5.1
pip-tools==7.5.2
# via -r requirements/pip-tools.in
pyproject-hooks==1.2.0
# via
Expand Down
4 changes: 3 additions & 1 deletion requirements/pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ wheel==0.45.1

# The following packages are considered to be unsafe in a requirements file:
pip==25.2
# via -r requirements/pip.in
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
# -r requirements/pip.in
setuptools==80.9.0
# via -r requirements/pip.in
1 change: 1 addition & 0 deletions requirements/quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ charset-normalizer==3.4.3
# requests
click==8.3.0
# via
# -c requirements/constraints.txt
# -r requirements/test.txt
# click-log
# code-annotations
Expand Down
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ charset-normalizer==3.4.3
# requests
click==8.3.0
# via
# -c requirements/constraints.txt
# -r requirements/base.txt
# code-annotations
# edx-django-utils
Expand Down