Git Product home page Git Product logo

rails_admin_become_user's Introduction

Rails Admin Become User

Rails Admin plugin to become a Devise user in the main application

Gem Version Code Climate

Overview

It can be very useful to see from a user's perspective when troubleshooting user isues.

This plugin adds a custom action to the Rails Admin dashboard to sign in as a user from your application without having to know their password.

This plugin only works for model classes that use Devise.

Installation

To enable rails_admin_become_user, add the following to your Gemfile:

gem 'rails_admin'
gem 'rails_admin_become_user'

rails_admin_become_user must be defined after rails_admin to work correctly.

Add in your config/initializers/rails_admin.rb initializer the configuration:

RailsAdmin.config do |config|
  config.actions do
    dashboard
    index
    new
    export
    history_index
    bulk_delete
    show
    edit
    delete
    history_show
    show_in_app
    become_user   # Add the clone action
  end
end

Routes

Important: The routes used Devise to redirect after sign in and the routes used by Rails Admin are not in the same namespace. To prevent routing errors, prepend main_app to all routes in ApplicationController.after_sign_in_path_for and add the router_name: :main_app to the devise_for route definition.

For example:

class ApplicationController < ActionController::Base
  def after_sign_in_path_for(resource)
    stored_location_for(resource) || main_app.dashboard_path 
  end
MyApp::Application.routes.draw do
  devise_for :users, :router_name => :main_app
end

Authorization

If you are using CanCan for authorization, there will be an authorization check for action :become_user on the target model. Make sure you authorize it for the users of the Rails Admin dashboard.

For example:

class Ability
  include CanCan::Ability

  def initialize(user)
    if user.administrator?
      can :become_user, User
	end
  end
end

Options

By default, the plugin is enabled on all models that use Devise. You can restrict which models will be included by using only or except.

RailsAdmin.config do |config|
  config.actions do
    # ...
    become_user do
	  only 'User'
      # or
	  only ['User', 'Moderator']
      # or
	  except 'Admin'
	end
  end
end

Contributing

Submitting a Pull Request:

  1. Fork the repository.
  2. Create a topic branch.
  3. Implement your feature or bug fix.
  4. Add, commit, and push your changes.
  5. Submit a pull request.

License

This project rocks and uses MIT-LICENSE.

Copyright 2014 Julien Vanier

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

rails_admin_become_user's People

Contributors

monkbroc avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

ivanzotov

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.