Closed (duplicate)
Project:
Profile 2
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
28 Oct 2015 at 17:27 UTC
Updated:
18 Mar 2018 at 21:50 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
joelpittetHow about this? It also makes a slight improvement to the administer profiles for micro performance optimization.
Comment #3
spleshkaHi Joël, the fix looks quite good & obvious, I'm happy to commit it. Just before I did it - can you please tell me how can I reproduce the similar issue? Thanks.
Comment #4
joelpittetI just noticed in my error log and doesn't happen often.
Though if profile is default null like the docs say it can be it with throw this notice
Comment #5
spleshkaIf we don't know the reason of this issue then I'm not sure that the suggested fix solves it. Can you tell me if the backlog shows you that notices are thrown by a user with "administer profiles" permission?
Comment #6
joelpittet@Spleshka it does fix it because your function parameter defaults to NULL and the docs say it is optional.
So regardless of where the error came from the expected code path of an optional profile is that it can deal with $profile being not a profile object and therefore doesn't have a type property.
To reproduce just call:
Here's some tests to help prove this. Also I noticed the defaults on $account weren't defaulting like the param docblock says so I added a test for that too.
Comment #7
joelpittetComment #10
joelpittetWhoops too used to D8's short array syntax.
Comment #12
joelpittetWhoops, don't use #10 that opens up some security issues because there is a $user variable in that function. I renamed it and this one is much better.
Comment #13
spleshkaThanks for the patch with test, @joelpittet. My only concern about your patch is that you change the behavior of the $account variable. Previously, when profile2_access() were used without 3rd argument then hook_profile2_access() passed NULL as a third param. Your patch changes this behavior to always have an object there. So if somebody implemented that hook and checked $account variable using empty/isset functions (or NULL), then this patch will introduce issues. Also I don't see a necessity to change the behavior for the $account variable. I've updated the patch with minor change in the code logic & removed the force set of $account variable. How does it look to you now?
Comment #14
joelpittet@Spleshka I did that because that's what
user_access()does it. But since user_access() does that for itself and I'd have to assume that the implementations of hook_profile2_access() can deal with the NULL value already, then that is fine.I guess I can't RTBC my own patch but maybe you feel comfortable enough with the tests and such that it's worth committing?
Comment #16
spleshkaCommited. Thanks for the issue, @joelpittet.
Comment #18
thomas bosviel commentedI think this commit introduces a bug. Roles assigned to the profile type are never checked.
Comment #19
rickj commentedThe bug in #18 was identified and corrected in #2683917, now committed.