Problem/Motivation

For a editorial office it's a worse way to use node access for their workflow:

  • Writers are only allowed to create unpublished nodes
  • Editors need access to every (so node_access isn't useful) unpublished node of the writers...
  • ...but they aren't allowed to publish the node, so I can't use "administer nodes" for the editors

-> the permission "view any unpublished content" is required.

Proposed resolution

Create new permissions for viewing any unpublished content or by node type.

The current patch have:

  • Permission for viewing unpublished nodes of any type.
  • Permissions for viewing unpublished nodes defined per node type.
  • Views status filter displays unpublished nodes if user has the 'view any unpublished' permission.

Remaining tasks

Currently postponed awaiting #2809177 (which will make this easier). As of 2022-05026 there is a patch in the queue that people have reported as working.

User interface changes

Adds new permissions.

CommentFileSizeAuthor
#180 273595-170-d10.patch8.51 KBAlbert Volkman
#171 273595-170.patch8.39 KBAJV009
#169 273595-168.patch8.03 KBAJV009
#166 273595-166.patch8.02 KBnlisgo
#164 273595-164.patch7.91 KBnlisgo
#160 273595-160.patch7.6 KBnlisgo
#159 273595-159.patch7.89 KBnlisgo
#151 interdiff_149-151.txt364 bytesangelamnr
#151 move_permission_view-273595-151.patch7.54 KBangelamnr
#149 move_permission_view-273595-149.patch7.5 KBkbentham
#137 move_permission_view-273595-137.patch13.87 KBjoey-santiago
#134 move_permission_view-273595-133.patch5.88 KBjoey-santiago
#133 move_permission_view-273595-132.patch5.79 KBjoey-santiago
#133 move_permission_view-273595-132.patch5.79 KBjoey-santiago
#129 move_permission_view-273595-129.patch8.31 KBjlbellido
#123 move_permission_view-273595-123.patch8.19 KBjlbellido
#123 interdiff.txt787 bytesjlbellido
#121 move_permission_view-273595-121.patch7.69 KBjlbellido
#97 new_node_permission-273595-97.patch7.94 KBManuel Garcia
#97 interdiff.txt679 bytesManuel Garcia
#94 new_node_permission-273595-94.patch7.95 KBManuel Garcia
#90 273595-interdiff.txt2.5 KBholist
#90 273595-90-unpublished-node-access.patch7.95 KBholist
#1 view_unpublished_books.diff10.13 KBRoi Danton
#1 view_unpublished_nodes_global.diff1.52 KBRoi Danton
#23 _273595.23.node_.view_unpublished_nodes_D7.patch1.11 KBjonathan1055
#23 _273595.23.node_.view_unpublished_nodes_D6.patch948 bytesjonathan1055
#29 273595-view-unpublished-content-29.patch5.37 KBc31ck
#32 interdiff-29-32.txt5.26 KBc31ck
#32 view-unpublished-content-273595-32.patch4.17 KBc31ck
#43 273595-43-view_all_unpublished.patch3.58 KBadammalone
#45 273595-45-view_unpublished_per_type.patch5.8 KBadammalone
#50 273595-50-view_unpublished_per_type.patch5.8 KBadammalone
#53 273595-53-unpublished-node-access.patch5.75 KBdcam
#59 273595-59-unpublished-node-access.patch5.92 KBrupertj
#68 drupal8-unpublished_node_access-273595-68.patch5.03 KBJalandhar
#77 273595-77-unpublished-node-access.patch5.37 KBholist
#84 273595-interdiff.txt663 bytesswentel
#84 273595-84-unpublished-node-access.patch5.45 KBswentel

Issue fork drupal-273595

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Roi Danton’s picture

Using the book module users with "view unpublished nodes" should be able to view the TOC of unpublished book nodes, add new pages etc. It is already described here:
#26552: Allow users with access to unpublished nodes to create unpublished books (Patch: http://drupal.org/files/issues/20070624_amdinbook.patch)

Files for modifying book and node module are attached. Additionally, the book module contains changes so that writers/editors without the "administer nodes" permission are able to set the weight of child book pages.

keith.smith’s picture

Just FYI: there are some very minor code style violations in the comments (space after the "//" and end the comment in a full-stop (period)).

Roi Danton’s picture

Thanks for the hint! Apart from that the comments are only temporary as long as I'm testing this for bugs respectively until a solution for per node type is written.

deviantintegral’s picture

Version: 5.7 » 7.x-dev

Moving this feature request to Drupal 7. For Drupal 5, this feature can be set up with the View Unpublished module.

--Andrew

loze’s picture

is this possible in d6?

Roi Danton’s picture

Status: Needs work » Active

Sure, but I had no need to port it to D6 'til now so there is no patch for D6. Maybe Override Node Publishing Options is a working alternative? I've created an issue there regarding unpublished node options: #334992: New access perm: View unpublished nodes

Nevertheless this node type permission included into core D7 would be nice. Changes could be done quite easy, see diff files posted above.

BorisBarowski’s picture

This would be a very nice feature to have, as I couldn't believe it wasn't in D6 core.
Someone made a D6 port of a now unmaintained D5 module here #304173: Make it to work in Drupal 6.

I would really like to see this in D7 :x

The only available permission now is "View own unpublished content".
This could be expanded with "View all unpublshed content"
more fine grained control could allow for "View all unpublished nodes"

Any input on this ?

slosa’s picture

sub

askibinski’s picture

I was really surprised this wasn't available in D6.
Really hope it makes it way to D7...

deviantintegral’s picture

Version: 7.x-dev » 8.x-dev

As this doesn't fit into the feature exceptions, it's going to have to wait until D8.

Agileware’s picture

This would be extremely useful.

The view_unpublished module is good if you only need basic functionality.
But if you need to be able to view/edit unpublished revisions or use file
attachments on unpublished nodes or anything more than the most basic use
you run into problems.

Because node_access checks node status, you run into a lot of problems very quickly
if you are trying to get around this outside of core.

This would definitely be something that would be good to get into drupal 7.
It would certainly make it worth waiting for.

arhak’s picture

err.. correct me if I'm wrong, bug D7 already has 'view own unpublished content'
maybe that's not what is being requested, but it seems pretty much similar

Agileware’s picture

This issue is also for "view any unpublished content" or something similar.

sun’s picture

Status: Active » Closed (duplicate)

Thanks for taking the time to report this issue.

However, I think that the most common use-cases are already covered by #452538: Enable Node Grants for Unpublished Nodes and thus marking as duplicate.

Agileware’s picture

Title: New node type permission "view unpublished content" » New node permission "view any unpublished content"
Version: 8.x-dev » 7.x-dev
Status: Closed (duplicate) » Active

Reopening this issue as #452538: Enable Node Grants for Unpublished Nodes didn't solve it

That issue took care of node grants for unpublished and view own unpublished so
this issue is for "view any unpublished" or possibly "view NODE-TYPE unpublished"

BenK’s picture

Subscribing.... BIG +1 for this feature!

drupalsteve’s picture

Subscribe

Taxoman’s picture

Subscribing.

sun’s picture

Version: 7.x-dev » 8.x-dev

This is a new feature. Far too late for D7. See #927792: Please explain what is still considered for D7

geek-merlin’s picture

+1

jonathan1055’s picture

+1.
Such a shame this did not get into D7 - the various threads started early enough. I have my own simple patches for 'view unpublished TYPE content' for D6 and D7 if anyone is interested.

Jonathan

Taxoman’s picture

@jonathan1055 / #21: interesting, could you upload them as a zip file here in this thread?

jonathan1055’s picture

Yes certainly. They are not zipped, no need really. D6 created against 6.20 and D7 against 7.0, not against the latest dev, but they should both apply ok.

Agileware’s picture

Status: Active » Needs review

Changing status

Status: Needs review » Needs work

The last submitted patch, view_unpublished_books.diff, failed testing.

entendu’s picture

For those searching, I've posted a D7 and new D6 version of the View Unpublished module on the project page: http://drupal.org/project/view_unpublished

ts145nera’s picture

I try to add views unpublished support, please see http://drupal.org/node/773784#comment-4680180

yoroy’s picture

Issue tags: +permissions

tagging

c31ck’s picture

Title: New node permission "view any unpublished content" » New node permission "view unpublished content"
Status: Needs work » Needs review
FileSize
5.37 KB

Patch that adds a 'view unpublished content' permission, makes the necessary changes to the access checks and adds a small test for the new permission.

todderasesareddot’s picture

Wow. That's great. This is exactly what I'm looking for!

I installed your patch, but I didn't get it to work.

I'm trying to allow users to see their own unpublished nodes within views. They can see their nodes by accessing the node's page directly, but it does not show up in any views. It seems like the permission 'View own unpublished content' should take care of this, but unpublished nodes do not show up in views. Are talking about the same thing?

I'm trying to follow along what you did here in this patch. I see you added a 'View unpublished content' permission to the node section, but that seems odd. It is not clear what is meant by that and how it relates to 'View own unpublished content'. I'm not sure exactly what the intention is. Maybe it should read "'View own unpublished content in views'?

Hmmmm....

arhak’s picture

Status: Needs review » Needs work

@#29 not fully reviewed, but first chunk seems to change indentation unnecessary
also, permission's name seems misleading (see #13 for a more appropriate suggestion)

c31ck’s picture

Status: Needs work » Needs review
FileSize
5.26 KB
4.17 KB

Reroll that renames the permission to 'view any unpublished content' and fixes the indentation issue.

Eric_A’s picture

Note that the recent block from node module calls node_get_recent() which does the same thing with these permissions.

jonathan1055’s picture

Hi Eric_A
Could you explain what you mean, I don't understand. Maybe I'm missing something, sorry.
Jonathan

tecjam’s picture

Hmm, I would really like this permission seperate for each Content Type and not globally for all content types in D7.

geek-merlin’s picture

+1 for #35

rooby’s picture

Hmm, I would really like this permission seperate for each Content Type and not globally for all content types in D7.

If you mean you want drupal core permission changes in drupal 7 it probably won't happen.
Changes like that generally won't happen until the next major version.

If you mean you want it in drupal 8, unlike how the view own unpublished works in drupal 7, then I agree.

Maybe this issue could be done to get the view any unpublished nodes permission in and then a follow up issue could be done for both the view own unpublished and the view any unpublished, to move them to content type specific perms.

arhak’s picture

+1 for #37
nevertheless, permission table gets bigger and bigger,
it would be nice to have configurable options to enable such permissions "for each" content type
but as rooby said @#37, lets start by having them globally at least

seanr’s picture

We just got bit by this too. Very strange that this functionality was removed from administer content without a suitable replacement ever being offered. Lets please try to get this in soon (and hopefully backport to D7).

Can we get a re-roll of this patch? It no longer applies.

adammalone’s picture

Assigned: Unassigned » adammalone
Status: Needs review » Needs work

I've just run into an issue with unpublished content on the admin/content page. I would think any kind of editorial workflow would allow users to edit other user's unpublished content. Currently this requires a contributed module to do. If D8 were to add in extra permissions however this would make things a whole lot simpler.

The way I see it there are three options ranging from simplest to most complex:

  1. Add in a 'View all unpublished content' permission
  2. Add in a 'View all unpublished $node->type' permission for extra granularity based on content type
  3. Extend #2 by adding in a complimentary 'View own unpublished $node->type' permission rather than the standard 'view own unpublished.

Assigning to myself to reroll a patch based on #2/#3 in the first instance. If a week goes by without a patch feel free to unassign!

joel_osc’s picture

I like his proposal and I think it plays nicely with the issue mentioned here #26552: Allow users with access to unpublished nodes to create unpublished books.

rooby’s picture

@joel_osc:
In relation to books and unpublished access, this issue is also relevant: #520786: menu_tree_check_access: only filter by status = 1 for non content admins
However I assume menu_tree_check_access() might be changing due to all the menu changes in D8.

[EDIT] Actually I see now that they are partly duplicate issues, so I have mentioned it in the unpublished books issue.

adammalone’s picture

OK - here's a little patch that addresses #1 in comment 40 so people don't think I've forgotten this issue.

I'm going to extend further and add in view unpublished per content type shortly.

adammalone’s picture

Status: Needs work » Needs review
adammalone’s picture

Ok - here's a more granular patch with view unpublished permissions per content type.

Status: Needs review » Needs work
Issue tags: -permissions

The last submitted patch, 273595-45-view_unpublished_per_type.patch, failed testing.

adammalone’s picture

Status: Needs work » Needs review
adammalone’s picture

Status: Needs review » Needs work
Issue tags: +permissions

The last submitted patch, 273595-45-view_unpublished_per_type.patch, failed testing.

adammalone’s picture

Status: Needs work » Needs review
FileSize
5.8 KB

Rerolled patch for latest D8 HEAD

TravisCarden’s picture

Marked #1388674: Add "View unpublished {node_type}" permission as a duplicate of this issue.

seanr’s picture

I'm definitely liking this so far. Especially happy with the more granular options provided as well. Great work folks. Will allow others to continue testing before RTBC.

dcam’s picture

#50 no longer applies. This is a reroll of #50.

BDaggerhart’s picture

Subscribing. This is looking awesome, is there any chance some form of this will also be implemented in d7?

seanr’s picture

Ishmayl, I kind of doubt it, though if this gets into D8, we can certainly tag it for backport and see. Doesn't look like it'd be too hard to backport. Would certainly be nice. ;-)

