switch_user 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +97 -78
- data/app/controllers/switch_user_controller.rb +9 -5
- data/app/helpers/switch_user_helper.rb +15 -20
- data/app/views/switch_user/_widget.html.erb +4 -0
- data/config/routes.rb +3 -11
- data/lib/generators/switch_user/install/templates/switch_user.rb +10 -2
- data/lib/switch_user.rb +14 -20
- data/lib/switch_user/base_guard.rb +20 -0
- data/lib/switch_user/lambda_guard.rb +22 -0
- data/lib/switch_user/provider.rb +7 -0
- data/lib/switch_user/provider/base.rb +7 -0
- data/lib/switch_user/rails.rb +5 -15
- data/lib/switch_user/version.rb +1 -1
- data/spec/provider_spec.rb +10 -0
- data/spec/support/provider.rb +4 -0
- data/spec/switch_user/lambda_guard_spec.rb +19 -0
- data/spec/switch_user_spec.rb +0 -21
- metadata +7 -3
- data/rails/init.rb +0 -1
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# switch_user
|
2
2
|
|
3
|
-
Inspired from [hobo][0], switch_user provides a convenient way to switch current user
|
3
|
+
Inspired from [hobo][0], switch_user provides a convenient way to switch current user without needing to log out and log in manually.
|
4
4
|
|
5
5
|
## Use Case
|
6
6
|
|
@@ -19,9 +19,9 @@ And source code here: <https://github.com/flyerhzm/switch_user_example>
|
|
19
19
|
## Install
|
20
20
|
|
21
21
|
Add in Gemfile.
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
```ruby
|
23
|
+
gem "switch_user"
|
24
|
+
```
|
25
25
|
## Usage
|
26
26
|
|
27
27
|
Add following code into your layout page.
|
@@ -42,90 +42,109 @@ If there are too many users (on production), the switch_user_select is not a goo
|
|
42
42
|
= link_to user.login, "/switch_user?scope_identifier=user_#{user.id}"
|
43
43
|
= link_to admin.login, "/switch_user?scope_identifier=admin_#{admin.id}"
|
44
44
|
|
45
|
-
If you
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
# config/routes.rb
|
53
|
-
match 'switch_user' => 'switch_user#set_current_user'
|
54
|
-
# wildcard route that will match anything
|
55
|
-
match ':id' => 'pages#show'
|
56
|
-
|
45
|
+
If you have a wildcard route in your project, add a route before the wildcard route.
|
46
|
+
```ruby
|
47
|
+
# config/routes.rb
|
48
|
+
match 'switch_user' => 'switch_user#set_current_user'
|
49
|
+
# wildcard route that will match anything
|
50
|
+
match ':id' => 'pages#show'
|
51
|
+
```
|
57
52
|
## Configuration
|
58
53
|
|
59
|
-
By default, you can switch between Guest and all users in users table, you don't need to do anything. The following is the
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
If the default configuration
|
54
|
+
By default, you can switch between Guest and all users in users table, you don't need to do anything. The following is some of the more commonly used configuration options.
|
55
|
+
```ruby
|
56
|
+
SwitchUser.setup do |config|
|
57
|
+
# provider may be :devise, :authlogic, :clearance, :restful_authentication or :sorcery
|
58
|
+
config.provider = :devise
|
59
|
+
|
60
|
+
# available_users is a hash,
|
61
|
+
# key is the model name of user (:user, :admin, or any name you use),
|
62
|
+
# value is a block that return the users that can be switched.
|
63
|
+
config.available_users = { :user => lambda { User.all } }
|
64
|
+
|
65
|
+
# available_users_identifiers is a hash,
|
66
|
+
# keys in this hash should match a key in the available_users hash
|
67
|
+
# value is the name of the identifying column to find by,
|
68
|
+
# defaults to id
|
69
|
+
# this hash is to allow you to specify a different column to
|
70
|
+
# expose for instance a username on a User model instead of id
|
71
|
+
config.available_users_identifiers = { :user => :id }
|
72
|
+
|
73
|
+
# available_users_names is a hash,
|
74
|
+
# keys in this hash should match a key in the available_users hash
|
75
|
+
# value is the column name which will be displayed in select box
|
76
|
+
config.available_users_names = { :user => :email }
|
77
|
+
|
78
|
+
# controller_guard is a block,
|
79
|
+
# if it returns true, the request will continue,
|
80
|
+
# else the request will be refused and returns "Permission Denied"
|
81
|
+
# if you switch from "admin" to user, the current_user param is "admin"
|
82
|
+
config.controller_guard = lambda { |current_user, request| Rails.env.development? }
|
83
|
+
|
84
|
+
# view_guard is a block,
|
85
|
+
# if it returns true, the switch user select box will be shown,
|
86
|
+
# else the select box will not be shown
|
87
|
+
# if you switch from admin to "user", the current_user param is "user"
|
88
|
+
config.view_guard = lambda { |current_user, request| Rails.env.development? }
|
89
|
+
|
90
|
+
# redirect_path is a block, it returns which page will be redirected
|
91
|
+
# after switching a user.
|
92
|
+
config.redirect_path = lambda { |request, params| '/' }
|
93
|
+
end
|
94
|
+
```
|
95
|
+
If you need to override the default configuration, run <code>rails g switch_user:install</code> and a copy of the configuration file will be copied to <code>config/initializers/switch_user.rb</code> in your project.
|
101
96
|
|
102
97
|
If you want to switch both available users and available admins
|
103
|
-
|
104
|
-
|
105
|
-
|
98
|
+
```ruby
|
99
|
+
config.available_users = { :user => lambda { User.available }, :admin => lambda { Admin.available } }
|
100
|
+
```
|
106
101
|
If you want to use name column as the user identifier
|
107
|
-
|
108
|
-
|
109
|
-
|
102
|
+
```ruby
|
103
|
+
config.available_users_identifiers => { :user => :name }
|
104
|
+
```
|
110
105
|
If you want to display the login field in switch user select box
|
111
|
-
|
112
|
-
|
113
|
-
|
106
|
+
```ruby
|
107
|
+
config.available_users_names = { :user => :login }
|
108
|
+
```
|
114
109
|
If you only allow switching from admin to user in production environment
|
115
|
-
|
116
|
-
|
117
|
-
|
110
|
+
```ruby
|
111
|
+
config.controller_guard = lambda { |current_user, request| Rails.env == "production" and current_user.admin? }
|
112
|
+
```
|
118
113
|
If you only want to display switch user select box for admins in production environment
|
119
|
-
|
120
|
-
|
121
|
-
|
114
|
+
```ruby
|
115
|
+
config.view_guard = lambda { |current_user, request| Rails.env == "production" and current_user and current_user.admin? }
|
116
|
+
```
|
122
117
|
If you want to redirect user to "/dashboard" page
|
123
|
-
|
124
|
-
|
125
|
-
|
118
|
+
```ruby
|
119
|
+
config.redirect_path = lambda { |request, params| "/dashboard" }
|
120
|
+
```
|
126
121
|
If you want to hide a 'Guest' item in the helper dropdown list
|
127
|
-
|
128
|
-
|
122
|
+
```ruby
|
123
|
+
config.helper_with_guest = false
|
124
|
+
```
|
125
|
+
## Switch Back
|
126
|
+
Sometimes you'll want to be able to switch to an unprivileged user and then back again. This can be especially useful in production when trying to reproduce a problem a user is having. The problem is that once you switch to that unprivileged user, you don't have a way to safely switch_back without knowing who the original user was. That's what this feature is for.
|
127
|
+
|
128
|
+
You will need to make the following modifications to your configuration:
|
129
|
+
```ruby
|
130
|
+
config.switch_user = true
|
131
|
+
config.controller_guard = lambda { |current_user, request, original_user|
|
132
|
+
current_user && current_user.admin? || original_user && original_user.super_admin?
|
133
|
+
}
|
134
|
+
# Do something similar for the view_guard as well.
|
135
|
+
```
|
136
|
+
This example would allow an admin user to user switch_user, but would only let you switch back to another user if the original user was a super admin.
|
137
|
+
|
138
|
+
### How it works
|
139
|
+
|
140
|
+
Click the checkbox next to switch_user_select menu to remember that user for this session. Once this
|
141
|
+
has been checked, that user is passed in as the 3rd option to the view and controller guards.
|
142
|
+
This allows you to check against current_user as well as that original_user to see if the
|
143
|
+
switch_user action should be allowed.
|
144
|
+
|
145
|
+
### Warning
|
146
|
+
|
147
|
+
This feature should be used with extreme caution because of the security implications. This is especially true in a production environment.
|
129
148
|
|
130
149
|
## Credit
|
131
150
|
|
@@ -23,9 +23,7 @@ class SwitchUserController < ApplicationController
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def available?
|
26
|
-
SwitchUser.
|
27
|
-
request,
|
28
|
-
provider.original_user)
|
26
|
+
SwitchUser.guard_class.new(self, provider).controller_available?
|
29
27
|
end
|
30
28
|
|
31
29
|
def handle_request(params)
|
@@ -33,11 +31,17 @@ class SwitchUserController < ApplicationController
|
|
33
31
|
provider.logout_all
|
34
32
|
else
|
35
33
|
loader = SwitchUser::UserLoader.prepare(params)
|
36
|
-
|
34
|
+
if SwitchUser.login_exclusive
|
35
|
+
provider.login_exclusive(loader.user, :scope => loader.scope)
|
36
|
+
else
|
37
|
+
provider.login_inclusive(loader.user, :scope => loader.scope)
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
42
|
+
# TODO make helper methods, so this can be eliminated from the
|
43
|
+
# SwitchUserHelper
|
40
44
|
def provider
|
41
|
-
SwitchUser.
|
45
|
+
SwitchUser::Provider.init(self)
|
42
46
|
end
|
43
47
|
end
|
@@ -1,33 +1,29 @@
|
|
1
1
|
module SwitchUserHelper
|
2
|
+
class SelectOption < Struct.new(:label, :scope_id); end
|
2
3
|
def switch_user_select
|
3
|
-
# TODO this should be moved in to a view file
|
4
4
|
return unless available?
|
5
|
-
options =
|
5
|
+
options = []
|
6
|
+
selected_user = nil
|
6
7
|
|
7
|
-
options
|
8
|
+
options << SelectOption.new("Guest", "") if SwitchUser.helper_with_guest
|
8
9
|
SwitchUser.available_users.each do |scope, user_proc|
|
9
|
-
|
10
10
|
current_user = provider.current_user(scope)
|
11
11
|
id_name = SwitchUser.available_users_identifiers[scope]
|
12
12
|
name = SwitchUser.available_users_names[scope]
|
13
13
|
|
14
14
|
user_proc.call.each do |user|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
:selected => user_match)
|
15
|
+
if user == current_user
|
16
|
+
selected_user = tag_value(user, id_name, scope)
|
17
|
+
end
|
18
|
+
options << SelectOption.new(tag_label(user, name), tag_value(user, id_name, scope))
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
select_tag "switch_user_identifier", options,
|
30
|
-
:onchange => "location.href = '/switch_user?scope_identifier=' + encodeURIComponent(this.options[this.selectedIndex].value)"
|
22
|
+
render :partial => "switch_user/widget",
|
23
|
+
:locals => {
|
24
|
+
:options => options,
|
25
|
+
:current_scope => selected_user
|
26
|
+
}
|
31
27
|
end
|
32
28
|
|
33
29
|
private
|
@@ -43,11 +39,10 @@ module SwitchUserHelper
|
|
43
39
|
end
|
44
40
|
|
45
41
|
def available?
|
46
|
-
|
47
|
-
SwitchUser.view_guard(user, request)
|
42
|
+
SwitchUser.guard_class.new(controller, provider).view_available?
|
48
43
|
end
|
49
44
|
|
50
45
|
def provider
|
51
|
-
SwitchUser.
|
46
|
+
SwitchUser::Provider.init(controller)
|
52
47
|
end
|
53
48
|
end
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<% if SwitchUser.switch_back %>
|
2
|
+
<%= check_box_tag "remember_user", "remember_user", provider.original_user.present?, :onchange => "location.href = 'switch_user/remember_user?remember=' + encodeURIComponent(this.checked)" %>
|
3
|
+
<% end %>
|
4
|
+
<%= select_tag "switch_user_identifier", options_from_collection_for_select(options, :scope_id, :label, current_scope), :onchange => "location.href = '/switch_user?scope_identifier=' + encodeURIComponent(this.options[this.selectedIndex].value)" %>
|
data/config/routes.rb
CHANGED
@@ -1,12 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
match 'switch_user' => 'switch_user#set_current_user'
|
5
|
-
match 'switch_user/remember_user' => 'switch_user#remember_user'
|
6
|
-
end
|
7
|
-
elsif Rails.version =~ /^4/
|
8
|
-
Rails.application.routes.draw do
|
9
|
-
get :switch_user, :to => 'switch_user#set_current_user'
|
10
|
-
get 'switch_user/remember_user', :to => 'switch_user#remember_user'
|
11
|
-
end
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
get :switch_user, :to => 'switch_user#set_current_user'
|
3
|
+
get 'switch_user/remember_user', :to => 'switch_user#remember_user'
|
12
4
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
SwitchUser.setup do |config|
|
2
|
-
# provider may be :devise, :authlogic, :clearance, :restful_authentication or :
|
2
|
+
# provider may be :devise, :authlogic, :clearance, :restful_authentication, :sorcery, or :session
|
3
3
|
config.provider = :devise
|
4
4
|
|
5
5
|
# available_users is a hash,
|
@@ -39,4 +39,12 @@ SwitchUser.setup do |config|
|
|
39
39
|
# helper_with_guest is a boolean value, if it set to false
|
40
40
|
# the guest item in the helper won't be shown
|
41
41
|
config.helper_with_guest = true
|
42
|
-
|
42
|
+
|
43
|
+
# false = login from one scope to another and you are logged in only in both scopes
|
44
|
+
# true = you are logged only into one scope at a time
|
45
|
+
config.login_exclusive = true
|
46
|
+
|
47
|
+
# switch_back allows you to switch back to a previously selected user. See
|
48
|
+
# README for more details.
|
49
|
+
config.switch_back = false
|
50
|
+
end
|
data/lib/switch_user.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
|
2
|
-
require 'switch_user/
|
3
|
-
|
1
|
+
if defined?(Rails)
|
2
|
+
require 'switch_user/rails'
|
3
|
+
end
|
4
4
|
|
5
5
|
module SwitchUser
|
6
6
|
autoload :UserLoader, "switch_user/user_loader"
|
7
|
+
autoload :Provider, "switch_user/provider"
|
8
|
+
autoload :BaseGuard, "switch_user/base_guard"
|
9
|
+
autoload :LambdaGuard, 'switch_user/lambda_guard'
|
7
10
|
|
8
11
|
class InvalidScope < Exception; end
|
9
12
|
|
@@ -15,28 +18,22 @@ module SwitchUser
|
|
15
18
|
mattr_accessor :session_key
|
16
19
|
mattr_accessor :helper_with_guest
|
17
20
|
mattr_accessor :switch_back
|
21
|
+
mattr_accessor :login_exclusive
|
22
|
+
mattr_accessor :controller_guard
|
23
|
+
mattr_accessor :view_guard
|
24
|
+
mattr_reader :guard_class
|
18
25
|
|
19
26
|
def self.setup
|
20
27
|
yield self
|
21
28
|
end
|
22
29
|
|
23
|
-
def self.provider_class
|
24
|
-
"SwitchUser::Provider::#{provider.to_s.classify}".constantize
|
25
|
-
end
|
26
|
-
|
27
30
|
def self.available_scopes
|
28
31
|
available_users.keys
|
29
32
|
end
|
30
33
|
|
31
|
-
def self.
|
32
|
-
|
34
|
+
def self.guard_class=(klass)
|
35
|
+
@@guard_class = klass.constantize
|
33
36
|
end
|
34
|
-
mattr_writer :controller_guard
|
35
|
-
|
36
|
-
def self.view_guard(*args)
|
37
|
-
call_guard(@@view_guard, args)
|
38
|
-
end
|
39
|
-
mattr_writer :view_guard
|
40
37
|
|
41
38
|
private
|
42
39
|
|
@@ -45,17 +42,14 @@ module SwitchUser
|
|
45
42
|
self.available_users = { :user => lambda { User.all } }
|
46
43
|
self.available_users_identifiers = { :user => :id }
|
47
44
|
self.available_users_names = { :user => :email }
|
45
|
+
self.guard_class = "SwitchUser::LambdaGuard"
|
48
46
|
self.controller_guard = lambda { |current_user, request| Rails.env.development? }
|
49
47
|
self.view_guard = lambda { |current_user, request| Rails.env.development? }
|
50
48
|
self.redirect_path = lambda { |request, params| request.env["HTTP_REFERER"] ? :back : root_path }
|
51
49
|
self.session_key = :user_id
|
52
50
|
self.helper_with_guest = true
|
53
51
|
self.switch_back = false
|
54
|
-
|
55
|
-
|
56
|
-
def self.call_guard(guard, args)
|
57
|
-
arity = guard.arity
|
58
|
-
guard.call(*args[0...arity])
|
52
|
+
self.login_exclusive = true
|
59
53
|
end
|
60
54
|
|
61
55
|
reset_config
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SwitchUser
|
2
|
+
class BaseGuard
|
3
|
+
# TODO is this the best arguments for the initializer ?
|
4
|
+
# TODO should @provider be set and current/original_user be added as # accessors ?
|
5
|
+
def initialize(controller, provider)
|
6
|
+
@controller = controller
|
7
|
+
@request = controller.request
|
8
|
+
@current_user = provider.current_user
|
9
|
+
@original_user = provider.original_user
|
10
|
+
end
|
11
|
+
|
12
|
+
def controller_available?
|
13
|
+
raise NotImplementedError.new("you must implement controller_available?")
|
14
|
+
end
|
15
|
+
|
16
|
+
def view_available?
|
17
|
+
controller_available?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SwitchUser
|
2
|
+
class LambdaGuard < BaseGuard
|
3
|
+
def controller_available?
|
4
|
+
call(SwitchUser.controller_guard)
|
5
|
+
end
|
6
|
+
|
7
|
+
def view_available?
|
8
|
+
call(SwitchUser.view_guard)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def args
|
14
|
+
[@current_user, @request, @original_user, @controller]
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(guard)
|
18
|
+
arity = guard.arity
|
19
|
+
guard.call(*args[0...arity])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/switch_user/provider.rb
CHANGED
@@ -8,5 +8,12 @@ module SwitchUser
|
|
8
8
|
autoload :Sorcery, "switch_user/provider/sorcery"
|
9
9
|
autoload :Dummy, "switch_user/provider/dummy"
|
10
10
|
autoload :Session, "switch_user/provider/session"
|
11
|
+
|
12
|
+
def self.init(controller)
|
13
|
+
klass_part = SwitchUser.provider.to_s.classify
|
14
|
+
klass = "SwitchUser::Provider::#{klass_part}".constantize
|
15
|
+
|
16
|
+
klass.new(controller)
|
17
|
+
end
|
11
18
|
end
|
12
19
|
end
|
@@ -16,6 +16,13 @@ module SwitchUser
|
|
16
16
|
login(user, requested_scope)
|
17
17
|
end
|
18
18
|
|
19
|
+
def login_inclusive(user, args)
|
20
|
+
requested_scope = args.fetch(:scope, :user).to_sym
|
21
|
+
|
22
|
+
logout(requested_scope)
|
23
|
+
login(user, requested_scope)
|
24
|
+
end
|
25
|
+
|
19
26
|
def logout_all
|
20
27
|
SwitchUser.available_scopes.each do |scope|
|
21
28
|
logout(scope)
|
data/lib/switch_user/rails.rb
CHANGED
@@ -1,19 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
ActionView::Base.send :include, SwitchUserHelper
|
7
|
-
end
|
1
|
+
module SwitchUser
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
initializer "switch_user.view" do
|
4
|
+
ActiveSupport.on_load(:action_view) do
|
5
|
+
include SwitchUserHelper
|
8
6
|
end
|
9
7
|
end
|
10
|
-
else
|
11
|
-
%w(controllers helpers).each do |dir|
|
12
|
-
path = File.join(File.dirname(__FILE__), '..', 'app', dir)
|
13
|
-
$LOAD_PATH << path
|
14
|
-
ActiveSupport::Dependencies.load_paths << path
|
15
|
-
ActiveSupport::Dependencies.load_once_paths.delete(path)
|
16
|
-
ActionView::Base.send :include, SwitchUserHelper
|
17
|
-
end
|
18
8
|
end
|
19
9
|
end
|
data/lib/switch_user/version.rb
CHANGED
data/spec/support/provider.rb
CHANGED
@@ -20,6 +20,10 @@ shared_examples_for "a provider" do
|
|
20
20
|
provider.should respond_to(:login_exclusive)
|
21
21
|
end
|
22
22
|
|
23
|
+
it "responds to login_exclusive" do
|
24
|
+
provider.should respond_to(:login_inclusive)
|
25
|
+
end
|
26
|
+
|
23
27
|
it "knows if there are any users logged in" do
|
24
28
|
provider.login(user)
|
25
29
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module SwitchUser
|
4
|
+
describe LambdaGuard do
|
5
|
+
describe "#controller_available?" do
|
6
|
+
it "calls the controller_guard proc" do
|
7
|
+
controller = stub.as_null_object
|
8
|
+
provider = stub.as_null_object
|
9
|
+
guard = SwitchUser::LambdaGuard.new(controller, provider)
|
10
|
+
|
11
|
+
SwitchUser.controller_guard = lambda {|a| a }
|
12
|
+
guard.should be_controller_available
|
13
|
+
|
14
|
+
SwitchUser.controller_guard = lambda {|a| !a }
|
15
|
+
guard.should_not be_controller_available
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/switch_user_spec.rb
CHANGED
@@ -14,26 +14,5 @@ describe SwitchUser do
|
|
14
14
|
SwitchUser.provider = :sorcery
|
15
15
|
SwitchUser.provider.should == :sorcery
|
16
16
|
end
|
17
|
-
it "sets the provider class" do
|
18
|
-
SwitchUser.provider = :devise
|
19
|
-
SwitchUser.provider_class.should == SwitchUser::Provider::Devise
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "guards" do
|
24
|
-
it "can have a 1 argument lambda" do
|
25
|
-
a = 0
|
26
|
-
SwitchUser.controller_guard = lambda {|p1| a = p1 }
|
27
|
-
SwitchUser.controller_guard(1,2,3)
|
28
|
-
|
29
|
-
a.should == 1
|
30
|
-
end
|
31
|
-
it "can have a 3 argument lambda" do
|
32
|
-
a = 0
|
33
|
-
SwitchUser.view_guard = lambda {|p1,p2,p3| a = p3 }
|
34
|
-
SwitchUser.view_guard(1,2,3)
|
35
|
-
|
36
|
-
a.should == 3
|
37
|
-
end
|
38
17
|
end
|
39
18
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: switch_user
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.9.
|
5
|
+
version: 0.9.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Richard Huang
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-05-
|
13
|
+
date: 2013-05-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -123,11 +123,14 @@ files:
|
|
123
123
|
- Rakefile
|
124
124
|
- app/controllers/switch_user_controller.rb
|
125
125
|
- app/helpers/switch_user_helper.rb
|
126
|
+
- app/views/switch_user/_widget.html.erb
|
126
127
|
- config/routes.rb
|
127
128
|
- lib/generators/switch_user/install/USAGE
|
128
129
|
- lib/generators/switch_user/install/install_generator.rb
|
129
130
|
- lib/generators/switch_user/install/templates/switch_user.rb
|
130
131
|
- lib/switch_user.rb
|
132
|
+
- lib/switch_user/base_guard.rb
|
133
|
+
- lib/switch_user/lambda_guard.rb
|
131
134
|
- lib/switch_user/provider.rb
|
132
135
|
- lib/switch_user/provider/authlogic.rb
|
133
136
|
- lib/switch_user/provider/base.rb
|
@@ -140,7 +143,6 @@ files:
|
|
140
143
|
- lib/switch_user/rails.rb
|
141
144
|
- lib/switch_user/user_loader.rb
|
142
145
|
- lib/switch_user/version.rb
|
143
|
-
- rails/init.rb
|
144
146
|
- spec/controllers/switch_user_controller_spec.rb
|
145
147
|
- spec/provider/authlogic_spec.rb
|
146
148
|
- spec/provider/clearance_spec.rb
|
@@ -149,9 +151,11 @@ files:
|
|
149
151
|
- spec/provider/restful_authentication_spec.rb
|
150
152
|
- spec/provider/session_spec.rb
|
151
153
|
- spec/provider/sorcery_spec.rb
|
154
|
+
- spec/provider_spec.rb
|
152
155
|
- spec/spec_helper.rb
|
153
156
|
- spec/support/application.rb
|
154
157
|
- spec/support/provider.rb
|
158
|
+
- spec/switch_user/lambda_guard_spec.rb
|
155
159
|
- spec/switch_user/user_loader_spec.rb
|
156
160
|
- spec/switch_user_spec.rb
|
157
161
|
- switch_user.gemspec
|
data/rails/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'switch_user'
|