Make it to work in Drupal 6.
arnoldc - September 4, 2008 - 22:21
| Project: | view_unpublished |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | support request |
| Priority: | critical |
| Assigned: | dsantangelo |
| Status: | closed |
Description
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.

#1
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 :)
#2
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.
#3
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?
#4
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.
#5
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.
#6
Attached is my take on a Drupal 6 version of this module.
Changes:
Thanks!
#7
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.
#8
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')) {
#9
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.
#10
Any idea if this will be a download available for Drupal 6 any time in the near future?
#11
It is available as in message #6 of this thread. Just no one officailly moves it to the proper download section.
#12
#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 :)
#13
simpe and work great, thanks
#14
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.
#15
@garrettc: I tested your patch and it worked very well for me. Thanks!
#16
#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);
}
#17
I suggest that somebody moves to take over this apparently abandoned module.
#18
i will take over the module if need be. I will log the request tomorrow unless anyone else steps up.
#19
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.
#20
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
#21
Patch worked for me.
Thanks.
#22
I used CalebD's version: it was exactly what i needed and worked without a problem
#23
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;
}
#24
Tagged and released for D6. Thanks, CalebD!