Added 'view own unpublished content' permission and save old access callback so that we call this one (for example in case module_grants has already altered it). Since module_grants doesn't do this (it is a replacement for node_access), we have to make sure that the view_unpublished module runs after module_grants. Hence the .install file.

Comments

jvanprehn’s picture

StatusFileSize
new2.57 KB

Rolled a .patch file.

izmeez’s picture

I have just run some tests on the view_unpublished module with this patch and it seems to be working.

The big problem I find is that there is no easy way for the users to see their unpublished content.

If they go directly to the url they can view and edit the unpublished post but not change the Publishing options unless they have admin privileges, as expected.

Here is an example of the difficulties users have in finding the unpublished posts. If the users have permission to view their own unpublished blog content and then they go to their blog page they do not see the teaser of the unpublished blog along with teasers of published blog posts. I can appreciate that this may have more to do with the blog module, but the same issue arises with other content types such as forum posts.

Even constructing a View may not work as the filters are for "published or admin" and these users are not being granted admin privileges.

If there is a way to solve this it would be fantastic.

Thanks for the efforts so far with this module and the patch.

Izzy

jvanprehn’s picture

Instead of using _view_unpublished_node_access, this would require implementing hook_node_grants and hook_node_access_records and using the module module_grants. If you haven't found another solution meanwhile, I'll roll a patch for this module.

jvanprehn’s picture

In this patch hook_node_grants and hook_node_access_records are implemented. I had to make a grant for providing access to published content, since the 'all' grant is not set when some module configures the grants.

This patch was tested with views. I made a view for displaying Blog posts of the user with uid (provided as argument). I created three users (and three roles for configuring the permissions):
- User1 has permissions to view his own unpublished content.
- User2 has permissions to view his own unpublished content.
- User3 has permissions to view unpublished blog content

Then I created some Blog entries:
- User1 creates two Blog entries (one published and one unpublished)
- User2 creates two Blog entries (one published and one unpublished)

I checked that:
- Anonymous users can only see the published Blog entries when accessing the view
- User1 can see his published and unpublished Blog entries
- User2 can see his published and unpublished Blog entries
- User3 can see the published and unpublished Blog entries by User1 and User2
- User1 can only see the published Blog entries of User2

So my approach when solving the blog post issue is to provide an own view instead of using the one provided by the blog module as I did above (since the blog module explicitly checks in the query if the node is published).

In the views I don't set the 'published' filter anywhere. Instead I rely on the permission system (which automatically alters the views queries; see node_db_rewrite_sql). It could be that this results in duplicate results when for example a grant is specified for viewing unpublished blog entries and for viewing own unpublished content. In these cases I set the 'filter duplicates' flag of the view.

manuel garcia’s picture

Well, the patch seems to do as advertised.

I cant however get this module to work with views any longer, not sure whether the last two updates on views has caused the trouble or what is going on, so I wont blame this patch for not working with views lists either.

izmeez’s picture

EDIT Sorry I didn't read the messages correctly before so I just deleted the message.

physiotek’s picture

cant make it work... tried both #1 and #4
is it possible to add it to the official release please?
thanks a lot!
pht3k

szantog’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new11.77 KB

Sorry for my english.
I've installed and tested this patch.
I'needed a small moderation workflow with rules and flag. It worked with my own content types, receipe and humor. A user can post his recipe, a rules make it unpublished, and only the user, and the content manager with view all unpublished content role can see this post.
I made a view too, when the users can see all of his unpublished and published contents too - it works perfect.

I attach the patched modul.

cyberwolf’s picture

Subscribing.

Akela’s picture

First of all, thank you very much for making the changes to View Unpublished.

I used the last file, but I now have a problem with the "unpublish" option giving my regular users access denied errors.

I am using Content Unpublish module.

webservant316’s picture

I also need this feature. I am using the scheduler module to allow user to schedule the publishing and unpublishing of classified ads. However, if they schedule the publishing and unpublishing they have no access to their node after they create it until it is published and then no access after it is unpublished.

It seems to me that CORE ought to allow a permission for user to view /edit their own unpublished content (perhaps by content type) in the tracker tab within their profile. It seems like this module is headed in that direction. Is this module production ready? Looks like some bugs are still being worked out.

Also is this module the best option to achieve my goal at this point?

Also is their plans to include this feature in Drupal CORE? Seems like a basic need that ought to be handled by the CORE permission module.

Jeff

patator’s picture

a very useful option - view own unpublished content
subscribe

jvanprehn’s picture

@Akela can you describe how to get to this error from a clean drupal 6 installation (tell me which version of core)? If I can reproduce the access denied errors, I can try to work out why this happens.

entendu’s picture

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

I've implemented the install file and the access callback affinity. "View own unpublished content" is actually handled already by core (see node_access()).

I have ignored the hook_node_grants for now since it would require a node access rebuild which I don't think anyone really wants to do.

Thanks everyone!

ryan_courtnage’s picture

fyi - there were some issues with this commit. For myself, I found that I was getting Access Denied errors when trying to view nodes. See #1180572: Access Denied due to incorrect menu "access callback"