Skip to content

New: Add accessQueryHook and remove post-query page fill#103

Merged
taylortom merged 2 commits into
masterfrom
add-access-query-hook
May 26, 2026
Merged

New: Add accessQueryHook and remove post-query page fill#103
taylortom merged 2 commits into
masterfrom
add-access-query-hook

Conversation

@taylortom
Copy link
Copy Markdown
Collaborator

Fixes #102

New

  • accessQueryHook — invoked after requestHook and before setUpPagination, allowing observers to merge access-control clauses into req.apiData.query. Fires from both requestHandler (non-GET) and queryHandler (paginated reads), so pagination counts (X-Adapt-PageTotal, Link) reflect the filtered query.

Fix

  • Reverted the post-query fill-the-page block in queryHandler. It had two latent bugs (skip drift on subsequent pages, over-fill slice dropping records) and produced an infinite re-fetch loop on the dashboard when combined with any accessCheckHook observer that filters. With observers migrated to accessQueryHook, fill-the-page is unnecessary.
  • accessCheckHook JSDoc updated to flag it as a safety net for non-queryable checks; filtering callers should move to accessQueryHook.

Testing

  • npm test — 62/62 pass
  • npx standard — clean
  • Behavioural verification lives in the follow-up PRs to adapt-authoring-multilang and adapt-authoring-adaptframework, which exercise the new hook end-to-end on the dashboard.

taylortom added 2 commits May 26, 2026 20:05
Adds a new content access hook that runs before find() so observers can
merge access-control clauses into req.apiData.query. This keeps mongo
skip/limit exact, pagination counts accurate, and avoids the need to top
up short pages.

Reverts the fill-the-page logic in queryHandler: with observers filtering
at query time, the mechanism is unnecessary; it also had skip-drift and
over-fill bugs that caused infinite re-fetch loops on the dashboard when
combined with multilang/adaptframework access checks.

accessCheckHook is retained for checks that cannot be expressed as
queries, but is now documented as a safety net rather than the filtering
path.
Mirrors the existing super-user bypass in checkAccess so query-time
access mutations don't filter dashboards or other queries for super
users.
@taylortom taylortom force-pushed the add-access-query-hook branch from 80758a2 to 5cba2df Compare May 26, 2026 19:06
@taylortom taylortom merged commit d1578c5 into master May 26, 2026
2 checks passed
@taylortom taylortom deleted the add-access-query-hook branch May 26, 2026 19:10
github-actions Bot pushed a commit that referenced this pull request May 26, 2026
# [3.7.0](v3.6.3...v3.7.0) (2026-05-26)

### New

* Add accessQueryHook and remove post-query page fill (#103) ([d1578c5](d1578c5)), closes [#103](#103)
* Add accessQueryHook and remove post-query page fill (fixes #102) ([43cd4fb](43cd4fb)), closes [#102](#102)

### Update

* Skip accessQueryHook for super users (refs #102) ([5cba2df](5cba2df)), closes [#102](#102)
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 3.7.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.

Pagination breaks when accessCheckHook filters results

1 participant