How do I write the following Drupal 8 EntityQuery so that it only returns nodes that the current user has access to?
$query = \Drupal::entityQuery('node') ->condition('type', 'article');
The above query will return all nodes, even unpublished ones. Depending on how you use the results (like a list of nodes), users could see titles or other information from unpublished nodes.
$query = \Drupal::entityQuery('node') ->condition('type', 'article') ->condition('status', 1);
When I add the "status" condition, I now get a list of only published nodes. But I would like people with administer nodes permission to see all the nodes.
Basically, is there a way to simulate the "admin or published" filter, like on Views?