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

ramper - September 6, 2008 - 04:00

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

arnoldc - September 8, 2008 - 22:36

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.

AttachmentSize
view_unpublished_d6_v01.zip 9.3 KB

#3

ramper - September 9, 2008 - 05:58

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

arnoldc - September 9, 2008 - 17:26

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

ramper - September 10, 2008 - 18:46

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.

#6

CalebD - September 20, 2008 - 17:37

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!

AttachmentSize
view_unpublished-6.x-2.tar_.gz 6.95 KB

#7

Dab - September 23, 2008 - 22:33

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

arnoldc - September 23, 2008 - 23:36

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

suydam - October 21, 2008 - 20:55

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

slosa - January 9, 2009 - 15:56

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

#11

arnoldc - January 9, 2009 - 18:43

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

#12

scottrigby - January 13, 2009 - 20:30

#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

jancor - January 23, 2009 - 14:23

simpe and work great, thanks

#14

garrettc - February 27, 2009 - 12:28
Status:active» needs review

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.

AttachmentSize
view_unpublished.patch 5.32 KB

#15

mutzel - April 8, 2009 - 07:20

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

#16

i.chris.jacob - April 24, 2009 - 01:53

#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

killes@www.drop.org - June 10, 2009 - 09:50

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

#18

a_c_m - July 16, 2009 - 11:26

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

#19

lelizondob - July 16, 2009 - 17:50
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.

#20

Bartezz - July 30, 2009 - 11:25

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

NaX - August 14, 2009 - 12:09
Category:support request» feature request
Priority:normal» critical

Patch worked for me.
Thanks.

#22

BorisBarowski - August 19, 2009 - 08:52

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

#23

christefano - August 29, 2009 - 23:51
Category:feature request» support request
Status:reviewed & tested by the community» needs review

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;
}

AttachmentSize
304173_view_unpublished_d6.patch 4.37 KB

#24

dsantangelo - August 30, 2009 - 19:53
Assigned to:Anonymous» dsantangelo
Status:needs review» closed

Tagged and released for D6. Thanks, CalebD!

 
 

Drupal is a registered trademark of Dries Buytaert.