Jump to content

Recommended Posts

Posted

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.

Posted

Hi @Robin S - that doesn't seem right to me. Can you reproduce on other sites? If so, does it also return true in the Console panel like in this example where I am getting false?

image.thumb.png.fbf0c6323aaa30556051703d51a04fcb.png

Posted

$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?

Posted

Oh, sorry - long day :)

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

Does that help?

  • Like 1
Posted
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

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
  • Recently Browsing   0 members

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