Let's start to convert all calls to user_access() with the new AccountInterface::hasPermission() method.

Part of #2048171: [meta] Replace user_access() calls with $account->hasPermission() wherever possible.

Change records for this issue:

Files: 
CommentFileSizeAuthor
#6 2062023-statistics-replace-user_access-calls-6.patch1.52 KBrhm50
PASSED: [[SimpleTest]]: [MySQL] 59,122 pass(es).
[ View ]
#6 interdiff-2062023-3-6.txt894 bytesrhm50
#3 2062023-statistics-replace-user_access-calls-3.patch1.51 KBrhm50
FAILED: [[SimpleTest]]: [MySQL] 58,532 pass(es), 5 fail(s), and 0 exception(s).
[ View ]
#3 interdiff-2062023-1-3.txt1.64 KBrhm50
#1 drupal-statistics_replace_user_access-2062023.patch1.59 KBInternetDevels
PASSED: [[SimpleTest]]: [MySQL] 57,868 pass(es).
[ View ]

Comments

Status:Active» Needs review
StatusFileSize
new1.59 KB
PASSED: [[SimpleTest]]: [MySQL] 57,868 pass(es).
[ View ]

Here is the patch.

Status:Needs review» Needs work
  1. +++ b/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php
    @@ -58,7 +58,7 @@ public function settings() {
    +    if (\Drupal::request()->attributes->get('_account')->hasPermission('access content')) {

    Suppose blocks should use current_user service via injection

  2. +++ b/core/modules/statistics/statistics.module
    @@ -58,7 +58,8 @@ function statistics_node_view(EntityInterface $node, EntityDisplay $display, $vi
    +    $account = Drupal::request()->attributes->get('_account');

    Drupal::currentUser()->hasPermission('view post access counter')

Status:Needs work» Needs review
StatusFileSize
new1.64 KB
new1.51 KB
FAILED: [[SimpleTest]]: [MySQL] 58,532 pass(es), 5 fail(s), and 0 exception(s).
[ View ]

Status:Needs review» Needs work

The last submitted patch, 2062023-statistics-replace-user_access-calls-3.patch, failed testing.

+++ b/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php
@@ -57,7 +57,7 @@ public function settings() {
+    if (Drupal::currentUser()->hasPermission('access content')) {

This needs '\' before Drupal at least

Status:Needs work» Needs review
StatusFileSize
new894 bytes
new1.52 KB
PASSED: [[SimpleTest]]: [MySQL] 59,122 pass(es).
[ View ]

Status:Needs review» Reviewed & tested by the community

this could go, but I wish a maintainer should decide about the usage of \Drupal here.
Probably better to file new issue to pass $account to block access() method

Yeah let's open an issue for that if there's not one already.

Status:Reviewed & tested by the community» Fixed

Committed/pushed to 8.x, thanks!

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