A Drupal newbie here and need this module to work in D6.

My reason:
I need to deploy it in conjunction with Workflow module to implement a publishing cycle in D6. Currently, an user cannot view any "unpublished" node if he's not the author nor given "administer nodes" right. It is silly that an approver can access the workflow tab but no right to view the content, how does he approve a node without seeing it. I hope this module will solve my problem.

In the hand of Drupal experts, I guess this can be done quickly. Feel free to point me what do I need to modify to make it to work in D6. Thanks.

Comments

ramper’s picture

Here's one more person who would really like to see a D6 version of this module that could act like a "force multiplier" by making other modules such as workflow that much more useful :)

arnoldc’s picture

StatusFileSize
new9.3 KB

Here's my first crack to work on a Drupal module. I have tested it in conjunction with Workflow module in Drupal 6 and seem to work well.

It passes code check from Coder except the node_load() function. Coder asks me to use "menu_get_object()" but I seem to run into "infinite" loop if I try to use the new method. So I just stick with the old "node_load" method for now. May be someone has a better idea how do make it to work....

*Notes

For those new to this module, access control of this module is only applicable to those users under these conditions:

1. they have no "administer nodes" permission
2. they have "use view_unpublished module" permission

Then you can configure view unpublished permission based on content_type accordingly.

ramper’s picture

Hi arnoldc
I was excited to see your post - and immediately wanted to try out your 'first crack' :)
I installed the module as usual, made sure "administer nodes" permission was not granted, and the roles had "use view_unpublished module" permission as well as permissions for some of the content types in the workflow I'm setting up.
I still get the "Access denied" message.
I'm not sure if I'm overlooking something.
Here's my situation:
I have a workflow with states 'Draft', 'Review', etc. I need the 'view_unpublished' access for a couple of roles. I don't know what I'm overlooking here.
BTW, does this module allow only 'View', or does it allow 'Edit' as well?

arnoldc’s picture

Did you happen to download the very first attachment as soon as I made the post? I have replaced with v01 zip file since then.

Make sure all users have "access content" right. I invoke the nodes from Workflow summary. I enable "access workflow summary views" and disable "administer workflow" permission for both editor and publisher roles. You should be able to use the "create/edit/delete content" permission to refine the access right as you see fit with your own publishing cycle.

I test it with a very stock Drupal setup, may be it is influenced by other modules. I found access permission is a very tricky business in Drupal.

ramper’s picture

may be it is influenced by other modules. I found access permission is a very tricky business in Drupal.

I thought so too - I have long since disabled the other modules that could potentially interefere. I checked the workflow settings summary page - the permissions look all right (in fact they work perfectly for published nodes :) I've set the permissions for 'view_unpublished' correctly, including 'use this module'. And the roles do not have administer nodes permission. Hmm... it must be something else... So for now, I'm just going to leave the nodes published as they move through the workflow while I figure out the problem. Though it's potentially less secure that way, the workflow permissions for various states seem to be holding up - so though the nodes are published, they are not accessible except for the respective roles.
Thanks again for the reply. (To be sure, I tested again with your current zip file). If you think of any other reason why it's not working for me, I'd appreciate hearing from you.

CalebD’s picture

StatusFileSize
new6.95 KB

Attached is my take on a Drupal 6 version of this module.

Changes:

  • view_unpublished.module: Added doxygen comments for functions.
  • view_unpublished.module: Removed the permission 'use view_unpublished module' because it becomes meaningless, see below.
  • view_unpublished.module: Refactored view_unpublished_perm to use node node_get_types().
  • view_unpublished.module: Removed view_unpublished_menu() in favor of view_unpublished_menu_alter().
  • view_unpublished.module: Renamed _my_access() to _view_unpublished_node_access() to prevent any potential namespace collisions.
  • view_unpublished.module: Added logic check for $node->status == 0 in the access function to see if the node we're testing is actually unpublished, as that is the purpose of this module. Its logic shouldn't apply to published nodes.
  • view_unpublished.module: Removed permissions check against 'administer nodes' in the access function.
  • view_unpublished.module: Removed logic using 'use view_unpublished module' permission in the access function, see next line.
  • view_unpublished.module: Return the value of node_access('view', $node) in the access function if the view all unpublished content permission or content type permission don't pass. This allows the module to work as an extension to node_access, rather than completely replacing it. Other modules that implement access tables or other access methods will still work (if it is through node_access).
  • view_unpublished.install: Removed the file. It is no longer necessary to set the module weight when using hook_menu_alter().
  • view_unpublished.info: Adjusted the description of the module.
  • README.txt: Updated content to reflect the way the module works and added my credit.

Thanks!

Dab-1’s picture

Well done mate!