adammalone’s picture

If you've tested this - the best and fastest way to get it into D8 would be to mark as RTBC. This way the maintainers will be made aware of it and inform us whether or not it's likely to make it into this release.

rupertj’s picture

Issue tags: -permissions

Status: Needs review » Needs work
Issue tags: +permissions

The last submitted patch, 273595-53-unpublished-node-access.patch, failed testing.

rupertj’s picture

#53 no longer applies. This is a new re-roll of #50

rupertj’s picture

Status: Needs work » Needs review
adammalone’s picture

Assigned: adammalone » Unassigned

Unassigning from me so anyone may review.

bkosborne’s picture

Issue summary: View changes

Is this essentially adding what the contrib module View Unpublished does?

adammalone’s picture

Functionality looks pretty similar actually but baking it into core will fix what I consider to be an anti-pattern in the way Drupal handles access for unpublished content.

adammalone’s picture

Status: Needs review » Needs work

The last submitted patch, 59: 273595-59-unpublished-node-access.patch, failed testing.

adammalone’s picture

Issue tags: +Needs reroll
bkosborne’s picture

Completely agree, just wanted to make sure I was on the same page after reading thru the issue history.

Jalandhar’s picture

Status: Needs work » Needs review
FileSize
5.03 KB

Updating patch with re-roll. Please review.

