Skip to content

Update: Migrate course access check to query-time hook#202

Merged
taylortom merged 1 commit into
masterfrom
migrate-access-query-hook
May 26, 2026
Merged

Update: Migrate course access check to query-time hook#202
taylortom merged 1 commit into
masterfrom
migrate-access-query-hook

Conversation

@taylortom
Copy link
Copy Markdown
Contributor

Fixes #201

Update

  • Tap the new content.accessQueryHook to 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.
  • checkContentAccess retained on accessCheckHook for non-course content types — the parent course's _id isn't in scope at query time, so post-query filtering is still the right path there.
  • No super-user bypass needed at this level — handled centrally by New: Add accessQueryHook and remove post-query page fill adapt-authoring-api#103.

New

  • lib/utils/applyContentAccessFilter.js — pure utility that mutates a query to add the access $or, safely combining with any existing $or via $and.
  • tests/utils-applyContentAccessFilter.spec.js — unit tests covering missing userId, fresh queries, existing $or, existing $and, and key preservation.

Testing

Relates to

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.
@taylortom taylortom merged commit b50f784 into master May 26, 2026
2 checks passed
@taylortom taylortom deleted the migrate-access-query-hook branch May 26, 2026 19:13
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 3.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate course access check to query-time hook

1 participant