Problem/Motivation

Since the property status of nodes is a core functionality, I think Grant should not override that. Grants should only apply if the content is published. At least for the view permission.

(Previously addressed in Drupal 7 version: #1444040: Access to unpublished node)

Steps to reproduce

Create a node as not published.
Go to the Grants tab and choose all roles as "view". Specially if you give the Anonymous role access.
Go to view in an incognito window the node and you will have then permissions to see it.

Proposed resolution

Let core deal with unpublished content via the permissions.

Issue fork nodeaccess-3169490

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:

Comments

e.escribano created an issue. See original summary.

eescribanoc’s picture

Here the patch, I also created a merge request.

alison’s picture

Title: Unpublished content can be viewed » Unpublished content can be viewed by anonymous
Issue summary: View changes
Related issues: +#2541588: Unpublished Nodes grants checkboxes won't save., +#3205870: Unpublishing a node removes the access rights for auth users

Title tweak + related issues -- some of which might be slightly contradictory...? I'm not certain, but, for now just adding links.

@e.escribano - thank you for submitting!

jungle’s picture

Status: Active » Needs work
Issue tags: +Needs followup

This module does not take into account whether the node is published or not, currently.

So I'd suggest adding a settings item for this case -- add to nodeaccess/config/install/nodeaccess.settings.yml. For example: Bypass unpublished nodes, and defaults to FALSE, so that the existent sites won't be affected. Or the patch above is aggressive and destructive to me.

Tagging `Needs followup` for further discussion of if published and unpublished nodes should be distinguished.

Thanks!

yogisingh’s picture

jungle’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Issue tags: -Needs followup

I would move this to the latest dev branch 2.0.x which has schema added, tests added, an upgrade path provided and almost fully refactored etc.

jungle’s picture

eesquibel’s picture

StatusFileSize
new1.26 KB

I needed the nodeaccess module to honor the published status, so I wrote this patch against the latest 2.0-alpha1.

It didn't go the extra mile and add a UI to toggle the behavior, but at least this is one step closer.

jungle’s picture

Issue tags: +Needs tests

@e.escribano, Thanks for the patch, tagging "Needs tests"

peterbkk’s picture

@e.escribano thanks, it resolved the issue for me.

abhijith s’s picture

Status: Needs work » Needs review
StatusFileSize
new2.49 KB

Adding test case for patch #9. Please review.

Status: Needs review » Needs work

The last submitted patch, 12: 3169490-12-test-only.patch, failed testing. View results

abhijith s’s picture

StatusFileSize
new3.75 KB
new2.4 KB
abhijith s’s picture

Status: Needs work » Needs review
markgp’s picture

#9 resolved the issue for us.

ecvandenberg’s picture

Patch #14 seems to work fine here with multiple access modules and a complex structure of access rights and workflows.

mortona2k’s picture

This patch works by preventing you from granting access to unpublished content, but it doesn't fix content that already has the grants.

It works by setting the view permission to the published status, when the grant form is saved.

There is no message to the user, the form silently unsets the value. If we keep this, I think there should be a message to the user about what's happening.

I think the fix should be done somewhere else though, like an access hook or event subscriber that would check when the content is loaded.

szeidler’s picture

Thanks for your work on this. I also struggled with the same issue. In addition we have a use-case that we have translated content and the translations could have a different published status. A bit like described in #2469523: Add language support to node access grants. When using the patch as it is here the source language of a content would decide if the content is treated as published or unpublished and react wrong on the translations, if the status is different.

I added language capability to patch #14 and extended the tests. Please decide if that should go into this issue or handled separately. If not, then ongoing work should be based on #14.

Thanks for a review.

alyaj2a’s picture

Hello, patch number 19 works for me. Thanks.

vbory’s picture

Hello, both patches do not work. I am using content_moderation module for managing nodes status and have applied nodeaccess settings according to my needs, and in my case logged in user with non-admin role is able to view unpublished content. Maybe someone has faced with that, not just checking content for anonymous users? Thank you

tikaszvince’s picture

Status: Needs review » Reviewed & tested by the community

The latest patch resolved this in my cases, when I tried with Drupal 10.2.7 and 10.3.1

doxigo’s picture

Status: Reviewed & tested by the community » Fixed

Thanks everyone, applied the patch #19

  • doxigo committed 05510490 on 2.0.x
    git commit -m 'Issue #3169490 by eescribanoc, Abhijith S, szeidler,...

Status: Fixed » Closed (fixed)

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

guillaumeg’s picture

Hi everyone, and thanks for the patch.

Could we please create a new release so that this important patch is included in the recommended module version?