Manuel Garcia’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs reroll

Patch #68 stil applies fine.

I did the following manual tests:

  1. Created a node/1 article with user 1 as author, left it unpublished.
  2. Assigned the permission 'View any unpublished content' to authenticated users.
  3. Visited the node/1 page as an authenticated normal user, I could see the node.
  4. Assigned the permission 'View own unpublished content' to authenticated users, removed 'View any unpublished content' from authenticated users.
  5. Changed the author to the normal user of node/1
  6. Visited the node/1 page as the authenticated normal user, I could see the node.

So the permission works, at least from an enduser perspective. Setting this to RTBC, unless someone thinks of other things that need testing =)

alexpott’s picture

Assigned: Unassigned » xjm

This all looks good to me.

Assigning to @agentrickard as node access maintainer - it'd be nice to get a +1 from a node access maintainer.

alexpott’s picture

Assigned: xjm » agentrickard

lol

agentrickard’s picture

Status: Reviewed & tested by the community » Needs review

Two points, one of which can likely be ignored, the other is a point of debate:

1) I don't like that part of the access check is in the controller and part in node_node_access(). This seems inconsistent to me. The implicit design is that "view any" retuning TRUE cannot be overridden by other modules the way that NODE_ACCESS_ALLOW can when sent from node_node_access().

