Skip to content

Commit f65b2a2

Browse files
committed
docs: add ADR for authz_permission_required decorator
1 parent 245fac6 commit f65b2a2

2 files changed

Lines changed: 156 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
AuthZ Django Integration
2+
########################
3+
4+
Overview
5+
********
6+
7+
The ``openedx.core.djangoapps.authz`` app provides Django integrations for the
8+
`openedx-authz` authorization framework within ``edx-platform``.
9+
10+
The `openedx-authz` library implements a centralized authorization system based
11+
on explicit permissions and policy evaluation. This Django app acts as a thin
12+
integration layer between ``edx-platform`` and the external library, providing
13+
utilities that make it easier to enforce authorization checks in Django views.
14+
15+
Currently, the app provides a decorator used to enforce AuthZ permissions in
16+
views. The app may also host additional Django-specific helpers and utilities
17+
as the integration with the AuthZ framework evolves.
18+
19+
Purpose
20+
*******
21+
22+
This app exists to:
23+
24+
- Provide Django-specific integrations for the ``openedx-authz`` framework
25+
- Offer reusable decorators for enforcing authorization checks in views
26+
- Centralize AuthZ-related utilities used across LMS and Studio
27+
28+
Keeping these integrations in a dedicated app avoids coupling authorization
29+
logic with unrelated apps and provides a clear location for future extensions.
30+
31+
Location in the Platform
32+
************************
33+
34+
The app lives in ``openedx/core/djangoapps`` because the functionality it
35+
provides is a **platform-level concern shared across LMS and Studio**, rather
36+
than something specific to either service.
37+
38+
Usage
39+
*****
40+
41+
The primary utility currently provided by this app is a decorator that enforces
42+
authorization checks using the AuthZ framework.
43+
44+
Example usage::
45+
46+
from openedx.core.djangoapps.authz.decorators import authz_permission_required
47+
48+
49+
@authz_permission_required("course.read")
50+
def my_view(request, course_key):
51+
...
52+
53+
The decorator ensures that the requesting user has the required permission
54+
before allowing the view to execute.
55+
56+
Additional parameters may allow compatibility with legacy permission checks
57+
during the transition to the new authorization framework.
58+
59+
Contents
60+
********
61+
62+
The app currently includes:
63+
64+
- **Decorators** for enforcing AuthZ permissions in Django views
65+
- **Constants** used by the AuthZ integration
66+
- **Tests** validating decorator behavior
67+
68+
Relationship with ``openedx-authz``
69+
***********************************
70+
71+
This app does not implement the authorization framework itself. Instead, it
72+
provides Django-specific integrations that connect ``edx-platform`` with the
73+
external ``openedx-authz`` library.
74+
75+
Keeping these integrations in ``edx-platform`` ensures that the external
76+
library remains framework-agnostic.
77+
78+
References
79+
**********
80+
81+
- `openedx-authz repository <https://github.com/openedx/openedx-authz>`_
82+
- `openedx-authz documentation <https://openedx-authz.readthedocs.io/>`_
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
0001 AUTHZ DJANGO INTEGRATION APP
2+
####################
3+
4+
Status
5+
******
6+
7+
Accepted
8+
9+
Context
10+
*******
11+
12+
This ADR defines where Django integrations for the openedx-authz framework should live within edx-platform.
13+
The openedx-authz library introduces a new authorization framework for Open edX based on explicit permissions and a centralized policy engine. Integrating this framework into edx-platform requires several Django-specific utilities.
14+
One of the first integrations is a view decorator used to enforce authorization checks using the new AuthZ framework. This decorator is expected to be reused across multiple views in LMS and Studio.
15+
During implementation, the question arose of where these Django integrations should live.
16+
17+
Some options considered were:
18+
19+
- common/djangoapps/student/auth.py
20+
- openedx/core/authz.py (a new python module)
21+
- openedx/core/djangoapps/authz (a new Django app)
22+
23+
The student app contains legacy authentication and authorization logic tied to student functionality. Adding new platform-level authorization integrations there would introduce cross-cutting concerns into an unrelated app.
24+
25+
Another option was creating a single module such as openedx/core/authz.py. However, the integration already includes multiple components (decorators, constants, tests) and is expected to grow over time.
26+
27+
Because of this, a dedicated Django app provides a clearer and more scalable structure for these integrations.
28+
29+
Decision
30+
********
31+
32+
edx-platform will introduce a new lightweight Django app openedx.core.djangoapps.authz to host Django integrations for the openedx-authz framework.
33+
34+
- The app will contain reusable decorators enforcing AuthZ permissions in Django views.
35+
- Supporting modules such as constants and helper utilities will live in this app.
36+
- The app will include tests validating these integrations.
37+
- The app acts as a thin integration layer between edx-platform and the external openedx-authz library.
38+
- The app will live in openedx/core/djangoapps because this functionality is a platform-level concern shared by LMS and Studio.
39+
40+
Initial contents include:
41+
42+
- An authorization decorator for Django views.
43+
- A constants.py module for AuthZ-related constants.
44+
- Tests validating the decorator behavior.
45+
46+
Consequences
47+
************
48+
49+
- Django integrations for the AuthZ framework have a centralized and discoverable location.
50+
- Future integrations can be added without expanding unrelated modules.
51+
- The separation clarifies the distinction between authentication (authn) and authorization (authz) responsibilities.
52+
53+
However:
54+
55+
- Introducing a new Django app slightly increases project structure complexity.
56+
- Some authorization logic may remain elsewhere until future refactoring occurs.
57+
58+
Rejected Alternatives
59+
**********************
60+
61+
- Add the decorator to common/djangoapps/student/auth.py
62+
Rejected because the module belongs to the student app and already mixes authentication and authorization responsibilities.
63+
64+
- Create a single module openedx/core/authz.py
65+
Rejected because the integration already includes multiple components and is expected to grow.
66+
67+
- Implement the decorator in the openedx-authz library
68+
Rejected because the decorator is Django-specific and tied to how edx-platform integrates authorization checks into views.
69+
70+
References
71+
**********
72+
73+
.. _openedx-authz repository: https://github.com/openedx/openedx-authz
74+
.. _openedx-authz documentation: https://openedx-authz.readthedocs.io/

0 commit comments

Comments
 (0)