Problem/Motivation

If a user goes to /user, Drupal will redirect the user to their user profile, /user/[uid]. Drupal does not need to check if the user has permission to "access user profiles" because the user always has permission to view their own profile.

And, yet, template_preprocess_username() (D8) and theme_username() (D7) currently check for the "access user profiles" permission before adding a link to a user's own profile page. That's wrong.

Proposed resolution

Check if the currently logged in user is the same as the user account that the theme hook is linking to.

User interface changes

Previously, all themed usernames would have no links if the "access user profiles" permission was turned off for their user roles. After this patch, the current user's themed username would have a link to the profile page, while all other usernames would continue to have no links.

API changes

None.

Comments

johnalbin’s picture

Title: theme_username doesn't link to user's profile » themed username doesn't link to user's own profile
Issue tags: +Needs backport to D7
StatusFileSize
new1.29 KB
new1.26 KB

Here's the patch for D8 and D7.

johnalbin’s picture

Status: Active » Needs review

Test please!

Status: Needs review » Needs work

The last submitted patch, 1: 2536750-username-perm-D7.patch, failed testing.

johnalbin’s picture

Status: Needs work » Needs review
StatusFileSize
new1.26 KB

Renaming D7 patch.

The last submitted patch, 1: 2536750-username-perm.patch, failed testing.

johnalbin’s picture

StatusFileSize
new1.29 KB

Fixed simpletest.

Status: Needs review » Needs work

The last submitted patch, 6: 2536750-6-username-perm.patch, failed testing.

johnalbin’s picture

Status: Needs work » Needs review
StatusFileSize
new2.12 KB

Bah. uploaded wrong patch file. Here's the correct one.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

vermauv’s picture

I had applied the above patch to 8.1.x and the patch applies fine. I think the changes suggested by JohnAlbin are correct and checking if a user has permission to view her/his is redundant.

This is for the first time I am testing a patch hence not moving to RTBC, would seek feedback from some more folks as well.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dpi’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#1101958: Username template cannot always link to current user