Skip to content

Commit 080544c

Browse files
taimoor-ahmed-1Faraz32123
authored andcommitted
feat: apply ADR 0034 (auth standardization) across 6 standardized APIs (#38796)
1 parent 2a870a4 commit 080544c

6 files changed

Lines changed: 58 additions & 7 deletions

File tree

cms/djangoapps/contentstore/rest_api/v1/views/xblock.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
* ADR 0026 - explicit authentication_classes + permission_classes
99
* ADR 0028 - consolidated into XblockViewSet via DefaultRouter
1010
* ADR 0029 - standardized error envelope via StandardizedErrorMixin
11+
* ADR 0034 - already compliant. ``authentication_classes`` is
12+
``(JwtAuthentication, SessionAuthenticationAllowInactiveUser)`` — no
13+
``BearerAuthentication`` / ``OAuth2Authentication`` to remove. This view
14+
is set explicitly (rather than relying on platform defaults) because it
15+
needs ``SessionAuthenticationAllowInactiveUser`` instead of the default
16+
``SessionAuthentication`` so inactive Studio authors can still hit the
17+
endpoint while their session is being verified.
1118
* ADR 0036 - minimal/flattened views. ``retrieve`` accepts a ``?view=minimal``
1219
query parameter that strips the (tree-shaped) xblock response to a small
1320
set of structural fields. The full xblock response is kept as the default

cms/djangoapps/contentstore/rest_api/v3/views/authoring_grading.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
real-world payload is always small. A hard cap is enforced upstream of
3131
this endpoint by :func:`CourseGradingModel.update_from_json`; we surface
3232
that as a documentation note rather than re-implement the bound here.
33+
* ADR 0034 – auth standardization (OEP-0042).
34+
``authentication_classes`` is ``(JwtAuthentication, SessionAuthenticationAllowInactiveUser)``;
35+
``BearerAuthenticationAllowInactiveUser`` has been removed per the
36+
deprecation policy. ``SessionAuthenticationAllowInactiveUser`` is
37+
retained (rather than relying on the platform-default
38+
``SessionAuthentication``) so Studio authors whose accounts are
39+
temporarily inactive can still update grading.
3340
3441
Permission model note:
3542
PR #38363 proposed a class-level ``HasStudioReadAccess`` permission. The
@@ -63,7 +70,6 @@
6370
from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission
6471
from openedx.core.djangoapps.authz.decorators import user_has_course_permission
6572
from openedx.core.djangoapps.credit.tasks import update_credit_course_requirements
66-
from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser
6773
from openedx.core.lib.api.mixins import StandardizedErrorMixin
6874

6975
_COURSE_KEY_PARAMETER = OpenApiParameter(
@@ -87,9 +93,12 @@ class AuthoringGradingViewSet(StandardizedErrorMixin, viewsets.ViewSet):
8793
Supersedes ``AuthoringGradingView`` at ``POST /api/contentstore/v0/grading/{course_id}``.
8894
"""
8995

96+
# ADR 0034 — JWT + session-with-inactive-user (BearerAuthenticationAllowInactiveUser
97+
# removed per OEP-0042). SessionAuthenticationAllowInactiveUser is retained
98+
# (instead of relying on the platform-default SessionAuthentication) so Studio
99+
# authors whose accounts are temporarily inactive can still update grading.
90100
authentication_classes = (
91101
JwtAuthentication,
92-
BearerAuthenticationAllowInactiveUser,
93102
SessionAuthenticationAllowInactiveUser,
94103
)
95104
permission_classes = (IsAuthenticated,)

cms/djangoapps/contentstore/rest_api/v3/views/course_details.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
* ADR 0029 – standardized error envelope via :class:`StandardizedErrorMixin`
1313
(v3-scoped — does not change the project-wide DRF ``EXCEPTION_HANDLER``
1414
setting)
15+
* ADR 0034 – already compliant. ``authentication_classes`` is
16+
``(JwtAuthentication, SessionAuthenticationAllowInactiveUser)`` — no
17+
``BearerAuthentication`` / ``OAuth2Authentication`` to remove.
18+
Explicit declaration kept (rather than relying on platform defaults)
19+
so that ``SessionAuthenticationAllowInactiveUser`` is used instead of
20+
the default ``SessionAuthentication``.
1521
1622
Permission model note:
1723
PR #38365 proposed a class-level ``HasStudioReadAccess`` permission. The

cms/djangoapps/contentstore/rest_api/v3/views/home.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
explicitly. The flat-list ``courses`` and ``libraries`` actions are
1919
out of scope (single-key dict around a list) and do not honour
2020
``?fields=``.
21+
* ADR 0034 – already compliant. ``authentication_classes`` is
22+
``(JwtAuthentication, SessionAuthenticationAllowInactiveUser)`` —
23+
no ``BearerAuthentication`` / ``OAuth2Authentication`` to remove.
24+
The explicit declaration is kept (rather than relying on platform
25+
defaults) so that ``SessionAuthenticationAllowInactiveUser`` is used
26+
instead of the default ``SessionAuthentication``.
2127
"""
2228

2329
import edx_api_doc_tools as apidocs

cms/djangoapps/contentstore/rest_api/v4/views/home.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ class HomeCoursesViewSet(StandardizedErrorMixin, viewsets.ViewSet):
128128
a dynamic-fields serializer mixin and per-field schema documentation)
129129
but is intentionally NOT added here to keep the v4 contract stable
130130
for the existing Studio frontend.
131+
- 0034: already compliant. ``authentication_classes`` is
132+
``(JwtAuthentication, SessionAuthenticationAllowInactiveUser)`` — no
133+
``BearerAuthentication`` / ``OAuth2Authentication`` to remove.
134+
Explicit declaration kept so ``SessionAuthenticationAllowInactiveUser``
135+
is used instead of the default ``SessionAuthentication``.
131136
"""
132137

133138
authentication_classes = (JwtAuthentication, SessionAuthenticationAllowInactiveUser)

openedx/core/djangoapps/enrollments/v2/views.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
77
* ADR 0025 – ``serializer_class`` on every viewset/view
88
* ADR 0026 – explicit ``authentication_classes`` + ``permission_classes``
9+
* ADR 0034 – auth standardization (OEP-0042). All four v2 viewsets/views use
10+
``(JwtAuthentication, EnrollmentCrossDomainSessionAuth)``;
11+
``BearerAuthenticationAllowInactiveUser`` has been removed per the
12+
deprecation policy. ``EnrollmentCrossDomainSessionAuth`` is retained
13+
(rather than relying on the platform-default ``SessionAuthentication``)
14+
because these endpoints must accept cross-domain Studio/LMS CSRF-validated
15+
session cookies.
916
* ADR 0027 – ``drf_spectacular`` for OpenAPI schema generation
1017
* ADR 0028 – consolidated into ``ViewSet`` classes registered via
1118
``DefaultRouter`` where the URL shape allows it
@@ -70,7 +77,6 @@
7077
EnrollmentUserThrottle,
7178
)
7279
from openedx.core.djangoapps.user_api.accounts.permissions import CanRetireUser
73-
from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser
7480
from openedx.core.lib.api.mixins import StandardizedErrorMixin
7581
from openedx.core.lib.api.permissions import ApiKeyHeaderPermissionIsAuthenticated
7682

@@ -209,9 +215,12 @@ class EnrollmentViewSet(StandardizedErrorMixin, viewsets.ViewSet, ApiKeyPermissi
209215
DELETE /api/enrollment/v2/enrollment/enrollment_allowed/ → allowed (DELETE)
210216
"""
211217

218+
# ADR 0034 — JWT + cross-domain session (BearerAuthenticationAllowInactiveUser
219+
# removed per OEP-0042). EnrollmentCrossDomainSessionAuth retained because the
220+
# endpoint must accept cross-domain Studio/LMS CSRF-validated session cookies;
221+
# the platform-default SessionAuthentication would reject those.
212222
authentication_classes = (
213223
JwtAuthentication,
214-
BearerAuthenticationAllowInactiveUser,
215224
EnrollmentCrossDomainSessionAuth,
216225
)
217226
permission_classes = (ApiKeyHeaderPermissionIsAuthenticated,)
@@ -417,9 +426,12 @@ def allowed(self, request):
417426
class EnrollmentRetrieveView(StandardizedErrorMixin, ApiKeyPermissionMixIn, APIView):
418427
"""GET enrollment for a course (and optionally a named user)."""
419428

429+
# ADR 0034 — JWT + cross-domain session (BearerAuthenticationAllowInactiveUser
430+
# removed per OEP-0042). EnrollmentCrossDomainSessionAuth retained because the
431+
# endpoint must accept cross-domain Studio/LMS CSRF-validated session cookies;
432+
# the platform-default SessionAuthentication would reject those.
420433
authentication_classes = (
421434
JwtAuthentication,
422-
BearerAuthenticationAllowInactiveUser,
423435
EnrollmentCrossDomainSessionAuth,
424436
)
425437
permission_classes = (ApiKeyHeaderPermissionIsAuthenticated,)
@@ -492,9 +504,12 @@ def get(self, request, course_id=None, username=None):
492504
class UserRolesView(StandardizedErrorMixin, APIView):
493505
"""List the current user's course-level roles."""
494506

507+
# ADR 0034 — JWT + cross-domain session (BearerAuthenticationAllowInactiveUser
508+
# removed per OEP-0042). EnrollmentCrossDomainSessionAuth retained because the
509+
# endpoint must accept cross-domain Studio/LMS CSRF-validated session cookies;
510+
# the platform-default SessionAuthentication would reject those.
495511
authentication_classes = (
496512
JwtAuthentication,
497-
BearerAuthenticationAllowInactiveUser,
498513
EnrollmentCrossDomainSessionAuth,
499514
)
500515
permission_classes = (ApiKeyHeaderPermissionIsAuthenticated,)
@@ -644,9 +659,12 @@ def get(self, request, course_id=None):
644659
class EnrollmentsAdminListView(StandardizedErrorMixin, ListAPIView):
645660
"""Admin-only paginated enrollment list with OEP-68 filter aliases."""
646661

662+
# ADR 0034 — JWT + cross-domain session (BearerAuthenticationAllowInactiveUser
663+
# removed per OEP-0042). EnrollmentCrossDomainSessionAuth retained because the
664+
# endpoint must accept cross-domain Studio/LMS CSRF-validated session cookies;
665+
# the platform-default SessionAuthentication would reject those.
647666
authentication_classes = (
648667
JwtAuthentication,
649-
BearerAuthenticationAllowInactiveUser,
650668
EnrollmentCrossDomainSessionAuth,
651669
)
652670
permission_classes = (permissions.IsAdminUser,)

0 commit comments

Comments
 (0)