Commit 4975d85
committed
fix(vue/documents): force cid/sid/gid on POST /api/documents
The shared axios request interceptor in assets/vue/config/api.js reads
getRawCourseContext() from window.location.search and injects cid/sid/gid
into config.params. When the SPA navigates inside a course without
preserving ?cid=… in the URL, that read returns nulls, no params are
injected, and the POST goes out as plain /api/documents (no query).
On the server side, CidReqListener sees an empty $request->get('cid'),
treats the request as out-of-course, and calls cleanSessionHandler()
which removes session.course. CreateDocumentFileAction then runs
buildResourceLinkListFromContext() which finds no course in session and
no cid in the query, so the resource_link entry is built without cid.
The new document is created but is orphaned — no resource_link binding it
to the course — so it disappears from the documents list immediately
after creation. The security check still passes because admins inherit
ROLE_CURRENT_COURSE_TEACHER via Symfony's role_hierarchy (security.yaml),
masking the bug for everyone with ROLE_ADMIN.
Affected: every /api/documents POST that goes through the legacy
makeService("documents").createWithFormData path — i.e. folder creation
and any flow using store.dispatch("documents/createWithFormData", …).
The chunked uploader at DocumentsUpload.vue:609 was already constructing
its own URL with explicit cid/sid/gid and is unaffected.
Surgical fix in services/documents.js:
- Override createWithFormData to construct its own POST request.
- Read cid/sid/gid from the Pinia cidReq store first (authoritative,
maintained by router guards, survives URL changes) and fall back to
getCourseContext() (URL-based) only when the store is not yet active
(early bootstrap / tests).
- Append them as query parameters on /api/documents.
Confirmed: the same code path exists on v2.0.2 and on chamilo/chamilo-lms
upstream master, so this is a community-wide bug. Forwarding it upstream
as a separate PR is on the to-do.1 parent 147e70e commit 4975d85
1 file changed
Lines changed: 47 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | 9 | | |
| |||
220 | 223 | | |
221 | 224 | | |
222 | 225 | | |
223 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
224 | 236 | | |
225 | | - | |
| 237 | + | |
226 | 238 | | |
227 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
228 | 272 | | |
229 | 273 | | |
230 | 274 | | |
| |||
0 commit comments