← Back to Upcase

Allow admin to impersonate all other users

(David Lee) #1

Hi everyone!

I’m working on a function that allows any admin to mimic or impersonate other users. In other words, I want the admin to be able to freely access any user’s personal dashboard. I came across a gem by Engine Yard called User_Impersonate (https://github.com/engineyard/user_impersonate). It looks promising, but is fairly new so I was interested in other alternatives to accomplish this.

I’m also using Devise. As an alternative to the above gem, could I just reconfig the Devise route so that the edit user page is no longer user/edit but something like users/:user_id/edit. If you had to implement something similar, how did you handle it? Thanks!

(Chad Pytel) #2

Hi @realDLee, if I was using Devise and wanted to do that functionality I would definitely look at using the user_impersonate gem, it’s 11 months old and looks like it’s actively maintained, so I wouldn’t consider it that new.

If you really only want admin’s to be able to edit users, and do other admin functionality, not actually impersonate users and see what they see on the site, then I think you should consider implementing an actual admin interface. Either by hand or using something like https://github.com/sferik/rails_admin

Let me know what you think, if you have any follow up questions, and also what you end up doing!


(Justin Gordon) #3

Here’s another gem that does impersonation: https://github.com/ankane/pretender

Anybody try it?

(Justin Gordon) #4

Here’s the gem that @cpytel is referring to: https://github.com/rcook/user_impersonate2.

It ROCKS! super easy to install, and gets the job done.

(Dan Weaver) #5

Thanks for the recommendation @cpytel and @Justin_Gordon!

I was about to implement this type of feature for my admin users with the method outlined in the Devise wiki here: https://github.com/plataformatec/devise/wiki/How-To:-Sign-in-as-another-user-if-you-are-an-admin

This is a really simple version and once an admin has become another user they would be required to sign out and sign back in again as admin to regain control.

The gem mentioned above looks much better and will give my admin users a much slicker experience.

(Dan Croak) #6

It looks like there are a number of workable solutions already mentioned on the thread but I’ll throw one more out that is more manual, in tutorial form: How To Masquerade As Another User To See How They Use Your App

(Flávio M Oota) #7

This is awesome! I’ve been always hacking to impersonate some users and never occured to me to search for a solution like this. The gem user_impersonate2 worked like a charm with devise.

There’s just one issue with me, I have 2 different user models: candidate and recruiter. Wondering if/how I could use this gem for those 2 models. Because from what I saw, it’s only possible to use for one user model.