Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Ensure list is limited appropriately before evaluating #886

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions code/GraphQL/FolderTypeCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ public function resolveChildrenConnection(
Connection $childrenConnection
) {
// canView() checks on parent folder are implied by the query returning $object
// Note: The inability to query permissions against the entire set means pagination
// is inaccurate when any item in the list returns false on canView()

$filter = (!empty($args['filter'])) ? $args['filter'] : [];

Expand All @@ -157,6 +159,10 @@ public function resolveChildrenConnection(
$filter['parentId'] = $object->ID;
$list = $filterInputType->filterList($list, $filter);

// Ensure that we're looking at a subset of relevant data.
$result = $childrenConnection->resolveList($list, $args);
$list = $result['edges'];

// Filter by permission
$ids = $list->column('ID');
$permissionChecker = File::singleton()->getPermissionChecker();
Expand All @@ -165,15 +171,14 @@ public function resolveChildrenConnection(
$context['currentUser']
)));
// Filter by visible IDs (or force empty set if none are visible)
$list = $list->filter('ID', $canViewIDs ?: 0);
// Remove the limit as it no longer applies. We've already filtered down to the exact
// IDs we need.
$canViewList = $list->filter('ID', $canViewIDs ?: 0)
->limit(null);

// Apply pagination
$return = $childrenConnection->resolveList(
$list,
$args
);
$result['edges'] = $canViewList;

return $return;
return $result;
}

/**
Expand Down