Closed (fixed)
Project:
Profile
Version:
8.x-1.x-dev
Component:
User interface
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
14 Jun 2017 at 08:34 UTC
Updated:
26 Jul 2019 at 20:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
beeyayjay commentedHere's a simple patch that filters out profile type tabs if the user doesn't have the right roles.
Comment #3
beeyayjay commentedSorry, the above patch doesn't work properly with caching. The tab set gets cached and not updated for each user.
Comment #4
mglamanThe work has to be done in the access handler. The check is here: \Drupal\profile\ProfileAccessControlHandler::checkCreateAccess
Comment #5
beeyayjay commentedThanks, 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.
Comment #7
johnhanley commentedWhat's the status of this patch? As administrator, I only want to see profile tabs for roles belonging to the current user.
Comment #8
k4v commentedThis patch works nicely for me :). We should fix the failing tests...
Comment #9
k4v commentedComment #10
k4v commentedOh wait, the tests are fine for 8.7 & PHP7.2. Go! :)
Comment #11
mglamanWe definitely need tests for this.
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?
Comment #12
mglamanLet's update the title and summary as well. #7 sums it up nicely:
Comment #13
bojanz commentedMarked #3052434: Profile does not respect the specified roles as expected as a duplicate.
Comment #14
jsacksick commentedI 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.
Comment #15
jsacksick commentedActually, I wonder if we should simply update
ProfileAccessControlHandlerand overridecheckAccess()there to also check the role setting, even if the permissions allow the operation (just likecheckCreateAccess()) although the role setting wasn't probably designed for that.Comment #16
bojanz commentedjsacksick 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.
Comment #17
jsacksick commentedI 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().Comment #19
jsacksick commentedComment #21
jsacksick commentedCoding standard fixes... I don't really understand the tests failure (the failing test passes for me locally).
Comment #23
jsacksick commentedSorry for the noise!
Comment #24
jsacksick commentedCoding standard fixes.
Comment #25
jsacksick commentedExpanded testProfileCreate() a bit.
Comment #27
bojanz commentedThank you jsacksick, just in time for one last release candidate.
Cleaned up testProfileCreate() pre-commit to be a bit clearer.