Follow-up to #2506345: Unpublished Nodes accessible

Problem/Motivation

When trying to save grants on a new, unpublished node, the checkboxes won't save.

Proposed resolution

Save grants on unpublished nodes too.

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joelpittet’s picture

Status: Active » Needs review
FileSize
2.32 KB

Here's some tests, they should fail:) I don't have a solution to the problem yet but this should help ensure it works going forward.

First time writing tests before I know the answer:)

Status: Needs review » Needs work

The last submitted patch, 1: unpublished_nodes-2541588-1-tests-only.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review

Those two fails are expected;)

joelpittet’s picture

Status: Needs review » Needs work

Actually I should leave this as needs-work because the fix needs to be added to these tests.

joelpittet’s picture

Priority: Normal » Major

Bump, there are tests to show this is broken, bumping priority.

Nick Dewitte’s picture

Attached is a patch that resolves this specific issue in a very naive way.

When this module saves grants, this is done via nodeaccess_set_grants().
This function calls node_access_acquire_grants(), which calls all implementations of hook_node_access_records().
The nodeaccess_node_access_records() implementation (which is the file I patched) checked if the node was unpublished,
and if so, it returned no grants (NULL).

After reading https://api.drupal.org/api/drupal/modules%21node%21node.module/group/nod...
it appears to me that the access based on the published state should be managed in hook_node_access().

Once grants are being checked, I don't think it's appropriate to flat out deny access to all unpublished nodes without any condition.
But perhaps ignoring the published state as this patch does isn't the way to go either?

Adding the "Needs committer feedback" tag since I think this is dependant on how the module should behave.

Status: Needs review » Needs work

The last submitted patch, 6: unpublished_nodes_grants_checkboxes_wont_save-2541588-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

joelpittet’s picture

I wrote tests in #1 see if they pass with that fix.

alison’s picture

Thank you @nick.dewitte and @joelpittet!

So, we need a version of the patch that has the fix and the tests, ya?

More broadly, though:
@nick.dewitte Are you saying that the patch you provided,
(1) allows the grants settings form to be saved (yay), and
(2) means that the grants settings from nodeaccess module will not have any impact on whether a user an see the node if it is unpublished, that determination is left up to whatever unpublished content perms exist on the site?

(Is that an accurate explanation, or?)

I think I'm fine with that concept. I'm ok with hearing other opinions, too, but it seeeeems logical to me that, unless additional nodeaccess-based permissions are added to account for viewing unpublished content (i.e. "view" + "edit" + "delete" + a new "view unpublished" perm), nodeaccess should not impact access to unpublished content. And, that feeeeeels like a safer setup -- I don't think people would want users with "view" access to automatically be able to view unpublished content -- right?