This applies to the current "view own unpublished" as well. I don't see why that should be in the checkAccess() method.

If this is intentional, we should document it as such.

2) This has no effect on list queries, which I suspect many people will see as a bug, but that can possibly be addressed in a followup, or ignored on the grounds that we don't track node access for unpublished content.

Status: Needs review » Needs work

The last submitted patch, 68: drupal8-unpublished_node_access-273595-68.patch, failed testing.

Leeteq’s picture

Ref. comment #72:

"2) This has no effect on list queries, which I suspect many people will see as a bug, but that can possibly be addressed in a followup, or ignored on the grounds that we don't track node access for unpublished content."

This can has been kicked down the road since the start of Drupal. This very issue was filed in 2008, but we have maaaaany such issues long before that, in various contrib modules as well as for core.

I think it is high time it is dealt with in a fundamental way that does not make Drupal stand out any worse than other solutions.

IMO, it is never ok to architectually risk exposing data to roles for which the system explicitly prohibits access to the content in question, just because it is a "list" or whatever is the reason why some page renders does not check the access control. That is neither good design, nor what is expected of a system that provides access control in the first place.

Now that Views is in core in D8, this must be dealt with by core itself.

xjm’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Needs work » Postponed

Per: https://www.drupal.org/core/beta-changes
We're now in beta. New features can go into 8.1.x. We can unpostpone this when that branch is opened for development.

@Leeteq re: #75, I agree with you, but it's a bit out of scope to discuss on this issue, I think. To that point, though, I would agree that filtering listings also needs to be a part of the permission's behavior when we reroll this for 8.1.x.

holist’s picture

Status: Postponed » Needs review
FileSize
5.37 KB

Hi, I dug this up from the issue queue because I need the feature and quickly refactored (core has changed so much that it was a lot more than reroll but the logic is the same) the old patch to current D8.

