I'm not sure anyone else is seeing this, but on our project, views suddenly stopped respecting the rights given by the module view_unpublished on the permissions page. We are using the filter "published or admin" on all our views, and previously it respected rights given through the view_unpublished module.

I am unsure however if this has started when we upgraded these last two times to 6.x-2.10 or what is causing this. I am opening this as a support request in a hope that someone else is seeing this and so we can perhaps troubleshoot this together.

As it is right now, I am pretty hopeless on this issue, I don't see the published or admin filter changed since we started the project, and neither has the module view_unpublished.. I even tried downgrading core to the last version in hope that that a change in core was causing this.

Any pointers are extremely welcomed. Our publishers need to see how the nodes will look in section listings before going published, and I really don't feel comfortable granting the administer nodes permission to them.

Comments

merlinofchaos’s picture

I don't know how the view_unpublished module works or what the permissions on it actually *are* or what would be different if using that module, so it's difficult for me to provide any guidance. Will need more details.

dawehner’s picture

Project: Views (for Drupal 7) » View Unpublished
Version: 6.x-2.10 » 6.x-1.x-dev

views never respected view_unpublished, or the other way round.

Doing something like this with hook_perm and menu item access callback, cannot integrate with views.
There is the need of hook_node_grants to achieve this, OR write a custom views handler.

manuel garcia’s picture

Project: View Unpublished » Views (for Drupal 7)
Version: 6.x-1.x-dev » 6.x-2.10

Thanks for the quick reply!

The module is reaaaly simple, it consists of 50 lines including comments:

/**
 * @file
 * Allow users to view all unpublished nodes, or unpublished nodes
 * of a specific type.
 */
 
/**
 * Implementation of hook_perm().
 *
 * Adds a global 'view all unpublished content' permission and also
 * a new permission for each content type.
 */
function view_unpublished_perm() {
  $perms = array('view all unpublished content');

  foreach (node_get_types() as $type => $name) {
    $perms[] = 'view unpublished ' . $type . ' content';
  }
 
  return $perms;
}

/**
 * Implementation of hook_menu_alter().
 *
 * Modifies the path node/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);
}

/**
 * Returns true if the user has 'view all unpublished content' or if
 * they have the permission corresponding to the node's content type.
 */
function _view_unpublished_node_access($node) {
  // Only check permissions on nodes that are unpublished.
  if ($node->status == 0) {
    if (user_access('view all unpublished content')) {
      return TRUE;
    }

    if (user_access('view unpublished ' . $node->type . ' content')) {
      return TRUE;
    }
  }
  
  // If none of the above conditions were satisfied, then use node_access like normal.
  return node_access('view', $node);
}

The module works, I mean if a publisher with the permission "View all unpublished content" goes to see an unpublished node, he can view it fine. But views listing this node will remove it if the user is not 1 (using the published or admin filter). This wasn't the case before, so something must be causing this.

I have checked the filter published or admin code, and it hasn't changed at all since the first views version we started to build this site with, so I am really at a loss here, cant see what could be causing this or how to go about troubleshooting.

dawehner’s picture

Project: Views (for Drupal 7) » View Unpublished
Version: 6.x-2.10 » 6.x-1.x-dev

It did not respect the permission. See my above comment. I cannot guess, why you thought it did.

Views generall does not integrate with other contrib module. Views is such extendable that the contrib module can make views working as it should.

manuel garcia’s picture

Project: View Unpublished » Views (for Drupal 7)
Version: 6.x-1.x-dev » 6.x-2.10

Oops Dereine, I think we were replying at the same time -- sorry!

OK, so humm... i remember our publishers being able to see these content before, ... X file?

I see waht you mean, although I am not familiar with this side of drupal code. I know there is an issue opened about this on the view_unpublished queue, #606516: View own unpublished content and respect module_grants - though I have tested it and unfortunately the problem did not go away. I am not knowledgeable enough to review the patch properly so I guess we are stuck for now until that gets worked on properly... and the module mantainer shows up :X

Thanks guys for the quick info, really appreciate it!

manuel garcia’s picture

Project: Views (for Drupal 7) » View Unpublished
Version: 6.x-2.10 » 6.x-1.x-dev

cross posted again sorry

merlinofchaos’s picture

The filter in Views specifically checks the administer nodes permission. In order for view_unpublished to work, it would need to provide a replacement for this filter. It can do this using hook_views_data_alter().

I can't imagine how it ever works if view_unpublished was not providing a replacement. The filter in question is quite specific.

manuel garcia’s picture

Title: Views no longer respect view_unpublished permission grants » Integration with views.
Assigned: Unassigned » manuel garcia
Category: support » feature

Yes, this is correct merlin, thanks.

