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.
Comment | File | Size | Author |
---|---|---|---|
#27 | draft_access-1461950-26.patch | 659 bytes | markie |
#11 | draft_access-1461950-11.patch | 667 bytes | markie |
#8 | workbench_moderation-view-drafts-permission-fix-1461950-8.patch | 508 bytes | damontgomery |
#7 | Screen Shot 2012-07-27 at 4.58.01 PM.png | 11.65 KB | ricardo_reyes |
#7 | Screen Shot 2012-07-27 at 4.56.13 PM.png | 19.02 KB | ricardo_reyes |
Comments
Comment #1
damontgomery CreditAttribution: damontgomery commentedHere is the patch described above. (Sorry, named the patch incorrectly since I thought it would be comment #2.)
Comment #3
damontgomery CreditAttribution: damontgomery commentedOk, I had the wrong relative directory. Here goes!
Comment #4
damontgomery CreditAttribution: damontgomery commentedComment #5
Vc Developer CreditAttribution: Vc Developer commentedSub.......
Comment #6
ricardo_reyes CreditAttribution: ricardo_reyes commentedComment #7
ricardo_reyes CreditAttribution: ricardo_reyes commentedCould 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.
Comment #8
damontgomery CreditAttribution: damontgomery commentedRico6xRico, 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.
Comment #9
Devin Carlson CreditAttribution: Devin Carlson commented#8 works for me.
Going through the code, I agree that
_workbench_moderation_access()
is too restrictive.Comment #10
apemantus CreditAttribution: apemantus commentedTried 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.
Comment #11
markie CreditAttribution: markie commentedI am a huge fan of drupal_alter for a solution. See patch.
Comment #12
damontgomery CreditAttribution: damontgomery commentedCan you explain what's happening in #11? It's beyond me right now.
Comment #13
markie CreditAttribution: markie commentedInstead 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.
Comment #14
John Pitcairn CreditAttribution: John Pitcairn commentedBecause this is a drupal_alter() call, wouldn't the altering module need to implement hook_workbench_moderation_draft_access_alter(&$access, $op, $node) ?
Comment #15
markie CreditAttribution: markie commentedThat is correct, sir
Comment #16
markie CreditAttribution: markie commentedThat is correct, sir
</copy>
Comment #17
damontgomery CreditAttribution: damontgomery commentedOk, 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.
Comment #18
damontgomery CreditAttribution: damontgomery commentedOk, 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.
Comment #20
iamEAP CreditAttribution: iamEAP commented#18 is a good workaround, but is not really a "fix."
Moving back to RTBC so a patch can be committed.
Comment #21
ginosuave CreditAttribution: ginosuave commented[removed]
Comment #22
colanIt's not clear what's being RTBCed here, #11? If so, there is some extra whitespace in there that needs to be removed.
Comment #23
markie CreditAttribution: markie commented@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.
Comment #24
colanThe first and last lines have additional whitespace characters. These should just be blank lines. The length is fine.
Comment #25
ben.bunk CreditAttribution: ben.bunk commentedCan 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:
Comment #26
markie CreditAttribution: markie commented@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:
Comment #27
markie CreditAttribution: markie commentedComment #28
leahtard CreditAttribution: leahtard commentedIf anyone else comes across this post, the "View moderation history" permission made the View Drafts tab available for me.
Cheers, Leah
Comment #29
delacosta456 CreditAttribution: delacosta456 commentedhi 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