In case this version does not apply to 8.0.1 (didn't try it out yet), I will make a such version for my own needs, just in case anyone else needs it too.

Status: Needs review » Needs work

The last submitted patch, 77: 273595-77-unpublished-node-access.patch, failed testing.

The last submitted patch, 77: 273595-77-unpublished-node-access.patch, failed testing.

holist’s picture

For the record, patch #77 applies and works on 8.0.1.

I have hard time figuring out why that one test fails but will look into it more. Ideas welcome, though.

Anonymous’s picture

Any updates on this? Some users are starting to deploy Drupal 8 in production and this feature is really needed. For example I have a case where all content can be published only by chief editor. After review.

holist’s picture

It would be indeed good to get this done quickly because there is still some time to get into 8.1.0. I haven't unfortunately had time to figure out the tests.

holist’s picture

I had a fresh look at the failing test but still no understanding came my way.

The failing test is Drupal\node\Tests\NodeAccessBaseTableTest, and it fails when checking if a user has access to an another user's private node. I have hard time understanding why because I haven't had time to figure out what actually this "private" node thing is.

The failure seems to be caused by the patch adding case 'view' in node_node_access(). I investigated implementing the unpublished check in NodeAccessControlHandler::checkAccess but I seem to be running into some other test failures with that approach.

swentel’s picture

Status: Needs work » Needs review
FileSize
5.45 KB
663 bytes

The problem is that it didn't return neutral in case the node is published.

Manuel Garcia’s picture

Thanks @swentel - Patch looks great to me, +1 for RTBC

Manuel Garcia’s picture

Status: Needs review » Needs work

OK while the patch works as advertised, I feel we should patch what views does when it comes to filtering out unpublished content, since views is in core, and all.

Something like what view_unpublished does for example:
http://cgit.drupalcode.org/view_unpublished/tree/?h=8.x-1.x

Else people are going to use these permissions, and will have to use view_unpublished module so that views actually respect these new permissions.

holist’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
Issue tags: +Needs followup

I'm not familiar with view_unpublished, so I have to confirm. Manuel, do you mean that there should be a filter in Views to the effect "select only published content, unless the user has permission to view unpublished content"? If I got this right, I agree that it is silly. I think the issue concerns cases where fields are used, and can be circumvented by using content display modes, because then access rights will be checked using the code in this patch, right? Still, using fields is very common so this note does not make the issue go away, although less of an impediment in my opinion.

However, this patch has been in the works for almost 8 years, and I think we now have a realistic possibility to get this in for 8.1.0. Having the feature at all is important, I don't see why we couldn't just fix Views support in a followup issue? Could it qualify for a patch release if this one makes 8.1.0? If yes, I think we should go for it, and implement view_unpublished in Core in a separate issue. (Or at least change the 8.x implementation of view_unpublished so that it utilises the permissions defined here, as it is a Views plugin after all, does it need to be in Core?)

This considered, I am going to tag this issue as needing followup and RTBC, feel free to push it back if I wasn't convincing enough. :)

chx’s picture

This won't work; there's a reason 'view' doesn't exist in node_node_access: when trying to list nodes (via views for example) you need to know accurately (for paging purposes) which nodes are visible and which aren't. Think of it, you request nodes 30-39 but during access control turns out the user doesn't have access to any of them, is the 4th page then going to be empty? This was raised in #72 although @agentrickard said it could be ignored -- ignored why exactly?

holist’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

@chx, sadly you're very right. (Previously I did not fully understand what @agentrickard meant in #72.)

But what does it mean? Should we actually, in contrast to what @agentrickard said in #72, implement this in NodeAccessControlHandler::checkAccess?

Edit: But checkAccess either is not called until node is being viewed, right? So where does this need to step in?

holist’s picture

Status: Needs work » Needs review
Issue tags: -Needs followup
FileSize
7.95 KB
2.5 KB

Ok, I managed to put some more time into this. What I did is as follows:

I modified the "Published status or admin user" (status_extra) filter plugin so that it checks for permission "view any unpublished content" (and renamed it more appropriately to "Published status or unpublished access"). Makes this almost work for Views, but per-node-type unpublished access checking is still needed.

I also tested for the problem @chx brought up. Either listing content or fields in Views with this feature enabled, with 20+ nodes of which 10 randomly unpublished I do not get empty pages in pager. Maybe I didn't think this far enough, but it seems to me that access checking works correctly in this use case as well.

As a slightly off topic point, I find it a bit odd user's permission to access individual nodes seems not to be checked if there is no status = 1 filtering in the view, meaning anyone can view unpublished nodes if Views doesn't filter them out. I guess this is by design?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

karl.hass’s picture

View Unpublished Content for Specific User Types
May need to download Modules:

(note) Permission Settings: (Need Dashboard to view and Admin )

Dashboards:

View the Administrative dashboard (check)

Node:

View own unpublished content (check)

(view name) Create New Content (check)
(view name) Edit own content (check)
(view name) Edit any content (check)
(view name) Delete own content (check)
(view name) Delete any content (check)

Override node options:

Override (view name) published option (check)

System:

(note) will only be able to see publishing edit with the admin theme
View the administration theme (check)

(Module add) View Unpublished

View any unpublished content (check)
(view name) View any unpublished content

Manuel Garcia’s picture

Assigned: agentrickard » Manuel Garcia
Status: Needs review » Needs work

Rerolling...

Manuel Garcia’s picture

Assigned: Manuel Garcia » Unassigned
Status: Needs work » Needs review
FileSize
7.95 KB

Was just a simple conflict on node_views_query_substitutions().

timmillwood’s picture

  1. +++ b/core/modules/node/node.module
    @@ -907,6 +907,14 @@ function node_node_access(NodeInterface $node, $op, $account) {
    +        return AccessResult::allowedIfHasPermissions($account, array('view any unpublished content', 'view unpublished ' . $type . ' content'), 'OR');
    

    Where adding or updating arrays should we use the short syntax []?

  2. +++ b/core/modules/node/src/Plugin/views/filter/Status.php
    @@ -22,7 +22,8 @@ public function canExpose() { return FALSE; }
    +    // @todo: Add per-node-type unpublished checks.
    

    Is this out of scope for this issue?

holist’s picture

Regarding #95:

  1. I fail to understand what you mean, can you please elaborate? We're not adding or updating array there?
  2. We add possibility to view unpublished nodes when the user has permission to view any unpublished, but even if user had permission to view unpublished particular content, it would not be shown, which is kind of broken. But now that I think of it, isn't the whole idea wrong? If the status filter is supposed to filter published nodes, why are we allowing it to show unpublished nodes? I suggest scrapping the whole part of this patch dealing with this here and leave it for another issue to a) decide what is wanted and b) implement the logic as wanted.
Manuel Garcia’s picture

holist’s picture

Issue summary: View changes

This won't be ready in time for 8.2.0 because beta phase is starting any time now. But I updated issue summary to make it easier to review.

The status filter question still needs input, otherwise this looks good?

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

rodrigoaguilera’s picture

Title: New node permission "view unpublished content" » Move permission "view any unpublished content" from content moderation to node
Issue summary: View changes
Status: Needs review » Needs work

I've been in the situation of needing this permission and one of the solutions that came to my mind was enabling the content moderation module (now in core as experimental) and use the permission.

I think enabling the module just for that is an overkill so I suggest that the permission is moved from one module to another because we can't have the same permission in two modules.

If the module is rejected as part of core this issue will go back to the state it is now.

Manuel Garcia’s picture

+1 @rodrigoaguilera makes sense - let's work on this in Dublin !

timmillwood’s picture

I think moving this out of Content Moderation makes sense. Although in the grand scheme I'm not sure node is the best place for it.

status (the field that stores the published state) is an entity key on node, so maybe we add the permissions to core, and only use them if the entity type has the status entity key.

Eventually I'd like to add the status field to more content entities, imagine a world where you could have unpublished blocks, or unpublished taxonomy terms. Putting this in core rather than node will mean it's "View any unpublished content entities" rather than "View any unpublished nodes".

Manuel Garcia’s picture

Perhaps then we should add permissions per content entity as well.

Manuel Garcia’s picture

Title: Move permission "view any unpublished content" from content moderation to node » Move permission "view any unpublished content" from content moderation to core
Issue tags: +Needs issue summary update
timmillwood’s picture

yes, or even per bundle?

Should this be a core thing, just loop through all content entities with the status entity key and add a "View any unpublished $entity_type->label()" permission?

Manuel Garcia’s picture

@timmillwood even better!

rodrigoaguilera’s picture

I'm wondering if core can have permissions like in a /core/core.permission.yml file
Maybe the permission should go in system.

So the permission exist only for entity types with status property?

It would be great if we can have a global permission and also granular per bundle.

Manuel Garcia’s picture

So I think the permissions should be (in order of access granted):

  1. View any unpublished content entity
  2. View any unpublished [entity] - one per entity that has a status property
  3. View any unpublished [entity bundle] - one per entity bundle for entities that have a status property
Manuel Garcia’s picture

It looks like the good folks on Entity API are trying to do just this and more:
#2801031: Provide a generic entity access handler and permissions

And according to Bojan's tweet, the plan is to move that into core:
https://twitter.com/bojan_zivanovic/status/779288985197830144

holist’s picture

I had a quick look on the Entity API issue, not claiming I've got a good understanding of how that feature would work but sounds great to me, at least that would be the right place for this.

And if I understand it correctly, it's actually quite far, so if there is work being done on this in Dublin on Friday, I'm in.

Manuel Garcia’s picture

Issue tags: +Dublin2016
rodrigoaguilera’s picture

Maybe this module can be solution for some of the use cases
https://www.drupal.org/project/access_unpublished

flocondetoile’s picture

I used content moderation with some module which implements hook_node_access_records() and hook_node_grants() for controlling access to node when they are published. Default behavior apply on nodes not yet published (in a draft mode, or any other state which is not the published state).

We can then view these nodes unpublished, using their url. But if we create a view to make a dashboard listing nodes in different status, then nodes not yet published are filtered because of hook_node_access_records implemented.

We can eventually use the module views_unpublished which take care of this specific use case for unpublished node (content type by content type), by implementing hook_node_access_records for unpublished nodes only.

I wonder if we could support this use case in this issue, by implementing hook_node_access_records and hook_node_grants for controlling access to node instead of using hook_node_access only ? Or is the right way is to use some contrib module as View unpublished if needed ?

Edit: I just saw that this was mentioned in #72. But what i don't uderstand is why using hook_node_access only to control access to unpublished nodes whereas hook_node_access_records() and hook_node_grants() take care of this (control access node by node) + views listing.

flocondetoile’s picture

Sorry. I just realize. I was lost in my use case. I answer myself.
I didn't see that if we manage access to these unpublished nodes with hook_node_access_records() then we must do the same for published node, which is not by default and a bit overkilled if not needed really.

larowlan’s picture

From #102 we kind of got derailed here. This issue is about letting editors view content that contributors created, so belongs in node. If we have plans to extend it to other content entities that should be a separate issue in my book.

DuaelFr’s picture

What about getting #100 first then improve it by adding permissions for entity types/bundles in a follow-up? #BabySteps

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

holist’s picture

How about just getting the permissions in, and deal with other issues (Views status filtering?) in either a follow-up or Content Moderation? I think majority of users will just need the generic permission, and the ones who need more granularity might want to use some more advanced tools anyways?

Could someone check reroll for current core? Did we just miss 8.3.0? :( The 9th birthday of this issue is approaching...

jofitz’s picture

Issue tags: -Needs reroll

Checked with 8.4.x - does not require re-roll.

jlbellido’s picture

Issue tags: +Needs reroll

It seems that /core/modules/node/src/Tests/NodeAccessTest.php was moved to /core/modules/node/tests/src/Kernel/NodeAccessTest.php

So we would need to reroll #97

jlbellido’s picture

Status: Needs work » Needs review
FileSize
7.69 KB

First try rerolling #97

Status: Needs review » Needs work

The last submitted patch, 121: move_permission_view-273595-121.patch, failed testing.

jlbellido’s picture

Status: Needs work » Needs review
FileSize
787 bytes
8.19 KB

Let's go with a second try!

jofitz’s picture

Issue tags: -Needs reroll
holist’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

I propose RTBC. The per node type permissions are not honored by the status filter but I think it is not a marjor issue and can be dealt with further on.

flocondetoile’s picture

Added a related issue #2853512: View unpublished could be deprecated ? , as a possible follow up.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

I propose RTBC. The per node type permissions are not honored by the status filter but I think it is not a marjor issue and can be dealt with further on.

Unfortunately, we cannot commit such feature regressions to minor releases. In order for this feature request to go forward, it needs to not regress any existing stable functionality.

holist’s picture

@xjm, what is the regression here?

jlbellido’s picture

Status: Needs work » Needs review
FileSize
8.31 KB

Rerolled #123 to the 8.4.x because it didn't apply anymore. Running the tests again.

akalata’s picture

Status: Needs review » Reviewed & tested by the community

@xjm I've just read through this issue summary and don't believe that #125 is noting a regression, but rather a place where future work would be welcome/needed. #72.2 confirms that Views' "status filter" does not check access for unpublished content, since access grants aren't tracked.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/node/src/Plugin/views/filter/Status.php
@@ -22,7 +22,8 @@ public function canExpose() { return FALSE; }
-    $this->query->addWhereExpression($this->options['group'], "$table.status = 1 OR ($table.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0 AND ***VIEW_OWN_UNPUBLISHED_NODES*** = 1) OR ***BYPASS_NODE_ACCESS*** = 1");
+    // @todo: Add per-node-type unpublished checks.
+    $this->query->addWhereExpression($this->options['group'], "$table.status = 1 OR ($table.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0 AND ***VIEW_OWN_UNPUBLISHED_NODES*** = 1) OR ***VIEW_ANY_UNPUBLISHED_NODE*** = 1 OR ***BYPASS_NODE_ACCESS*** = 1");

As per above this todo is not yet complete. However it does not point to a followup issue either. We don't add @todo items without followup issues and linking the followup issue. I would personally consider it a bug that we allow viewing unpublished nodes in Views to people who can view any unpublished nodes, but we don't allow viewing unpublished Articles for people who can only view unpublished Articles. While this is "new" functionality, in terms of views, it is wrapped under this existing views handler where we introduce the bug with this patch (ie. the handler will not do what its title and description says it does).

+++ b/core/modules/node/src/NodeViewsData.php
@@ -40,12 +40,12 @@ public function getViewsData() {
     $data['node_field_data']['status_extra'] = [
-      'title' => $this->t('Published status or admin user'),
+      'title' => $this->t('Published status or unpublished access'),
       'help' => $this->t('Filters out unpublished content if the current user cannot view it.'),
       'filter' => [
         'field' => 'status',
         'id' => 'node_status',
-        'label' => $this->t('Published status or admin user'),
+        'label' => $this->t('Published status or unpublished access'),
       ],

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joey-santiago’s picture

Hello,

here's the patch for 8.4.x with the modifications about views stripped out as, if i got it well, the views changes should be addressed somewhere else? :)

thanks!

joey-santiago’s picture

And here's the patch for 8.5.x.
Views modifications stripped out as the views bits need more work (and most likely a new thread).

cheers

joey-santiago’s picture

Status: Needs work » Needs review
timmillwood’s picture

Status: Needs review » Needs work

This patch doesn't remove anything from Content Moderation.

I guess if we're looking to "move" the permission from Content Moderation to Node it should remove from Content Moderation, as well as adding to Node.

joey-santiago’s picture

oh, didn't notice content_moderation has gone into core now.

Here's the adds to the patch.

thanks

Manuel Garcia’s picture

Status: Needs work » Needs review
timmillwood’s picture

I don't think this permission should be part of Node.

+++ b/core/modules/content_moderation/content_moderation.module
@@ -166,14 +166,7 @@ function content_moderation_entity_access(EntityInterface $entity, $operation, A
-    $access_result = (($entity instanceof EntityPublishedInterface) && !$entity->isPublished())
-      ? AccessResult::allowedIfHasPermission($account, 'view any unpublished content')
-      : AccessResult::neutral();

In content moderation this permission worked for all publishable entities. Do we need a permission for each module that provides a publishable entity (currently in core this is Node, Comment, and Media), or do we have a catch all permission?

Also as Content Moderation is now Beta we need to provide full backwards compatibility and an upgrade path. So we'll need to make sure that if a site had the permission enabled in Content Moderation that they have the permission in all other modules enabled after the patch.

timmillwood’s picture

Status: Needs review » Needs work
Issue tags: +Needs upgrade path, +Needs upgrade path tests
holist’s picture

Status: Needs work » Closed (outdated)
Issue tags: -Needs upgrade path, -Needs upgrade path tests

Considering what @timmillwood said in #140, I talked with @joey-santiago, and we agreed with Tim that this feature is better provided by using Content Moderation. Content Moderation does provide better framework to manage content types' permissions than by implementing them individually.

I think this issue should retire in a respectable age of nine years, marked "Closed (outdated)".

timmillwood’s picture

I'm not really suggesting that it should be in Content Moderation, just that if the permission is being moved out of Content Moderation it will need to provide the same level of functionality as the one in Content Moderation does. The current patch is node specific so does not offer backwards compatibility with the Content Moderation permission.

holist’s picture

I think permissions related to the publishing status are better in Content Moderation than in individual content entity types. Adding such permission to Node (and all other modules that need it) would fragment what is essentially one functionality. Besides, it is a working implementation in core that accomplishes the essence of what this issue originally requested, which I do prefer over this issue.

Now that I look into this, if the unpublished permission would be moved out of Content Moderation (it is a lot of module for one plain check, true), in my opinion the check for it should be defined in EntityPublishedInterface (and implemented in EntityPublishedTrait) which is the source of the published state for all editorial content entities, but that leaves the question of where the permission would be defined. If I haven't gotten something wrong, the only way is via a module's permissions.yml (or a callback defined in one). So that kind of brings us to the need for a module such as Content Moderation, right?

flocondetoile’s picture

Hi,

Some (many?) sites may need a basic workflow (published/unpublished) and so need the "view unpublished" permissions without Content Moderation module. It would be a bit heavy to have to enable content moderation just to have these permissions.

The system module could be a good candidate to hold these permissions ?

badrange’s picture

We were using this patch before it was closed as outdated; we have no need for content moderation but we do need the ability to let certain roles view unpublished content.

Would it be that bad to get this into core?

amateescu’s picture

Status: Closed (outdated) » Needs work

This is still useful to get into core IMO. See the problems that people are getting into in #2934011: [PP-1] Add a selection handler to content_moderation that respects 'view any unpublished content' .

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

badrange’s picture

Heads up: The patch in #137 does not apply on 8.5.0. Good to keep in mind before #drupalgeddon2

kbentham’s picture

I have rebased the last patch against 8.6.x, rearranged the tests, and updated \Drupal\node\Plugin\views\filter\Status::query to account for the "view all unpublished content" permission.

timmillwood’s picture

+++ b/core/modules/node/node.module
@@ -935,6 +935,15 @@ function node_node_access(NodeInterface $node, $op, $account) {
+      ¶

Too many spaces.

angelamnr’s picture

Remove extra spaces from #149

timmillwood’s picture

Component: node system » content_moderation.module

Thanks, my biggest concern here is that the current "View any unpublished content" permission works in Content Moderation for all entity types, such as Nodes and Blocks. Where as the patch changes this to only work with Nodes.

angelamnr’s picture

Yes, I agree that it should be moved somewhere else. Since the publish/unpublish api was added in Drupal 8.3 for all entities, it wouldn't be consistent to make the permission only available for nodes. It seems like it should be treated like the "access content" permission, which was moved into the system module in 8.5.x.

The real issue is where to put the access check logic. We need to pull this code from content moderation (lines 187-193 in content_moderation.module) and put it somewhere, but I'm not certain where the best place to put that is:

  $access_result = NULL;
  if ($operation === 'view') {
    $access_result = (($entity instanceof EntityPublishedInterface) && !$entity->isPublished())
      ? AccessResult::allowedIfHasPermission($account, 'view any unpublished content')
      : AccessResult::neutral();

    $access_result->addCacheableDependency($entity);
}

#143 mentions EntityPublishedInterface.php as a possibility. Does that still make sense? Also, how much will this impact performance?

angelamnr’s picture

It's worth pointing out that there is a similar permission for "View own unpublished content" that lives in the node module and only applies to nodes. Should there be an issue to move that out of the node module and make it apply to all entities as well?

Manuel Garcia’s picture

I agree with #152 and doing #154 would make sense.

As far as where this should go, perhaps we should ping the Entity API maintainers for directions?

Manuel Garcia’s picture

Status: Needs work » Postponed
Related issues: +#2809177: Introduce entity permission providers

Had a chat with @timmillwood and we've figured out where we stand, there is a wider effort in this space which will make this patch easier to implement. And that is #2801031: Provide a generic entity access handler and permissions, which was implemented in entity api module, which is now being moved to core on #2809177: Introduce entity permission providers.

Let's postpone until #2809177: Introduce entity permission providers gets in, and focus our efforts there. After that is in, it will be simpler to figure out what we need to do here.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

nlisgo’s picture

nlisgo’s picture

This will apply to the 8.7.0 branch.

jonathan1055’s picture

When the status is 'postponed' even though on uploading it says "test with ..." the patch is not automatically queued. You have to click "add test / re-test" and do it manually (which is what I have just done with the #159 patch)

AaronMcHale’s picture

Title: Move permission "view any unpublished content" from content moderation to core » Move permission "view any unpublished content" from Content Moderation to Node

More accurate title

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

nlisgo’s picture

This will apply to the 8.8.0 branch.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

nlisgo’s picture

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

AJV009 made their first commit to this issue’s fork.

AJV009’s picture

AJV009’s picture

Re-rolled to 9.2.x

AJV009’s picture

AJV009’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dalin’s picture

Issue summary: View changes

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

acbramley’s picture

Patch still applies to 10.1.x, however

+++ b/core/modules/node/node.module
@@ -806,6 +806,15 @@ function node_node_access(NodeInterface $node, $op, AccountInterface $account) {
+    case 'view':

Shouldn't we do this in NodeAccessControlHandler?

I don't understand why the existing code is in this hook but perhaps it just hasn't been moved out yet.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Albert Volkman’s picture

FileSize
8.51 KB

Re-roll for latest 10.1