Jump to content

Detecting superuser when User Switcher active


Robin S
 Share

Recommended Posts

Hi @adrian,

If I'm working on a site that other users have access to I'll often do something like:

if($user->isSuperuser()) {
    // Run this code for me only
    //...
}

But if I'm presenting as another user via the User Switcher panel then this won't work.

Do you know of an easy way to check if the current user is in reality a superuser but is currently browsing via User Switcher?

Thanks for any suggestions.

Link to comment
Share on other sites

$user->isSuperuser() will return false just like you show in your screenshot, which is expected because User Switcher is active. But what I'm wanting is something like the pseudocode $user->isReallySuperuser() that would return true when User Switcher is active. 

Now it doesn't need to be some method of $user, but I'm wondering if Tracy might be able to offer something that allows for a simple way to check if User Switcher is active and being used by a superuser (not sure if users less than superuser could even access User Switcher - I've never needed to allow that). Or maybe Tracy already does expose something that could be easily checked for this purpose?

Link to comment
Share on other sites

2 minutes ago, adrian said:

There is the $session->tracyUserSwitcherId which is set whenever a user switcher session is active.

Does that help?

Yep, perfect, thanks!

Just to spell it out for any future readers...

if($session->tracyUserSwitcherId) {
    // Run this code only if browsing via User Switcher
    //...
}

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...