Rebuild permissions gives me :

Fatal error: Using $this when not in object context in /path/to/drupal8/core/modules/node/node.module on line 1296

This is caused by this oversight in _node_access_rebuild_batch_operation() :

$node_storage = $this->container->get('entity.manager')->getStorage('node');

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

willzyx’s picture

Patch attached

aspilicious’s picture

I wanted to RTBC this but realised we don't have any tests for this...

willzyx’s picture

Berdir’s picture

Status: Needs review » Needs work

Nice find, we also need a combined patch with the fix and the tests now.

Test looks correct, just a bunch of nitpicks...

  1. +++ b/core/modules/node/src/Tests/NodeAccessRebuildNodeGrantsTest.php
    @@ -0,0 +1,39 @@
    + * Definition of Drupal\node\Tests\NodeAccessRebuildNodeGrantsTest.
    

    Should be contains, with a leading \: \Drupal\node\...

  2. +++ b/core/modules/node/src/Tests/NodeAccessRebuildNodeGrantsTest.php
    @@ -0,0 +1,39 @@
    +
    +
    +namespace Drupal\node\Tests;
    

    Should only have one empty line.

  3. +++ b/core/modules/node/src/Tests/NodeAccessRebuildNodeGrantsTest.php
    @@ -0,0 +1,39 @@
    +class NodeAccessRebuildNodeGrantsTest extends NodeTestBase{
    

    Missing space before {

  4. +++ b/core/modules/node/src/Tests/NodeAccessRebuildNodeGrantsTest.php
    @@ -0,0 +1,39 @@
    +
    +  public static $modules = array('node', 'node_access_test');
    +
    +  protected function setUp() {
    +    parent::setUp();
    

    setUp() needs an @inheritdoc and the modules needs the usual Modules to enable @var array.

    Isn't node already enabled by default in NodeTestBase?

  5. +++ b/core/modules/node/src/Tests/NodeAccessRebuildNodeGrantsTest.php
    @@ -0,0 +1,39 @@
    +    $web_user = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'access site reports'));
    +    $this->drupalLogin($web_user);
    +    $this->web_user = $web_user;
    

    No need to assign the user, you don't need it anymore later.

willzyx’s picture

Status: Needs work » Needs review
FileSize
2.01 KB

@Berdir
Coding standards issues were resolved. Thanks for reviewing

Combined patch with the fix and the tests is attached

dawehner’s picture

Wow!

  1. +++ b/core/modules/node/src/Tests/NodeAccessRebuildNodeGrantsTest.php
    @@ -0,0 +1,45 @@
    + * Definition of \Drupal\node\Tests\NodeAccessRebuildNodeGrantsTest.
    

    Certainly optional nitpick: You could use "Contains \Drupal\node ..."

  2. +++ b/core/modules/node/src/Tests/NodeAccessRebuildNodeGrantsTest.php
    @@ -0,0 +1,45 @@
    +    $this->drupalGet('admin/reports/status');
    +    $this->clickLink(t('Rebuild permissions'));
    +    $this->drupalPostForm(NULL, array(), t('Rebuild permissions'));
    +    $this->assertText(t('The content access permissions have been rebuilt.'));
    

    What about adding a quick check that the rebuild was actually successfull? You could for example try the 'node.grant_storage' service ... to fetch entries.

dawehner’s picture

Status: Needs review » Needs work

.

willzyx’s picture

@dawehner

1) There are ~35 test cases that use "Definition of Drupal\node\.." ( without a leading \ ) in the node module.. what is the way to follow?

2) I'm not sure what you mean.. Aren't we verifing that node access rebuild functions work correctly even when other modules implements hook_node_grants()? isn't better to delegate to a separate test case the check that rebuild (according to the assignment of the grants defined in node_test_access) was actually successfull?

pcambra’s picture

Status: Needs work » Needs review
FileSize
4.01 KB
4.21 KB

New patch taking into account #8, added a few tests using the grant storage service

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

1) There are ~35 test cases that use "Definition of Drupal\node\.." ( without a leading \ ) in the node module.. what is the way to follow?

Contains is kind of the standard since 2 years, but we just had a hard time updating the old one :)

nice tests!

amateescu’s picture

Version: 8.0.0-beta4 » 8.0.x-dev

I found two small nitpicks, sorry :/

  1. +++ b/core/modules/node/src/Tests/NodeAccessRebuildNodeGrantsTest.php
    @@ -0,0 +1,85 @@
    +  protected $web_user;
    

    Any reason to not use camel case here? :)

  2. +++ b/core/modules/node/src/Tests/NodeAccessRebuildNodeGrantsTest.php
    @@ -0,0 +1,85 @@
    +  function testNodeAccessRebuildNodeGrants() {
    ...
    +  function testNodeAccessRebuildNoAccessModules() {
    

    These two need the member visibility (public).

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

For #14

alexpott’s picture

Title: Fatal error rebuilding permissions » Fatal error rebuilding node access permissions

Fixing the title to be a bit more specific.

alexpott’s picture

Priority: Major » Critical

This actually must be a critical because if this does not work then there are possible security implications.

pcambra’s picture

Status: Needs work » Needs review
FileSize
3.2 KB
4.22 KB

Thanks for the review @amateescu, here's a new patch fixing #14

dawehner’s picture

Feedback got addressed

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Yup :)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 33eb65a and pushed to 8.0.x. Thanks!

  • alexpott committed 33eb65a on 8.0.x
    Issue #2396519 by pcambra, willzyx: Fatal error rebuilding node access...

Status: Fixed » Closed (fixed)

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