Hi, On a D9 site with the 8x dev release installed nodeaccess appears to be working correctly when using the defaults set.

If I try to override permissions for a specific node to add another role to view at /node/*/grants - when I click save the form reverts to the previous defaults.

A drush cr doesn't update it either. Am I doing something wrong or is this functionality not implemented yet?

Many thanks in advance,
Dan

Comments

Hitby created an issue. See original summary.

alison’s picture

Hi there,
D9 compatibility isn't stable yet, I'm afraid -- and, individual node permissions is one of the elements that's less finished than other pieces:
https://www.drupal.org/project/nodeaccess/issues/3130778#comment-13640220

I'm going to rename this issue, and add it to the D9 readiness issue as a blocker. I don't have the capacity to do more than that at this point in time, but at least it'll be recorded / organized. Thank you for your report!

alison’s picture

Title: Node permissions don't save » D9: Individual node permissions don't work
Hitby’s picture

Thanks Alison,
I'm not too far along so I'll rebuild in D8. It was always a risk jumping ahead.

waspper’s picture

It would be useful to get https://www.drupal.org/project/nodeaccess/issues/3070372 first. This, because some important changes are introduced there, and seems they will be needed here.

waspper’s picture

Just a note: For this issue, check please comment at https://www.drupal.org/project/nodeaccess/issues/3070372#comment-13837951. If patch/solution is provided there, then this issue could be solved in same commit.

waspper’s picture

StatusFileSize
new454 bytes
new448 bytes

At the end, if needed here, it's just about adding one more line. So, after discussing at https://www.drupal.org/project/nodeaccess/issues/3070372#comment-13837971, I'll provide 2 versions here:

3169639-7.patch: Normal patch on this issue, without any change.
3169639-7-apply-for-issue-3070372-15.patch: To appy AFTER patch https://www.drupal.org/project/nodeaccess/issues/3070372#comment-13837708 (#15).

waspper’s picture

Status: Active » Needs review
pvasener’s picture

Line added in the Patch #7 fixed the problem for me.

gantal’s picture

The patch in #7 (adding $node->save()) worked for me as well.

balis_m’s picture

Status: Needs review » Reviewed & tested by the community

Patch from #7 worked for me too.

balis_m’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new502 bytes

I' m sorry for changing the issue status again. I found out that the patch from #7 not working when I try to remove node permissions.

I solved it with this patch.

dasginganinja’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #12 worked swimmingly for me. The patch in #7 exhibited the same behavior that was noted in #12.

+1 RTBC so we can get a tagged D9 module!

alison’s picture

Thank you for all the work on this issue, everybody!

I haven't tested the actual bug fix part of this patch, I'm just commenting to report that it applies cleanly alongside the latest patch for D9 deprecated code fixes.

I'd love to hear from some folks from earlier in the thread about the latest version of the patch, if possible -- it's nerveracking to commit a patch on a module when I'm not in a position to do manual testing, and it doesn't have automated tests for D8, and it's already so janky.

If we don't get more reviews before the deprecated code fixes are ready to commit/release, my plan is to release the D9 compatible version without this fix, and then immediately commit this to dev, so at least it won't be in a tagged release right away -- better chances of hearing about whether it ended up causing regressions.

jungle’s picture

StatusFileSize
new129.25 KB
new121.6 KB
new153.41 KB

Manually tested #12 with a fresh Drupal 8.9.19 standard installation

Before: after saving, it shows nothing.

After: It does show saved grants, but it's incorrect. The reason is another code issue in \Drupal\nodeaccess\Form\GrantsForm::buildForm() from the line 70 to 87 below.

      // Load users from node_access.
      $query = $db->select('node_access', 'n');
      $query->join('users_field_data', 'ufd', 'ufd.uid = n.gid');
      $query->fields('n', ['grant_view', 'grant_update', 'grant_delete', 'nid']);
      $query->fields('ufd', ['name']);
      $query->condition('n.nid', $nid, '=');
      $query->condition('n.realm', 'nodeaccess_uid', '=');
      $query->orderBy('ufd.name', 'ASC');
      $results = $query->execute();
      while ($acounts = $results->fetchAssoc()) {
        $form_values['uid'][$account->uid] = [
          'name' => $account->name,
          'keep' => 1,
          'grant_view' => $account->grant_view,
          'grant_update' => $account->grant_update,
          'grant_delete' => $account->grant_delete,
        ];
      }
jungle’s picture

Continue with #15

      while ($acounts = $results->fetchAssoc()) {
        $form_values['uid'][$account->uid] = [

1. $acounts with a typo should be $accounts by guessing from the context. It may be while ($account = $results->fetchAssoc()) {, or the variable $account in the next line is undefined.
2. Meanwhile, $account->uid is accessing an object, So, $results->fetchAssoc() should be $results->fetchObject()
3. Furthermore, $query->fields('ufd', ['name']); should be $query->fields('ufd', ['name', 'uid']); to return the uid, or $account->uid in $form_values['uid'][$account->uid] is undefined again.

The extra patch looks like the following which was posted to both #3061378: Table name typo? and #3185156: Permission to individual Users throws error on grants tab of nodes

       $query = $db->select('node_access', 'n');
       $query->join('users_field_data', 'ufd', 'ufd.uid = n.gid');
       $query->fields('n', ['grant_view', 'grant_update', 'grant_delete', 'nid']);
-      $query->fields('ufd', ['name']);
+      $query->fields('ufd', ['name', 'uid']);
       $query->condition('n.nid', $nid, '=');
       $query->condition('n.realm', 'nodeaccess_uid', '=');
       $query->orderBy('ufd.name', 'ASC');
       $results = $query->execute();
-      while ($acounts = $results->fetchAssoc()) {
+      while ($account = $results->fetchObject()) {
         $form_values['uid'][$account->uid] = [
           'name' => $account->name,
           'keep' => 1,
jungle’s picture

StatusFileSize
new177.24 KB

Combined with the patch mentioned in #16, manually tested it again, it works as expected

jungle’s picture

Issue tags: +Needs followup
StatusFileSize
new893 bytes
new1.21 KB
+++ b/src/Form/GrantsForm.php
@@ -347,6 +347,7 @@ class GrantsForm extends FormBase {
+    \Drupal::service('node.grant_storage')->write($node, $grants);

Should be replaced with Dependency injection. This is not the only one that needs work. Tagging Needs followup. Let's do it in another one.

Uploading the new patch. As the extra changes are just two lines of code. I'd keep it as RTBC, and I will commit it next with the confidence got from the manual tests above.

  • jungle committed 355f010 on 8.x-1.x authored by balis_m
    Issue #3169639 by waspper, jungle, balis_m, Hitby, alisonjo315, pvasener...
jungle’s picture

Status: Reviewed & tested by the community » Fixed
jungle’s picture

Status: Fixed » Closed (fixed)

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