-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False negative for Craft::$app->getUser()->getIsAdmin() in a plugin #2473
Comments
I was able to reproduce this on Control Panel requests. Issue is that on CP requests, plugins are first initialized right in the midst of Craft/Yii fetching the logged-in user, in the process of setting the application language based on the user’s preferred language. Until it’s done, (It’s not an issue on front-end requests because the application language is determined by the current site on front-end requests, not the logged-in user.) This bug was introduced by 1bbd5ac, which fixed #2439. Beforehand, plugins were loaded before Craft went on to set the application language, which is all well and good unless a plugin happens to need to load the To fix both bugs (#2439 and this one), we just need to be able to get the logged-in user’s preferred language without actually fetching the logged-in user. |
As of Craft 4.0.0-RC1, I'm no longer able to reproduce this issue 🎉 |
This was supposedly fixed four years ago. Not the case? |
Pardon the confusion, my brain wasn't fully plugged in before. This original issue in Craft is fixed; I guess I've just been using this as a bookmark for when the same problem is triggered via modules or plugins – a thing that still crops up from time to time and that I can consistently reproduce on 3.7.39, but not on 4.0 (hence the excitement). Like the similar/related #8733 this should probably be considered a plugin issue though (and in any case should've had its own issue years ago, instead of referring back to this one). Sorry for the noise 😅 |
Hah, alright, well I’m glad we inadvertently did something to fix it further :) |
Description
In a site upgraded from RC 10.1 to RC 11, I'm seeing some odd behaviour where the
Craft::$app->getUser()->getIsAdmin()
method returnsfalse
when called from a plugin'sinit
method, even if the logged in user is an admin.Specifically, this is an issue with my CP Field Inspect plugin, but I've also tested it with different plugins, and the same thing happens with all of them. As far as I've been able to figure out,
getIsAdmin()
actually returnsfalse
becauseUser::getIdentity()
returnsnull
... for some reason.To make things weirder, this does not happen on a different, clean install of RC 11. However, other users are seeing the same thing as me on their upgraded RC11 installs.
Probably related: I'm also seeing similarly odd behaviour with
Craft::$app->getFields()->getAllFields();
, which returns an empty array when called from a plugin'sinit
method, although there are definitely fields in the site.Disabling/enabling or even re-installing the affected plugin(s) does not help. I've also tried clearing out all caches and emptying all sessions/cookies/localstorage.
Steps to reproduce
Craft::$app->getUser()->getIsAdmin();
from a plugin'sinit()
method, confirm it returnsfalse
Additional info
The text was updated successfully, but these errors were encountered: