Add a course permission check to ContainerChildrenView

Aperta Adatta ai principianti
#604 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Inizia in rest_api/v1/views/course_index.py, in corrispondenza di ContainerChildrenView.get(), e confronta il relativo controllo di accesso con quello di ContainerHandlerView. Aggiungi o aggiorna i test per un utente senza accesso al corso e conferma che la richiesta restituisca 403 prima che get_xblock possa creare blocchi informativi del corso. Verifica che un utente autorizzato possa ancora caricare la pagina dell’unità.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

willow
Description

ContainerChildrenView does not check course access, so any authenticated user can request a container's children. It is backend only and needs a direct API call.

Current Behavior

rest_api/v1/views/course_index.py:125 only applies view_auth_classes(is_authenticated=True). Unlike its sibling ContainerHandlerView, it never calls _get_item_in_course, so no course access check runs. This also happens with the legacy access checks, and was already the case upstream.

Expected Behavior

Only users with view access to the course can list a container's children.

Steps to reproduce

Setup

  • A course with at least one unit (vertical).
  • A user with no access to that course: authenticated, not course staff, and with no AuthZ role on it.

Steps

  1. In Studio, open any unit of the course as a user with access and copy its usage key from the URL, for example block-v1:Org+Course+Run+type@vertical+block@abc123.

  2. Log in to Studio as the user with no access to the course.

  3. Call the endpoint with that usage key (URL-encoded):

    GET /api/contentstore/v1/container/{usage_key_string}/children
    
  4. Observe the response.

Result

  • Actual: 200, with the container's children in the body.
  • Expected: 403.

For comparison, GET /api/contentstore/v1/container_handler/{usage_key_string} as the same user returns 403, because it goes through _get_item_in_course.

Acceptance Criteria
  • get() returns 403 for users without COURSES_VIEW_COURSE on the container's course.
  • The check runs before anything else in get().
  • The unit page keeps working, since container_handler already requires the same permission.
  • Tests are added or updated.
Proposed Solution

At the top of get():

if not user_has_course_permission(
    request.user, COURSES_VIEW_COURSE.identifier,
    usage_key.course_key, LegacyAuthoringPermission.READ,
):
    self.permission_denied(request)
Technical Notes

get_xblock creates course_info blocks on a GET when they do not exist (view_handlers.py:1140), so the permission check has to come before that.

Lingua principale
Python
Stelle
0
Fork
10
Merge medio
5g 9h
PR unite (30g)
24

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openedx/openedx-authz

Tutte le issue di openedx/openedx-authz

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.