I notice that the profile tab is displayed on the user edition when edit it with an admin roles even if the profil type has ben restrited to some role in the configuration page of the profile type "admin/config/people/profiles/types/manage/[profile type]" by checking roles on "Limit the users that can have this profile by role."

Comments

steveoriol created an issue. See original summary.

beeyayjay’s picture

StatusFileSize
new1.06 KB

Here's a simple patch that filters out profile type tabs if the user doesn't have the right roles.

beeyayjay’s picture

Sorry, the above patch doesn't work properly with caching. The tab set gets cached and not updated for each user.

mglaman’s picture

Status: Active » Needs work

The work has to be done in the access handler. The check is here: \Drupal\profile\ProfileAccessControlHandler::checkCreateAccess

      $bundle = ProfileType::load($entity_bundle);
      if (!empty(array_filter($bundle->getRoles()))) {
        $result = AccessResult::allowedIf(!empty(array_intersect($account->getRoles(), $bundle->getRoles())));
      }
beeyayjay’s picture

Status: Needs work » Needs review
StatusFileSize
new723 bytes

Thanks, mglaman. I updated the access function, using code from \Drupal\profile\ProfileAccessControlHandler::checkCreateAccess. I also added a check to make sure that at least one role had been selected for the profile before testing the role intersection.

Status: Needs review » Needs work

The last submitted patch, 5: check-permitted-roles-2886029-5.patch, failed testing. View results

johnhanley’s picture

What's the status of this patch? As administrator, I only want to see profile tabs for roles belonging to the current user.

k4v’s picture

This patch works nicely for me :). We should fix the failing tests...

k4v’s picture

Status: Needs work » Reviewed & tested by the community
k4v’s picture

Oh wait, the tests are fine for 8.7 & PHP7.2. Go! :)

mglaman’s picture

Status: Reviewed & tested by the community » Needs work

We definitely need tests for this.

+++ b/src/Access/ProfileAccessCheck.php
@@ -50,6 +50,10 @@ class ProfileAccessCheck implements AccessInterface {
+    if (!empty(array_diff($profile_type->getRoles(), ["0"])) && empty(array_intersect($user->getRoles(), $profile_type->getRoles()))) {

I don't understand this line and the magic ["0"]

array_diff($profile_type->getRoles(), ["0"]))

Is this just to check if it's restricted?

mglaman’s picture

Let's update the title and summary as well. #7 sums it up nicely:

As administrator, I only want to see profile tabs for roles belonging to the current user.

bojanz’s picture

Title: Profile tab is displayed when not need... » Profile tab access does not respect the "roles" setting
Version: 8.x-1.0-alpha7 » 8.x-1.x-dev
jsacksick’s picture

Status: Needs work » Needs review

I just posted a patch for review in https://www.drupal.org/project/profile/issues/3064457#comment-1317309 that should also address this issue.

The permissions are checked first, and if the access is allowed using the permissions, then the role setting isn't checked.
Using the patch, the access can be granted using either the permissions or the roles setting.

jsacksick’s picture

Status: Needs review » Needs work

Actually, I wonder if we should simply update ProfileAccessControlHandler and override checkAccess() there to also check the role setting, even if the permissions allow the operation (just like checkCreateAccess()) although the role setting wasn't probably designed for that.

bojanz’s picture

jsacksick and myself spent a long time reviewing this bug. Turns out that the access logic has been broken since beta1.

There are two problems:
1) We check roles for "create" access, but not "update" / "delete" access.
2) When checking "update" / "delete" access, we need to check against the entity owner, not $account, so that admins can't see the tab on the user pages either.

Before beta1 we had checkAccess() and it used the entity owner to perform the check. It's obvious that we're missing test coverage (despite having two kernel access tests), which caused this regression to happen.

jsacksick’s picture

Status: Needs work » Needs review
StatusFileSize
new26.42 KB

I got rid of ProfileAccessTest and moved all the access tests into ProfileRoleAccessTest.

I'm not 100% satisfied with the signature of testProfileRoutesAccessCheck() wanted to pass an array of roles instead of booleans for the 2 last parameters but dataProviders are actually called before setUp().

Status: Needs review » Needs work

The last submitted patch, 17: profile_2886029-17.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jsacksick’s picture

Status: Needs work » Needs review
StatusFileSize
new26.41 KB
new616 bytes

Status: Needs review » Needs work

The last submitted patch, 19: profile_2886029-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jsacksick’s picture

Status: Needs work » Needs review
StatusFileSize
new26.99 KB
new4.29 KB

Coding standard fixes... I don't really understand the tests failure (the failing test passes for me locally).

Status: Needs review » Needs work

The last submitted patch, 21: profile_2886029-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jsacksick’s picture

Status: Needs work » Needs review
StatusFileSize
new26.83 KB
new579 bytes

Sorry for the noise!

jsacksick’s picture

StatusFileSize
new26.9 KB
new1.77 KB

Coding standard fixes.

jsacksick’s picture

StatusFileSize
new27.54 KB
new1.52 KB

Expanded testProfileCreate() a bit.

  • bojanz committed 70b1bab on 8.x-1.x authored by jsacksick
    Issue #2886029 by jsacksick, beeyayjay, bojanz: Profile tab access does...
bojanz’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests, -Needs issue summary update

Thank you jsacksick, just in time for one last release candidate.

Cleaned up testProfileCreate() pre-commit to be a bit clearer.

Status: Fixed » Closed (fixed)

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