Update: Migrate course access check to query-time hook#202
Merged
Conversation
Taps the new `content.accessQueryHook` for course-type queries so the ownership/sharing filter is applied by mongo rather than post-query. This keeps `skip`/`limit` exact on the dashboard and removes the trigger for the infinite re-fetch loop on wide viewports. `checkContentAccess` is retained on `accessCheckHook` for non-course types (page/article/block/component), where the parent course's `_id` isn't in scope at query time. Super-user bypass is handled by the api module. Query mutation extracted to `lib/utils/applyContentAccessFilter.js` with unit tests.
|
🎉 This PR is included in version 3.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #201
Update
content.accessQueryHookto inject ownership/sharing constraints (createdBy,_isShared,_shareWithUsers) into course-type queries, so mongo returns only the courses the user can see. The dashboard infinite-fetch loop on wide viewports is removed at the same time as the multilang fix.checkContentAccessretained onaccessCheckHookfor non-course content types — the parent course's_idisn't in scope at query time, so post-query filtering is still the right path there.New
lib/utils/applyContentAccessFilter.js— pure utility that mutates a query to add the access$or, safely combining with any existing$orvia$and.tests/utils-applyContentAccessFilter.spec.js— unit tests covering missing userId, fresh queries, existing$or, existing$and, and key preservation.Testing
npm test— 156/156 passnpx standard— cleanRelates to
_accessmechanism;checkContentAccessremoval happens there.