Giter Club home page Giter Club logo

Comments (8)

lcowell avatar lcowell commented on July 18, 2024

Internally, I use session[:original_user] to store the original user. Checking to see if that exists will tell you if you've switched from another user.

FYI This is definitely going to change because I definitely shouldn't be storing the whole user object in the session.

HTH

from switch_user.

firedev avatar firedev commented on July 18, 2024

Hi, you mean you're storing the whole user object? I think it would be ok to store just the ID.

from switch_user.

firedev avatar firedev commented on July 18, 2024

Just checked it, session[:original_user] is always nil

from switch_user.

lcowell avatar lcowell commented on July 18, 2024

Examine the entire session variable if you can. It may be under session[:original_user_scope_identifier] at this point in time.

from switch_user.

firedev avatar firedev commented on July 18, 2024

Added session[:original_user_scope_identifier].inspect to application layout. It's always nil as well.

from switch_user.

lcowell avatar lcowell commented on July 18, 2024

Hmmmm are you using the switch_back feature ? You can read about it in the read me.

from switch_user.

firedev avatar firedev commented on July 18, 2024

Hmm I think yes, here is an excerpt from my initializers/switch_user.rb:

  config.switch_back = true
  config.controller_guard = ->(current_user, request, original_user) do
    current_user && current_user.can_supervise? || original_user && original_user.can_supervise?
  end

from switch_user.

osuthorpe avatar osuthorpe commented on July 18, 2024

try this in your switch_user.rb

SwitchUser.setup do |config|
  config.switch_back = true
  config.controller_guard = lambda { |current_user, request, original_user|
      current_user && (current_user.has_role? :admin) || original_user && (original_user.has_role? :admin)
    }
end

and then something like this in your view

<%if current_user.present? %>
    <% if (current_user.has_role? :admin) or (session[:original_user_scope_identifier].present?) %>
        <%= switch_user_select %>
    <% end %>
<% end %>

from switch_user.

Related Issues (20)

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.