Perhaps this would require significant functionality to accomplish in a secure manner, but I'm in a situation where I'd like certain users to be able to see a list of "active" users on the site, and temporarily become them. I don't like the masquerade block because there's too high a chance they'll mistype the username.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wjaspers’s picture

Here you go.
I created a custom filter for views so you can generate a link directly from the user ID.
I don't know how secure generating links might be, but I went on as much code as made sense to me in the masquerade module itself.

This functionality also includes an access check before the link is generated to ensure the user is permitted to masquerade as another user (does not check if permitted to masquerade as admin). This also includes the option to specify a custom redirect URL--In my case, I wanted customer service people to be able to immediately jump from a view of open "carts" to a specific user's cart. The only caveat of this, is that Masquerade will forget where you left off.

Any further improvements or suggestions would be appreciated.

wjaspers’s picture

Status: Active » Needs review
wjaspers’s picture

Sigh....once again, I didn't double check my filename headers closely enough.
Please review THIS patch, not the one above it.

wjaspers’s picture

Title: Add a Views field to generate a masquerade as user link » Add Views, CTools, and Context module support.
FileSize
12.11 KB

Try this one on for size.
Adds CTools Access support, and a Context module condition, as well as the views fields.

andypost’s picture

Great issue, I'd like it but it needs testing

PS: marked as duplicate #1089586: disable user search

andypost’s picture

Is there any reviews? I'm going to include some changes in next realese

Also as I see there's Context, Ctools & Views plugins. I think it's hard to review all of them once

wjaspers’s picture

I actually had a future idea for this too, where-in specific permissions could be restricted while masquerading .... (e.g. "Access Checkout" for Drupal commerce could be restricted, so customer service personnel could add something to a cart, but can't checkout for someone).

wjaspers’s picture

Dang laptop caused me to double post again.

andypost’s picture

Status: Needs review » Needs work

Mostly everything great, except minor code-style; trailing whitespace and some formatting

+++ b/masquerade.module	Thu Jan 15 03:14:12 1970
@@ -838,4 +836,67 @@
+function masquerade_views_api() {
+  return array(
+    'api' => 2,

Are you sure that version 2?

+++ b/masquerade.module	Thu Jan 15 03:14:12 1970
@@ -838,4 +836,67 @@
+  if ($owner == 'ctools') {
+    return "ctools/$plugin_type";
+  }
+  // we don't know what's being requsted
+  return '';

last 2 lines are useless

+++ a/views/masquerade_handler_field_user_link.inc	Thu Jan 15 03:14:12 1970
@@ -0,0 +1,85 @@
+    ¶

There's some trailing whitespace troubles in patch

+++ b/ctools/access/is_masquerading.inc	Thu Jan 15 03:14:12 1970
@@ -0,0 +1,39 @@
+  'default' => array(
+  ),

Please leave this on one line

wjaspers’s picture

Status: Needs work » Closed (duplicate)
vlooivlerke’s picture

Could the Views Support work if I try and patch it against a D6 views 3 version?

wjaspers’s picture

The code would likely be the same, but the patch would start at a different line, and thus won't apply.
Shouldn't be too hard to port though.
Please post new comments on #1305662: Add Views support.