Drupal 7 has a really nice 'view your own unpublished content' permission, it'll be double nice to be able to set that permission in content_access so that content owners with that permission get a 'view' grant on their own content.

Comments

markusa’s picture

Category: feature » bug

+1 With this module enabled the core 'view your own unpublished' privelege is invalidated....seems like this is a bug....although it would be nice to have this added as a feature on a per content basis

DrupalDan’s picture

I added a view to allow users to see their own nodes, including unpublished ones, but the view shows no result of my own unpublished nodes unless I submitted nodes as an admin. If I just log in as an authenticated user and submit some nodes, they won't show up in that view if not published, even though the privilege "view one's own unpublished nodes" are given to authenticated users . This problem baffles me several days and I just found it has something to do with the content access module. If it is disabled the user's unpublished nodes got shown in a view but not when the module is enabled. Hopefully this problem can be fixed soon. Thank you all.

jelle_s’s picture

A quick fix is changing

if (content_access_disabling() || !$node->status) {

to

if (content_access_disabling()) {

on line 115 of content_access.module

etron770’s picture

Its not working f.e in the workbench modules for the drafts
for views see:
http://mbharris.co.uk/content/access-control-module-prevents-view-users-...

pcho’s picture

Jelle_S,

The solution seems to work on my end, although we are going to test it further to make sure it doesn't deprecate other functionality. For now, I have encapsulated your recommendation into a patch file

wickwood’s picture

The patch in #5 works for me. Frankly I don't see why the exclusion of unpublished nodes was ever included and this problem tripped me up twice now and wasted days of time trying to figure it out.

marblegravy’s picture

Patch at #5 works as advertised in some cases.

I was trying to allow Workbench Moderation's View all unpublished content permission to work and this will allow it to function as expected For the Workbench Views only. However, it works too well for the ootb Administration Views content view and allows anyone with access to view the page the ability to see unpublished content.

For future reference, it seems that this is a known issue that will not be fixed -> #1264482: Cause and work around of user not seeing own unpublished content in views
So whatever workaround you can find that works for you is the recommended approach!

wickwood’s picture

You're right Marblegravy, it works too well! The patch in #5 also exposes unpublished content to anyone, even anonymous users, if there is no other restriction from another module.

I had created another patch for Workbench Moderation that would restricts who can view unpublished content by content type, see https://drupal.org/node/1447886#comment-7570151 for this patch.

Anyway, I was using my Workbench Moderation patch with this Content Access patch, and just discovered that this patch allows unpublished content that I'm not moderating to be visible to any and everyone.

Thanks for the reference. It is disappointing that this will not be properly fixed. If I come up with another solution, I will post back again.

hefox’s picture

Status: Active » Needs work
hefox’s picture

Status: Needs work » Needs review
StatusFileSize
new1.26 KB

Quick minimally tested patch

For further information, see #1147526: Unpublished nodes displayed to anonymous users where the !$node->status line was added to prevent the mentioned issue above

highfellow’s picture

I can confirm that the patch in #10 is working for me.

garamani’s picture

The patch #10 doesn't work for me.
I applied patch on 3 different version of content access and The user still cant see own unpublished content; however authenticated users have "View own unpublished content" access permission.

garamani’s picture

The patch #5 doesn't work neither!
I load views content via panels module. maybe my problem is not related to content access. I just want the user be able to see his/her own unpublished content.

garamani’s picture

It's weird but after removing content acceess permissions (structure>content types>your-content-type>access control) and reapplying permissions, the patch #10 WORKS!
I also unchecked the "per content node access control" checkbox.

milesw’s picture

Patch #10 worked for me, resolving the problem I had with unpublished content not appearing within Workbench.

Make sure to rebuild permissions (/admin/reports/status/rebuild) after applying the patch!

hefox’s picture

Issue summary: View changes
Status: Needs review » Needs work

Needs update operation to set that node access needs rebuild

also

+++ b/content_access.module
@@ -103,6 +103,7 @@ function content_access_admin_settings_access() {
+    'content_access_author_unpublished' => user_access('view own unpublished content', $account) && $account->uid ? array($account->uid) : array(),

$account->uid should be before user_access since it's the faster check

bkosborne’s picture

Hmm, I'm having trouble understanding the reasoning here. Looking thru the node_access function, the following code is executed before any hook_node_grants() implementations are even considered:

  // Check if authors can view their own unpublished nodes.
  if ($op == 'view' && !$node->status && user_access('view own unpublished content', $account) && $account->uid == $node->uid && $account->uid != 0) {
    $rights[$account->uid][$cid][$op] = TRUE;
    return TRUE;
  }

So how does the current version of Content Access interfere with this at all? The logic above states if a user is trying to view an unpublished node, they are the owner of the node, and they have the permission "view own unpublished content", then they will be able to view it.

milesw’s picture

@bkosborne: I think the issue here is specific to grants. With node queries (including Views), the node_access() function is not used.

bkosborne’s picture

Status: Needs work » Needs review
StatusFileSize
new1.76 KB

Yes okay that makes sense, since I assume whatever Views does with limiting search results has to be down purely in the query, so we need to add node access records for an unpublished realm.

Rerolled to include an update hook to enable the rebuild access permissions flag.

I've tested this patch and it seems to work as intended.

bkosborne’s picture

Forgot to rearrange the ternary conditions as per #16

Yaron Tal’s picture

Patch works perfectly here.

+++ b/content_access.module
@@ -103,6 +103,7 @@ function content_access_admin_settings_access() {
+    'content_access_author_unpublished' => $account->uid && user_access('view own unpublished content', $account) ? array($account->uid) : array(),

This line is a bit long though. Can we split this in two lines?

Besides that I am all for committing this.

pianomansam’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #20 works as advertised. Marking as RTBC.

damien_vancouver’s picture

+1 for Patch #20 working properly

JanKanis’s picture

I've created a module here that solves this issue for me. In my case the above patch applied all the same visibilities and permissions to unpublished content rather than just making it visible to their owner.

albert volkman’s picture

*bump*

ashlinry’s picture

Hey! I just ran into this issue myself. I'm wondering if this patch is making its way into the next release.

  • bkosborne authored c556f48 on 7.x-1.x
    Issue #1225520 by bkosborne, hefox, pcho: Add View own unpublished...
gisle’s picture

Status: Reviewed & tested by the community » Fixed

This is fixed in 7.x-1.x-dev.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.