I installed the Organic Group module and suddenly masquerade module is not working !
The swithc back function is not working and the button is not showing up.
The switching to other users actually work, but u cant get back.

As i disabled all the OG modules, it worked again.
If og modules are installed (og module access control on or off, doesnt count) then masq. doesnt work.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mj2308’s picture

I have the same problem as well ... =(

smilodon’s picture

I gave up with OG, fortunately it was not so critical on my site. Very many problems solved, less errors with every other module.

ec’s picture

I also have the same problem here with drupal 4.7.0 and latest og release ! regards, eric.

starbow’s picture

Hmm, seems like $user->masquerade is getting unset somewhere.
It's a nasty hack, but you can work around this by changing the line:

$items[] = array('path' => 'masquerade/unswitch',
'title' => t('switch back'),
'callback' => 'masquerade_switch_back',
'access' => $user->masquerading,
'type' => MENU_NORMAL_ITEM);

to:

$masquerading = db_result(db_query("SELECT uid_from FROM {masquerade} WHERE sid = '%s'\
AND uid_as = %d", session_id(), $user->uid));
$items[] = array('path' => 'masquerade/unswitch',
'title' => t('switch back'),
'callback' => 'masquerade_switch_back',
'access' => $masquerading,
'type' => MENU_NORMAL_ITEM);

yngens’s picture

Hi,

I also have this problem. Tried given replacement of the code, but unfortunately it did not help, I still can not change back to admin. Any progress on this issue?

cooperaj’s picture

I am encountering the same issue.

and the above code does not fix.

Regards
Adam

cooperaj’s picture

Found that the menu cache was not being cleared for the new user when switching. Meaning that although starbows fix was working the menu displayed was a cached version, hence no switch back option. To fix

Add:

  cache_clear_all("menu:".$user->uid.":", true);

Just above:

  drupal_goto();

In:

  function masquerade_switch_user($uid)

Making:

  $user->masquerading = $new_user->uid;
  $user = $new_user;  
  cache_clear_all("menu:".$user->uid.":", true);
  drupal_goto();
}
ec’s picture

Hy, I tried both fix but still fall on the same issue ! Any idea ? regards, eric.

jhm’s picture

it doesn't work with OG because that module calls the user_load function and thus overrides the state of masquerading the masquerade module is trying to track in the global $user structure.

I am looking into a patch for the masquerade module, so it will not use a global structure that could be overritten to track its state.

see: http://drupal.org/node/71907

jhm’s picture

I created a new global variable called masquerading and set its value to null. In the init hook of masquerade I track the masqueraded uid in this global variable.

This being a quick hack, I did not bother removing/changing the current global $user references.

This is what the new masquerade_init looks like:

function masquerade_init() {
  global $user;
  // load from table uid + session id
  $uid = db_result(db_query("SELECT uid_from FROM {masquerade} WHERE sid = '%s' AND uid_as = %d", session_id(), $user->uid));
  // using if so that we get unset rather than false if not masqing
  if ($uid) {
    $GLOBALS['masquerading'] = $user->masquerading = $uid;
  }else{
    $GLOBALS['masquerading'] = null;
  }
}

Now we just need to modify the menu hook to retrieve the global value:

function masquerade_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    global $user;
    if(! is_null($GLOBALS['masquerading'])) $user->masquerading = $GLOBALS['masquerading'];
    $items[] = array('path' => 'masquerade/switch', 
      'title' => t('switch user'),
      'callback' => 'masquerade_switch_user',
      'access' => !$user->masquerading && (user_access('masquerade as user') || user_access('masquerade as admin')),
      'type' => MENU_CALLBACK);

    $items[] = array('path' => 'masquerade/unswitch', 
      'title' => t('switch back'),
      'callback' => 'masquerade_switch_back',
      'access' => $user->masquerading,
      'type' => MENU_NORMAL_ITEM);
  }

  return $items;
}

that works on my 4.7.2 drupal installation with the latest og module.

merlinofchaos’s picture

Can you submit this in patch form?

jhm’s picture

FileSize
978 bytes

here is a patch file

Steve Dondley’s picture

I tried the patch but it doesn't to seem to have any affect at all.

Steve Dondley’s picture

FileSize
1.25 KB

OK, here's a different version of jhm's patch. The switch back link now shows for me. I did away with using $user->masquerade and just used the $GLOBALS['masquerade'] variable. Maybe this isn't the best way but it works.

Steve Dondley’s picture

FileSize
1.25 KB

Hmm...somehow some tabs snuck into the patch. Here's a version of the same patch with them removed.

Steve Dondley’s picture

Status: Active » Needs review

Set to review.

Steve Dondley’s picture

Status: Needs review » Fixed

Patch applied, committed to head and drupal-4-7 branch

Anonymous’s picture

Status: Fixed » Closed (fixed)

  • Commit 2969814 on 4.7.x-1.x, 5.x-1.x, 6.x-1.x, master, 8.x-2.x, 8.x-2.x-admin-menu, 8.x-1.x-1836516 by Steve Dondley:
    patch #62278 by Steve Dondley: made compatible with org. groups module
    
    

  • Commit 2969814 on 4.7.x-1.x, 5.x-1.x, 6.x-1.x, master, 8.x-2.x, 8.x-2.x-admin-menu, 8.x-1.x-1836516 by Steve Dondley:
    patch #62278 by Steve Dondley: made compatible with org. groups module