Dereine spent some time helping me doing just that last night, and we managed. I will clean it up and provide an initial patch for view_unpublished as soon as I can.

chaloalvarezj’s picture

I think this is a great module and would like to use it, but not being able to use views would make it hard to use.
Any news with the initial patch?

manuel garcia’s picture

Status: Active » Needs review
StatusFileSize
new1.74 KB

OK, the project is now live (you can check it out if you want at www.hobbynews.es), and is time to give back to the community, so we all prosper and conquer the world =)

Find attached the module that implements preliminary this integration. Keep in mind that we only use the "View all unpublished content" permission, so this is what we needed only. The module only takes over the query for view unpublished or admin filter, and takes into account this permission.

So there's not much to it, you just enable the module, and that permission will work with this filter automatically, nothing else to do.

It's a start, and I hope it will get in the module sometime. Feel free to discuss whether or not to put this as a separate module, and how to go about implementing this for the rest of permissions per content type.

BIG thanks to dereine for helping me get through the views maze without loosing my head too much, on a sunday night -> Big respect!

chaloalvarezj’s picture

Gracias!!
Will post later when I start using this module..

entendu’s picture

Right on guys, I'll take a look at this rolling this out over the weekend.

amclin’s picture

Any progress on this? Because without views integration, this module is pretty useless for all but the simplest of scenarios.

westie’s picture

Tested patch@#10 and seems to work fine for me. Can we get this included in the next module release?

gooddesignusa’s picture

subscribing

1timer’s picture

sub

manuel garcia’s picture

Status: Needs review » Reviewed & tested by the community

Just a heads up... my code has been used in production for hobbynews.es for nearly a year now. Working fine.

dddave’s picture

+1

Just tested the module in #10. Desperately needed to make this great module really useful. Thanks Manuel!

Perhaps you could try to contact the maintainer directly. It seems the maintainer hasn't revisited this module in a long time.

entendu’s picture

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

Adding this to the 6x branch. Nice work, Manuel!

Note on this: you have to use the "Published or Admin" filter in Views to make it work, and this only works for the "View all unpublished" permission, no support yet for the per-content-type permissions.

pumpkinkid’s picture

Weird... I just went through the same train of thought as the OP... I too could have sworn this had been working...

Either way, I could really use the functionality for the specific content types... Any idea when this might be fixed or anything specific you need help with to make this work?

Thanks!

jdln’s picture

Subscribing.

filiptc’s picture

Need support for the per-content-type permissions very, very (very) badly... Subscribing =)

EDIT: OK, here's a loophole if you are as desperate as me and only have one content type you're struggling with on this. Open view_unpublish.module, go to line 85 and find 'view all unpublished content'. Replace it by 'view unpublished XXXXXXXXX content', where XXXXXX is the machine readable content type name. That's all, should work right out of the box with this tweak.

hanoii’s picture

Title: Integration with views. » Integration with views - adding per-content type support
Status: Closed (fixed) » Needs review
StatusFileSize
new1.75 KB

Attached is a patch for a per content-type support.

manuel garcia’s picture

I haven't had time to test out the patch, but the code looks good to me, thanks hanoii!

Can anyone test it out properly please so we can set this to rtbc ?

BenK’s picture

Subscribing

ts145nera’s picture

subscribe
There's a port to D7?

perlgal’s picture

I tested the patch in #23 and it works like a charm!

Thank you hanoii!

manuel garcia’s picture

Status: Needs review » Reviewed & tested by the community
pcambra’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
StatusFileSize
new1.67 KB

And here's the port for D7.

I think this one and #23 should get committed asap.

pcambra’s picture

StatusFileSize
new2.69 KB

Oops I'd missed the views handler

manuel garcia’s picture

Status: Reviewed & tested by the community » Needs review
bforchhammer’s picture

From a quick test, the patch in #30 seems to be doing what it's supposed to... RTBC?

manuel garcia’s picture

Status: Needs review » Reviewed & tested by the community

Code makes sense to me.

Imho:

  • #23 is ready to be committed to the 6.x-1.x branch.
  • #30 is ready to be committed to the 7.x-1.x branch.
seattlehimay’s picture

Can I ask what *exactly* it is supposed to do? I have installed the patch (#30) and cleared caches.

I have a set of "unpublished resource centers" that I want to display in a view-created block to anyone that has "Resource Center: View any unpublished content" permission. This piece does not work for me. (The block appears fine, but with no results.)

If I give these users "view any unpublished content," then it will show the block with correct content--but I really don't want to give them access to *all* unpublished content.

entendu’s picture

#30 is committed to the 7x-dev branch.

entendu’s picture

Assigned: manuel garcia » entendu
entendu’s picture

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

#23 is committed to 6.x branch.