Problem/Motivation

username template does not render a hyperlink if it is for the current user and the current user does not have the 'access user profiles' permission.

Proposed resolution

Use $user->access('view') instead of \Drupal::currentUser()->hasPermission('access user profiles') when determining whether the current user can see the link.

Original report by boombatower

Seems a bit odd that if a user does not have the 'access user profiles' permission they do not get a link to their own username even though they have permission to view their own profile.

Issue fork drupal-1101958

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

boombatower’s picture

Title: Change theme_username() to create links for current user always » Change theme_username() to always create a link for current user
boombatower’s picture

Assigned: Unassigned » boombatower
Status: Active » Needs review
FileSize
1.14 KB
boombatower’s picture

seems to have been missed by bot

Dave Reid’s picture

Maybe we should just use something like $variables['profile_access'] = drupal_valid_path('user/' . $account->uid); since that handles anything that modifies access to the user path?

boombatower’s picture

I mean this really leads down to user access API (or better yet entity access) which should allow a user access to itself.

drupalycious’s picture

#2: 1101958-theme-username.patch queued for re-testing.

drupalycious’s picture

this is what I am looking for since a while, will it be pushed to drupal core?

thanks

Status: Needs review » Needs work

The last submitted patch, 1101958-theme-username.patch, failed testing.

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.

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

Title: Change theme_username() to always create a link for current user » Username template cannot always link to current user
Assigned: boombatower » Unassigned
Issue summary: View changes
Related issues: +#849602: Update 'username' theme template to use 'view label' operation.

Confirmed this is still an issue in 8.3.x, updated issue summary.

dpi’s picture

Category: Feature request » Bug report
David_Rothstein’s picture

David_Rothstein’s picture

[removed duplicate comment]

dpi’s picture

Issue summary: View changes

Wrong access operation in sample code.

dpi’s picture

Assigned: Unassigned » dpi
dpi’s picture

Version: 8.2.x-dev » 8.3.x-dev
Status: Needs work » Needs review
FileSize
6.13 KB

Up for testing

For my reference: dpi/drupal/user-username-link-to-self-1101958

dpi’s picture

Issue summary: View changes

Removed a stray piece of text in issue summary

Status: Needs review » Needs work

The last submitted patch, 17: 1101958-user-username-link-to-self.patch, failed testing.

dpi’s picture

Test failure due to bug fix.

Fixed some tests that made an assumption that username would be in a <span>. These tests were showing a [`#theme` => 'username'] to the current user. In this case, the logged in user had administer users, but not access user profiles, which meant it could not view its own profile link.

Tests no longer assume username in a <span>. It will just get HTML inner-text.

Edit: whoops wrong file suffix for interdiff.

The last submitted patch, 20: user-username-link-to-self-1101958-20-interdiff.diff, failed testing.

dpi’s picture

Outline of patch (#20)

Some of template_preprocess_username() was refactored:
Removed $external and the Url object re-creation at the end of the function since we already have a Url object from the $account. There is no point in casting it to string then re-creating it.

Tests

Includes testing.

Setting 'uid' explicitly to avoid installing {sequences}. Using uid=2 to avoid any special treatment that uid=1 gets.

Uploading test only patch.

Status: Needs review » Needs work

The last submitted patch, 22: user-username-link-to-self-1101958-20-testonly.patch, failed testing.

dpi’s picture

Status: Needs work » Needs review

Patch #20 is ready for review

jibran’s picture

+++ b/core/modules/user/src/Tests/UserAdminListingTest.php
@@ -63,7 +63,7 @@ public function testUserListing() {
+      $name = strip_tags($account->td[0]->asXML());

Can't we use `$account->td[0]->a;`?

dpi’s picture

Can't we use `$account->td[0]->a;`?

No, because it is a mix of tags.

Logged in as 'admin', administer users, no access user profiles:

The test shows a list of users:

It is much easier to get inner text (the username), than to check existence of both td->span and td->a

User old code new code
admin <td><span>admin</span></td> <td><a>admin</a></td>
user2 <td><span>user2</span></td> <td><span>user2</span></td>
user3 <td><span>user3</span></td> <td><span>user3</span></td>
user... etc

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

borisson_’s picture

Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative, +Needs reroll

The patch in #20 no longer applies, but the test only change in #22 does seem to make sense and provest that this change fixes the problem.

The test will also need updating to the latest standards as well.

ajaypratapsingh’s picture

I tried to re-roll the patch #22 against drupal 9.5.x, mainly considered the points of @borrisson_ mentioned in comment #38

Status: Needs review » Needs work

The last submitted patch, 39: user_username_link_to_self-1101958-39.patch, failed testing. View results

borisson_’s picture

Looks like the patch in #39 did not include the actual fix but only the "test-only" patch, needs to have the fix also.

Medha Kumari’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
7.59 KB

Reroll the patch #43 with Drupal 9.5.x .

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Seems #42 is doing the same as #39 and not including the fix.

rpayanm made their first commit to this issue’s fork.

smustgrave’s picture

Status: Needs work » Closed (outdated)

Actually retesting this on D10.

Created an admin user and another userA
Using the Who's on block (edited it to be unrestricted)
UserA doesn't have the permission to "access user profiles"
When logged in as UserA the admin user is not hyperlinked but userA is.

So appears the issue has been resolved.