The new node is published and this only happens when view unpublished is enabled.
I updated to the latest version of dev rebuilt the permissions but no luck.

I debuged the code and in node_access() in node.module on the node_access part where the query $result is FALSE

any idea any help would be appreciated.

Comments

DuaelFr’s picture

Issue summary: View changes
Status: Active » Closed (cannot reproduce)

I just tested this issue on a clean simplytest instance and I am not able to reproduce it.

fox mulder’s picture

I am not able to reproduce this problem on simplytest too, but I ran into this on a development site. My test user has access to create "A" type node, and has access to view any type unpublished node, but he/she is redirected after "A" type node creation to front page because node_access() returns FALSE.

I am using this debug code in the node_access() function:

function node_access($op, $node, $account = NULL) {
  ...
  // If the module did not override the access rights, use those set in the
  // node_access table.
  if ($op != 'create' && $node->nid) {
    if (module_implements('node_grants')) { // <-- view_unpublished implements hook_node_grants()
      ...
      $result =  (bool) $query
        ->execute()
        ->fetchField();

/**
 * Beginning of debugging
 */
$debug = debug_backtrace();
foreach ($debug as $d_index => $_debug) {
// I am using i18n module and it replaces node_form_submit() of the core node module... It is irrelevant
if ($_debug['function'] == 'i18n_node_form_submit') {
dpq($query);
dsm((int) $result, 'result');
dsm($op, 'op');
}}
/**
 * End of debugging
 */
      $rights[$account->uid][$cid][$op] = $result;
      return $result;
    }
    elseif (is_object($node) && $op == 'view' && $node->status) {
      ...

It returns:

  • SELECT 1 AS expression
    FROM
    {node_access} node_access
    WHERE (grant_view >= '1') AND( (nid = '623') OR (nid = '0') )AND(( (gid = '0') AND (realm = 'all') ))
    LIMIT 1 OFFSET 0
  • result => 0
  • op => view
  • SELECT 1 AS expression
    FROM
    {node_access} node_access
    WHERE (grant_view >= '1') AND( (nid = '623') OR (nid = '0') )AND(( (gid = '0') AND (realm = 'all') )OR( (gid = '155') AND (realm = 'view_unpublished_author') )OR( (gid = '1') AND (realm = 'view_unpublished_content') ))
    LIMIT 1 OFFSET 0
  • result => 0
  • op => view

Result is 0 and the node author is returned to front page. But if I am copying the resulted SQL queries and I am using these queries in PHPMyadmin, than the result is 1.

It's magic

Used view_unpublished version: 7.x-1.2

joelstein’s picture

I experienced this, too, and I tracked it down to modules calling node_access() within hook_node_insert(), which results in a cached access result before node_save() has a chance to acquire the node access grants. For example, XML Sitemap does this, as well as Boost when used with Cache Expiration.

So if you are using a module which calls node_access() within hook_node_insert(), and you're using some access control modules, you will likely run into this bug. This is not the fault of the View Unpublished module. It's arguably a design problem within Drupal core, but regardless, it's something that needs to be fixed within the module invoking hook_node_insert().

Or you can simply reset the static node_access cache in your own module:

/**
 * Implements hook_node_insert().
 */
function mymodule_node_insert($node) {
  drupal_static_reset('node_access');
}

See the related issues to learn more.

fox mulder’s picture

Hi Joel! Thanks for your response.

Calling drupal_static_reset('node_access') in a custom hook_node_insert() implementation does not solves the problem for me :/

fox mulder’s picture

This works:

/**
 * Implements hook_node_insert().
 */
function mymodule_node_insert($node) {
  node_access_acquire_grants($node);
  drupal_static_reset('node_access');
}