--- 1349080-439.patch 2020-05-29 11:56:36.147937067 +0300 +++ 1349080-444.patch 2020-05-29 12:16:22.652926904 +0300 @@ -1,5 +1,5 @@ diff --git a/core/modules/node/src/NodeGrantDatabaseStorage.php b/core/modules/node/src/NodeGrantDatabaseStorage.php -index d273359be1..47d4724776 100644 +index bacd952c36..bb3a98676e 100644 --- a/core/modules/node/src/NodeGrantDatabaseStorage.php +++ b/core/modules/node/src/NodeGrantDatabaseStorage.php @@ -3,6 +3,7 @@ @@ -10,7 +10,7 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Query\Condition; -@@ -152,16 +153,29 @@ public function alterQuery($query, array $tables, $op, AccountInterface $account +@@ -152,6 +153,14 @@ public function alterQuery($query, array $tables, $op, AccountInterface $account $langcode = FALSE; } @@ -25,22 +25,17 @@ // Find all instances of the base table being joined -- could appear // more than once in the query, and could be aliased. Join each one to // the node_access table. - $grants = node_access_grants($op, $account); -+ - // If any grant exists for the specified user, then user has access to the - // node for the specified operation. - $grant_conditions = static::buildGrantsQueryCondition($grants); +@@ -162,6 +171,9 @@ public function alterQuery($query, array $tables, $op, AccountInterface $account $grants_exist = count($grant_conditions->conditions()) > 0; $is_multilingual = \Drupal::languageManager()->isMultilingual(); -+ + // The main loop is using $tables instead of $tables_ref -- if for any + // reason the two arrays differ, technically this function has been + // told to operate on the entries listed in $tables. foreach ($tables as $nalias => $tableinfo) { $table = $tableinfo['table']; if (!($table instanceof SelectInterface) && $table == $base_table) { -@@ -192,7 +206,26 @@ public function alterQuery($query, array $tables, $op, AccountInterface $account +@@ -192,7 +204,26 @@ public function alterQuery($query, array $tables, $op, AccountInterface $account // Now handle entities. $subquery->where("$nalias.$field = na.nid"); @@ -68,12 +63,51 @@ } } } +@@ -210,7 +241,16 @@ public function write(NodeInterface $node, array $grants, $realm = NULL, $delete + } + // Only perform work when node_access modules are active. + if (!empty($grants) && count($this->moduleHandler->getImplementations('node_grants'))) { +- $query = $this->database->insert('node_access')->fields(['nid', 'langcode', 'fallback', 'realm', 'gid', 'grant_view', 'grant_update', 'grant_delete']); ++ $query = $this->database->insert('node_access')->fields([ ++ 'nid', ++ 'langcode', ++ 'fallback', ++ 'realm', ++ 'gid', ++ 'grant_view', ++ 'grant_update', ++ 'grant_delete', ++ ]); + // If we have defined a granted langcode, use it. But if not, add a grant + // for every language this node is translated to. + $fallback_langcode = $node->getUntranslated()->language()->getId(); +@@ -257,13 +297,13 @@ public function delete() { + public function writeDefault() { + $this->database->insert('node_access') + ->fields([ +- 'nid' => 0, +- 'realm' => 'all', +- 'gid' => 0, +- 'grant_view' => 1, +- 'grant_update' => 0, +- 'grant_delete' => 0, +- ]) ++ 'nid' => 0, ++ 'realm' => 'all', ++ 'gid' => 0, ++ 'grant_view' => 1, ++ 'grant_update' => 0, ++ 'grant_delete' => 0, ++ ]) + ->execute(); + } + diff --git a/core/modules/node/src/Tests/NodeAccessJoinTest.php b/core/modules/node/src/Tests/NodeAccessJoinTest.php new file mode 100644 -index 0000000000..d5e690ef20 +index 0000000000..9042781a39 --- /dev/null +++ b/core/modules/node/src/Tests/NodeAccessJoinTest.php -@@ -0,0 +1,351 @@ +@@ -0,0 +1,357 @@ +save(); + -+ entity_get_display('node', 'page', 'default') ++ /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */ ++ $display_repository = \Drupal::service('entity_display.repository'); ++ $display_repository->getViewDisplay('node', 'page', 'default') + ->setComponent('related_article') + ->save(); -+ entity_get_form_display('node', 'page', 'default') ++ $display_repository->getFormDisplay('node', 'page', 'default') + ->setComponent('related_article', [ + 'type' => 'entity_reference_autocomplete', + ]) @@ -203,10 +243,10 @@ + ]); + $field->save(); + -+ entity_get_display('node', 'article', 'default') ++ $display_repository->getViewDisplay('node', 'article', 'default') + ->setComponent('related_article') + ->save(); -+ entity_get_form_display('node', 'article', 'default') ++ $display_repository->getFormDisplay('node', 'article', 'default') + ->setComponent('related_article', [ + 'type' => 'entity_reference_autocomplete', + ]) @@ -287,9 +327,9 @@ + $node = $this->drupalCreateNode($edit); + $this->articles[$article][$reference2] = $node->id(); + -+ $this->assertEqual((int) $is_private, (int) $node->private->value, 'The private status of the article node was properly set in the node_access_test table.' . $node->uid->target_id); ++ $this->assertEquals((int) $is_private, (int) $node->private->value, 'The private status of the article node was properly set in the node_access_test table.' . $node->uid->target_id); + if ($reference2 != 'no_reference') { -+ $this->assertEqual((int) $this->articles[$reference2]['no_reference'], (int) $node->related_article->target_id, 'Proper article attached to article.'); ++ $this->assertEquals((int) $this->articles[$reference2]['no_reference'], (int) $node->related_article->target_id, 'Proper article attached to article.'); + } + } + } @@ -320,7 +360,7 @@ + } + $node = $this->drupalCreateNode($edit); + if ($article_nid) { -+ $this->assertEqual((int) $article_nid, (int) $node->related_article->target_id, 'Proper article attached to page.'); ++ $this->assertEquals((int) $article_nid, (int) $node->related_article->target_id, 'Proper article attached to page.'); + } + + // Calculate totals expected for each user type @@ -373,36 +413,36 @@ + $this->drupalLogin($this->authorUser); + $this->drupalGet('test-node-access-join'); + $chk_total = count($this->xpath("//td[@headers='view-title-table-column']")); -+ $this->assertEqual($chk_total, $total, 'Author should see ' . $total . ' rows. Actual: ' . $chk_total); ++ $this->assertEquals($chk_total, $total, 'Author should see ' . $total . ' rows. Actual: ' . $chk_total); + $chk_total = count($this->xpath("//td[@headers='view-title-1-table-column']/a")); -+ $this->assertEqual($chk_total, $count_s_author, 'Author should see ' . $count_s_author . ' primary references. Actual: ' . $chk_total); ++ $this->assertEquals($chk_total, $count_s_author, 'Author should see ' . $count_s_author . ' primary references. Actual: ' . $chk_total); + $chk_total = count($this->xpath("//td[@headers='view-title-2-table-column']/a")); -+ $this->assertEqual($chk_total, $count_s2_author, 'Author should see ' . $count_s2_author . ' secondary references. Actual: ' . $chk_total); -+ $this->assertText('Page - no_reference', 'Author should see page with no reference.'); -+ $this->assertText('Page - public - no_reference', 'Author should see page with one public reference.'); -+ $this->assertText('Page - public - public', 'Author should see page with two public references.'); -+ $this->assertText('Page - author_private - no_reference', 'Author should see page with own private reference.'); -+ $this->assertText('Article public', 'Author should see articles with access type: public.'); -+ $this->assertNoText('Article private', 'Author should not see articles with access type: private.'); -+ $this->assertText('Article author_public', 'Author should see articles with access type: author_public.'); -+ $this->assertText('Article author_private', 'Author should see articles with access type: author_private.'); ++ $this->assertEquals($chk_total, $count_s2_author, 'Author should see ' . $count_s2_author . ' secondary references. Actual: ' . $chk_total); ++ $this->assertSession()->responseContains('Page - no_reference', 'Author should see page with no reference.'); ++ $this->assertSession()->responseContains('Page - public - no_reference', 'Author should see page with one public reference.'); ++ $this->assertSession()->responseContains('Page - public - public', 'Author should see page with two public references.'); ++ $this->assertSession()->responseContains('Page - author_private - no_reference', 'Author should see page with own private reference.'); ++ $this->assertSession()->responseContains('Article public', 'Author should see articles with access type: public.'); ++ $this->assertSession()->responseNotContains('Article private', 'Author should not see articles with access type: private.'); ++ $this->assertSession()->responseContains('Article author_public', 'Author should see articles with access type: author_public.'); ++ $this->assertSession()->responseContains('Article author_private', 'Author should see articles with access type: author_private.'); + // Check a regular user (who did not author any articles). + $this->regularUser = $this->drupalCreateUser(['access content']); + $this->drupalLogin($this->regularUser); + $this->drupalGet('test-node-access-join'); + $chk_total = count($this->xpath("//td[@headers='view-title-table-column']")); -+ $this->assertEqual($chk_total, $total, 'Public user should see ' . $total . ' rows. Actual: ' . $chk_total); ++ $this->assertEquals($chk_total, $total, 'Public user should see ' . $total . ' rows. Actual: ' . $chk_total); + $chk_total = count($this->xpath("//td[@headers='view-title-1-table-column']/a")); -+ $this->assertEqual($chk_total, $count_s_public, 'Public user should see ' . $count_s_public . ' primary references. Actual: ' . $chk_total); ++ $this->assertEquals($chk_total, $count_s_public, 'Public user should see ' . $count_s_public . ' primary references. Actual: ' . $chk_total); + $chk_total = count($this->xpath("//td[@headers='view-title-2-table-column']/a")); -+ $this->assertEqual($chk_total, $count_s2_public, 'Public user should see ' . $count_s2_public . ' secondary references. Actual: ' . $chk_total); -+ $this->assertText('Page - no_reference', 'Public user should see page with no reference.'); -+ $this->assertText('Page - public - no_reference', 'Public user should see page with one public reference.'); -+ $this->assertText('Page - public - public', 'Public user should see page with two public references.'); -+ $this->assertText('Article public', 'Public user should see articles with access type: public.'); -+ $this->assertNoText('Article private', 'Public user should not see articles with access type: private.'); -+ $this->assertText('Article author_public', 'Public user should see articles with access type: author_public.'); -+ $this->assertNoText('Article author_private', 'Public user should not see articles with access type: author_private.'); ++ $this->assertEquals($chk_total, $count_s2_public, 'Public user should see ' . $count_s2_public . ' secondary references. Actual: ' . $chk_total); ++ $this->assertSession()->responseContains('Page - no_reference', 'Public user should see page with no reference.'); ++ $this->assertSession()->responseContains('Page - public - no_reference', 'Public user should see page with one public reference.'); ++ $this->assertSession()->responseContains('Page - public - public', 'Public user should see page with two public references.'); ++ $this->assertSession()->responseContains('Article public', 'Public user should see articles with access type: public.'); ++ $this->assertSession()->responseNotContains('Article private', 'Public user should not see articles with access type: private.'); ++ $this->assertSession()->responseContains('Article author_public', 'Public user should see articles with access type: author_public.'); ++ $this->assertSession()->responseNotContains('Article author_private', 'Public user should not see articles with access type: author_private.'); + // Check a user with the special 'node test view' permission, who should + // be able to view all pages and articles. + $this->accessUser = $this->drupalCreateUser(['access content', 'node test view']); @@ -411,22 +451,22 @@ + $chk_total = count($this->xpath("//td[@headers='view-title-table-column']")); + $this->assertEqual($chk_total, $total, 'Full-access user should see ' . $total . ' rows. Actual: ' . $chk_total); + $chk_total = count($this->xpath("//td[@headers='view-title-1-table-column']/a")); -+ $this->assertEqual($chk_total, $count_s_total, 'Full-access user should see ' . $count_s_total . ' primary references. Actual: ' . $chk_total); ++ $this->assertEquals($chk_total, $count_s_total, 'Full-access user should see ' . $count_s_total . ' primary references. Actual: ' . $chk_total); + $chk_total = count($this->xpath("//td[@headers='view-title-2-table-column']/a")); -+ $this->assertEqual($chk_total, $count_s2_total, 'Full-access user should see ' . $count_s2_total . ' secondary references. Actual: ' . $chk_total); -+ $this->assertText('Page - no_reference', 'Full-access user should see page with no reference.'); -+ $this->assertText('Page - public - no_reference', 'Full-access user should see page with one public reference.'); -+ $this->assertText('Page - public - public', 'Full-access user should see page with two public references.'); -+ $this->assertText('Page - author_private - no_reference', 'Full-access user should see page with author_private reference.'); -+ $this->assertText('Article public', 'Full-access user should see articles with access type: public.'); -+ $this->assertText('Article private', 'Full-access user should see articles with access type: private.'); -+ $this->assertText('Article author_public', 'Full-access user should see articles with access type: author_public.'); -+ $this->assertText('Article author_private', 'Full-access user should see articles with access type: author_private.'); ++ $this->assertEquals($chk_total, $count_s2_total, 'Full-access user should see ' . $count_s2_total . ' secondary references. Actual: ' . $chk_total); ++ $this->assertSession()->responseContains('Page - no_reference', 'Full-access user should see page with no reference.'); ++ $this->assertSession()->responseContains('Page - public - no_reference', 'Full-access user should see page with one public reference.'); ++ $this->assertSession()->responseContains('Page - public - public', 'Full-access user should see page with two public references.'); ++ $this->assertSession()->responseContains('Page - author_private - no_reference', 'Full-access user should see page with author_private reference.'); ++ $this->assertSession()->responseContains('Article public', 'Full-access user should see articles with access type: public.'); ++ $this->assertSession()->responseContains('Article private', 'Full-access user should see articles with access type: private.'); ++ $this->assertSession()->responseContains('Article author_public', 'Full-access user should see articles with access type: author_public.'); ++ $this->assertSession()->responseContains('Article author_private', 'Full-access user should see articles with access type: author_private.'); + } + +} diff --git a/core/modules/node/tests/modules/node_access_test/node_access_test.module b/core/modules/node/tests/modules/node_access_test/node_access_test.module -index 589accef27..27513588e0 100644 +index 6ef55224d3..36219a1339 100644 --- a/core/modules/node/tests/modules/node_access_test/node_access_test.module +++ b/core/modules/node/tests/modules/node_access_test/node_access_test.module @@ -79,7 +79,7 @@ function node_access_test_node_grants($account, $op) {