Posted by smilodon on May 7, 2006 at 10:48am
9 followers
| Project: | Masquerade |
| Version: | 4.7.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
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.
Comments
#1
I have the same problem as well ... =(
#2
I gave up with OG, fortunately it was not so critical on my site. Very many problems solved, less errors with every other module.
#3
I also have the same problem here with drupal 4.7.0 and latest og release ! regards, eric.
#4
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);
#5
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?
#6
I am encountering the same issue.
and the above code does not fix.
Regards
Adam
#7
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:
<?php
cache_clear_all("menu:".$user->uid.":", true);
?>
Just above:
<?phpdrupal_goto();
?>
In:
<?phpfunction masquerade_switch_user($uid)
?>
Making:
<?php$user->masquerading = $new_user->uid;
$user = $new_user;
cache_clear_all("menu:".$user->uid.":", true);
drupal_goto();
}
?>
#8
Hy, I tried both fix but still fall on the same issue ! Any idea ? regards, eric.
#9
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
#10
I created a new global variable called masquerading and set its value to
null. In theinithook 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:
<?phpfunction 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
menuhook to retrieve the global value:<?php
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.
#11
Can you submit this in patch form?
#12
here is a patch file
#13
I tried the patch but it doesn't to seem to have any affect at all.
#14
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.
#15
Hmm...somehow some tabs snuck into the patch. Here's a version of the same patch with them removed.
#16
Set to review.
#17
Patch applied, committed to head and drupal-4-7 branch
#18