Unpublished nodes not included even when option is selected if there are node_grants implementations

Created on 22 April 2019, over 5 years ago
Updated 16 May 2024, 8 months ago

Problem/Motivation

The current logic for allowing unpublished nodes to display in the Linkit autocomplete will not respect the "Include unpublished nodes" setting if there are any implementations of hook_node_grants() in the codebase:

    if ($this->configuration['include_unpublished'] == FALSE) {
      $query->condition('status', NodeInterface::PUBLISHED);
    }
    elseif (!$this->moduleHandler->hasImplementations('node_grants')) {
      if (($this->currentUser->hasPermission('bypass node access') || $this->currentUser->hasPermission('view any unpublished content'))) {
        // User can see all content, no check necessary.
      }
      elseif ($this->currentUser->hasPermission('view own unpublished content')) {
        // Users with "view own unpublished content" can see only their own.
        if ($this->configuration['include_unpublished'] == TRUE) {
          $or_condition = $query
            ->orConditionGroup()
            ->condition('status', NodeInterface::PUBLISHED)
            ->condition('uid', $this->currentUser->id());
          $query->condition($or_condition);
        }
      }
    }
    else {
      // All other users should only get published results.
      $query->condition('status', NodeInterface::PUBLISHED);
    }

This is not immediately obvious to people trying to use the "Include unpublished nodes" option, and might better be handled by a dedicated permission.

πŸ› Bug report
Status

Needs work

Version

7.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Kasey_MK

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024