Testing this currently in conjunction with workflow and no other access modules to implement a simple reviewing system. Works fine, at first glance. Will comment on any issues.

arnoldc’s picture

Good job, Caleb. Simple and elegant. Work great with Workflow. You should consider to create a D6 branch for it.

Pass Coder except really minor stuff.

view_unpublished.module

    *
      severity: normalLine 19: string concatenation should be formatted without a space separating the operators (dot .) and a quote

          $perms[] = 'view unpublished ' . $type . ' content';

    *
      severity: normalLine 46: string concatenation should be formatted without a space separating the operators (dot .) and a quote

          if (user_access('view unpublished ' . $node->type . ' content')) {
suydam’s picture

CalebD, this is a great module! You really should consider getting CVS access and committing this.
Maybe there's some other way to do it, but I've not seen one and this appears to work great.

slosa’s picture

Any idea if this will be a download available for Drupal 6 any time in the near future?

arnoldc’s picture

It is available as in message #6 of this thread. Just no one officailly moves it to the proper download section.

scottrigby’s picture

#6 works really well - nice! Only problem is this doesn't display in views lists, even if you have permissions (because the only available filter for viewing unpublished content in Views now is 'published or admin'). This module could provide a views filter however, and then it could work :)

michaelj’s picture

simpe and work great, thanks

garrettc’s picture

Status: Active » Needs review
StatusFileSize
new5.32 KB

I've created a patch against the most recent 5.x release using CalebD's work. I also took the opportunity to fix the Coder issues regarding string concatenation.

mutzel’s picture

@garrettc: I tested your patch and it worked very well for me. Thanks!

i.chris.jacob’s picture

#6 CalebD - works perfectly! However I did make a minor change to allow for commenting against unpublished nodes. Note: If you use this code I suggest using 'Flush all caches' in the module Administration Menu (http://drupal.org/project/admin_menu) - otherwise the new Menu Alter will not take effect.

Change made in view_unpublished.module replaces the existing function: function view_unpublished_menu_alter(&$items)

/**
* Implementation of hook_menu_alter().
*
* Modifies the path node/nid to use our access callback.
* Modifies the path comment/reply/nid to use our access callback.
*/
function view_unpublished_menu_alter(&$items) {
$items['node/%node']['access callback'] = '_view_unpublished_node_access';
$items['node/%node']['access arguments'] = array(1);
$items['comment/reply/%node']['access callback'] = '_view_unpublished_node_access';
$items['comment/reply/%node']['access arguments'] = array(2);
}

killes@www.drop.org’s picture

I suggest that somebody moves to take over this apparently abandoned module.

a_c_m’s picture

i will take over the module if need be. I will log the request tomorrow unless anyone else steps up.

lelizondo’s picture

Status: Needs review » Reviewed & tested by the community

more than 3 users said this is working, I think it should be moved to the next status.. If someone takes over the project, please tell us what's the new name so we can receive updates from update_status.

As the original post said, workflow should include this by default.

bartezz’s picture

Thanx for this CalebD and others, I was looking for a D6 version and will give this a go.
Would be nice to see it as an official D6 branch though.

Big Thumbs Up
Cheers

NaX’s picture

Category: support » feature
Priority: Normal » Critical

Patch worked for me.
Thanks.

borisbarowski’s picture

I used CalebD's version: it was exactly what i needed and worked without a problem

christefano’s picture

Category: feature » support
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new4.37 KB

The patch shouldn't delete the install file as it should be removed using CVS instead. There are a few lines in the info file that should be left alone since they're written by the package release system. I'm sorry to kick this back to "needs review" but it needs a simple retest.

Also, can the code change that's proposed in #16 please be considered after the Drupal 6 upgrade? That would actually necessitate an install file and we can require a visit to update.php at a later time to run something like this:

function view_unpublished_update_6000() {
  $ret = array();
  menu_cache_clear_all();
  drupal_set_message(t("The menu cache has been cleared."));
  return $ret;
}
entendu’s picture

Assigned: Unassigned » entendu
Status: Needs review » Closed (fixed)

Tagged and released for D6. Thanks, CalebD!

rstuker’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev

Sorry to be negative, but i cant make it work. I use D6.15 & postgres. In my permission admin i give to users of a rol the permission "view all unpublished content" and another of "view all contentX type" permission. I make sure no to give them "administer nodes" allowance. But, where the user who has permission to see unpublish content, can make the search, no option in menu appears for him to find that content. I may have missed something, i do apreciate any help.
pd= I dont use workflow module, use TAC and Content Access. Thanks. The version I user is 6.x

hixster’s picture

Just wondering if the fix for comments from post #16 will be committed? Should the module expose some permission for commenting on unpublished content types too?