We want to create a "reviewer" role that doesn't have permissions to actually edit anything. This role would be able to view unpublished content as well as published content.

This works in Drupal by giving the user the permission, "view content revisions," but unfortunately the Workbench Moderation permissions functions override the revisions behavior and prevent these users from viewing "drafts" that are moderated by Workbench Moderation.

I have found a solution to this problem by modifying the function as shown below. The function is only called once and only called in the "view draft" mode. The problem is that the current workbench function used checks to see if the user can also edit the content, which I don't feel in necessary to view it.

function _workbench_moderation_access_current_draft($node) {

  // This tab should only appear for node types under moderation
  if (!workbench_moderation_node_type_moderated($node->type)) {
    return FALSE;
  }

  $state = $node->workbench_moderation;
  #return (_workbench_moderation_access('view revisions', $node)
  return (user_access('view revisions')
      && !empty($state['published'])
      && $state['published']->vid != $state['current']->vid);
}

This is only called here:

function workbench_moderation_menu() {
  $items = array();

  // View the current draft of a node.
  $items["node/%node/draft"] = array(
    'title' => 'View draft',
    'page callback' => 'workbench_moderation_node_view_draft',
    'page arguments' => array(1),
    'access callback' => '_workbench_moderation_access_current_draft',
    'access arguments' => array(1),
    'file' => 'workbench_moderation.node.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => -9,
  );

  return $items;
}

Attached in the next comment is a patch for this single line change.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

damontgomery’s picture

Here is the patch described above. (Sorry, named the patch incorrectly since I thought it would be comment #2.)

Status: Needs review » Needs work

The last submitted patch, workbench_moderation-view-drafts-permission-fix-1461950-2.patch, failed testing.

damontgomery’s picture

Ok, I had the wrong relative directory. Here goes!

damontgomery’s picture

Status: Needs work » Needs review
Vc Developer’s picture

Sub.......

ricardo_reyes’s picture

ricardo_reyes’s picture

Could this patch also resolve the issue for the drafter role? [the dafter role is the node creator]
Right now, the drafter role (user) in my system does not show the My Drafts tab. Any ideas as to why it would not be displaying it?

Also, the Use "My Drafts" workbench tab permission is checked for that Role in the Drupal permission settings.

damontgomery’s picture

Rico6xRico, I'm not sure about your issue.

------------------

I have updated the patch since there is a new version of Workbench Moderation. This works with version 7.x-1.2.

Devin Carlson’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

#8 works for me.

Going through the code, I agree that _workbench_moderation_access() is too restrictive.

apemantus’s picture

Tried patch in #8 as I needed people to have access to view drafts but not edit them. Works great as far as I can tell.

markie’s picture

FileSize
667 bytes

I am a huge fan of drupal_alter for a solution. See patch.

damontgomery’s picture

Can you explain what's happening in #11? It's beyond me right now.

markie’s picture

Instead of just returning the access, I set it to a variable $access. Then I set up a hook using the drupal_alter. This way, people can create a function HOOK_workbench_moderation_draft_access(&$access, $op, $node) which modifies $access they need to perform. Then that adjusted $access is returned.

$access = (_workbench_moderation_access('view revisions', $node)
       && !empty($state['published'])
       && $state['published']->vid != $state['current']->vid);
      
$op = 'draft';
drupal_alter('workbench_moderation_draft_access', $access, $op, $node);
 
return $access;
John Pitcairn’s picture

Because this is a drupal_alter() call, wouldn't the altering module need to implement hook_workbench_moderation_draft_access_alter(&$access, $op, $node) ?

markie’s picture

That is correct, sir

markie’s picture

That is correct, sir

</copy>

damontgomery’s picture

Ok, I believe the workbench moderation module added the alter hook and I built a little module myself to specify my draft access permissions as described by markie.

I believe we can close this issue. I'm going to look for my code on Monday and leave a comment in case anyone stumbles across this thread and wants some help.

damontgomery’s picture

Status: Reviewed & tested by the community » Fixed

Ok, here is the hook I used in place of my patch above. I don't believe you can put this in the theme template.php, but you can make a new module or put it inside another.

function MY_MODULE_workbench_moderation_access_alter(&$access, $op, $node) {

  if ($op == 'view revisions' && user_access('view revisions')){
    $access = TRUE;
  }

}

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

iamEAP’s picture

Status: Closed (fixed) » Reviewed & tested by the community

#18 is a good workaround, but is not really a "fix."

Moving back to RTBC so a patch can be committed.

ginosuave’s picture

[removed]

colan’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

It's not clear what's being RTBCed here, #11? If so, there is some extra whitespace in there that needs to be removed.

markie’s picture

@colan: Yes, #11 would be RTBC. Can you be more descriptive on the white space? Are you talking about lines 10 - 12? Would you like it to be all on one line? Seems like a long line which is why I broke it up.

colan’s picture

Status: Postponed (maintainer needs more info) » Needs work
+++ b/workbench_moderation.module
@@ -575,9 +575,14 @@ function _workbench_moderation_access_current_draft($node) {
+      ¶
+  $op = 'draft';
+  drupal_alter('workbench_moderation_draft_access', $access, $op, $node);
+  ¶

The first and last lines have additional whitespace characters. These should just be blank lines. The length is fine.

ben.bunk’s picture

Can someone help me understand why the patch is needed? I just implemented hook_workbench_moderation_access_alter() and had no problem seeing drafts. Here is the code:

/**
 * Implements hook_workbench_moderation_access_alter().
 */
function finra_org_workbench_moderation_access_alter(&$access, $op, $node) {
  if ($op == 'view revisions' && user_access('view revisions')) {
    $access = TRUE;
  }
  else {
    // Don't touch anything.
  }
}
markie’s picture

Status: Needs work » Needs review
FileSize
661 bytes

@colan: Attached is a new patch with the errant whitespace removed.

@ben.bunk: This adds the ability to alter the access point on the current draft, which is not present at this time. Adding to your example:

<?php
/**
 * Implements hook_workbench_moderation_access_alter().
 */
function finra_org_workbench_moderation_access_alter(&$access, $op, $node) {
  if ($op == 'view revisions' && user_access('view revisions')) {
    $access = TRUE;
  }
  elseif ($op == 'draft') {
     // Unicorns.
  }
  // Else not needed if nothing is happening.
}
?>
markie’s picture

FileSize
659 bytes
leahtard’s picture

If anyone else comes across this post, the "View moderation history" permission made the View Drafts tab available for me.

Cheers, Leah

delacosta456’s picture

hi i on my one side instead of patch, this module https://www.drupal.org/project/view_unpublished (providing a "View any unpublish of [type]") has help