switch_user 0.6.0 → 0.7.0
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 +21 -21
- data/app/controllers/switch_user_controller.rb +20 -1
- data/lib/switch_user/version.rb +1 -1
- data/lib/switch_user.rb +1 -1
- metadata +27 -55
data/README.md
CHANGED
@@ -36,12 +36,12 @@ erb
|
|
36
36
|
or haml
|
37
37
|
|
38
38
|
= switch_user_select
|
39
|
-
|
39
|
+
|
40
40
|
If there are too many users (in production), the switch_user_select is not a good choice, you should call the switch user request by yourself.
|
41
41
|
|
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
45
|
= link_to user.login, "/switch_user?scope_identifier=user_#{user.id}"
|
46
46
|
= link_to admin.login, "/switch_user?scope_identifier=admin_#{admin.id}"
|
47
47
|
|
@@ -56,11 +56,11 @@ Configuration
|
|
56
56
|
By default, you can switch between Guest and all users in users table, you don't need to do anything. The following is the default configuration.
|
57
57
|
|
58
58
|
SwitchUser.setup do |config|
|
59
|
-
# provider may be :devise or :
|
59
|
+
# provider may be :devise, :authlogic or :restful_authentication
|
60
60
|
config.provider = :devise
|
61
61
|
|
62
|
-
# available_users is a hash,
|
63
|
-
# key is the model name of user (:user, :admin, or any name you use),
|
62
|
+
# available_users is a hash,
|
63
|
+
# key is the model name of user (:user, :admin, or any name you use),
|
64
64
|
# value is a block that return the users that can be switched.
|
65
65
|
config.available_users = { :user => lambda { User.all } }
|
66
66
|
|
@@ -72,29 +72,29 @@ By default, you can switch between Guest and all users in users table, you don't
|
|
72
72
|
# expose for instance a username on a User model instead of id
|
73
73
|
config.available_users_identifiers = { :user => :id }
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
# available_users_names is a hash,
|
76
|
+
# keys in this hash should match a key in the available_users hash
|
77
|
+
# value is the column name which will be displayed in select box
|
78
78
|
config.available_users_names = { :user => :email }
|
79
79
|
|
80
|
-
# controller_guard is a block,
|
81
|
-
# if it returns true, the request will continue,
|
80
|
+
# controller_guard is a block,
|
81
|
+
# if it returns true, the request will continue,
|
82
82
|
# else the request will be refused and returns "Permission Denied"
|
83
83
|
# if you switch from "admin" to user, the current_user param is "admin"
|
84
84
|
config.controller_guard = lambda { |current_user, request| Rails.env.development? }
|
85
85
|
|
86
|
-
# view_guard is a block,
|
87
|
-
# if it returns true, the switch user select box will be shown,
|
86
|
+
# view_guard is a block,
|
87
|
+
# if it returns true, the switch user select box will be shown,
|
88
88
|
# else the select box will not be shown
|
89
89
|
# if you switch from admin to "user", the current_user param is "user"
|
90
|
-
config.view_guard
|
90
|
+
config.view_guard = lambda { |current_user, request| Rails.env.development? }
|
91
91
|
|
92
|
-
# redirect_path is a block, it returns which page will be redirected
|
92
|
+
# redirect_path is a block, it returns which page will be redirected
|
93
93
|
# after switching a user.
|
94
94
|
config.redirect_path = lambda { |request, params| '/' }
|
95
95
|
end
|
96
96
|
|
97
|
-
If the default configuration can't meet your requirement, you can define your customized configuration in <code>config/
|
97
|
+
If the default configuration can't meet your requirement, you can define your customized configuration in <code>config/initializers/switch_user.rb</code>
|
98
98
|
|
99
99
|
If you want to switch both available users and available admins
|
100
100
|
|
@@ -102,24 +102,24 @@ If you want to switch both available users and available admins
|
|
102
102
|
|
103
103
|
If you want to use name column as the user identifier
|
104
104
|
|
105
|
-
|
106
|
-
|
105
|
+
config.available_users_identifiers => { :user => :name }
|
106
|
+
|
107
107
|
If you want to display the login field in switch user select box
|
108
108
|
|
109
109
|
config.available_users_names = { :user => :login }
|
110
|
-
|
110
|
+
|
111
111
|
If you only allow switching from admin to user in production environment
|
112
112
|
|
113
113
|
config.controller_guard = lambda { |current_user, request| Rails.env == "production" and current_user.admin? }
|
114
|
-
|
114
|
+
|
115
115
|
If you only want to display switch user select box for admins in production environment
|
116
116
|
|
117
117
|
config.view_guard = lambda { |current_user, request| Rails.env == "production" and current_user and current_user.admin? }
|
118
|
-
|
118
|
+
|
119
119
|
If you want to redirect user to "/dashboard" page
|
120
120
|
|
121
121
|
config.redirect_path = lambda { |request, params| "/dashboard" }
|
122
|
-
|
122
|
+
|
123
123
|
|
124
124
|
Copyright © 2010 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
125
125
|
|
@@ -56,7 +56,22 @@ class SwitchUserController < ApplicationController
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
|
+
def restful_authentication_handle(params)
|
61
|
+
if params[:scope_identifier].blank?
|
62
|
+
logout_killing_session!
|
63
|
+
else
|
64
|
+
params[:scope_identifier] =~ /^([^_]+)_(.*)$/
|
65
|
+
scope, identifier = $1, $2
|
66
|
+
|
67
|
+
SwitchUser.available_users.keys.each do |s|
|
68
|
+
if scope == s.to_s && user = find_user(scope, s, identifier)
|
69
|
+
self.current_user = user
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
60
75
|
def find_user(scope, identifier_scope, identifier)
|
61
76
|
identifier_column = SwitchUser.available_users_identifiers[identifier_scope] || :id
|
62
77
|
if identifier_column == :id
|
@@ -73,4 +88,8 @@ class SwitchUserController < ApplicationController
|
|
73
88
|
def authlogic_current_user
|
74
89
|
UserSession.find.try(:record)
|
75
90
|
end
|
91
|
+
|
92
|
+
def restful_authentication_current_user
|
93
|
+
current_user
|
94
|
+
end
|
76
95
|
end
|
data/lib/switch_user/version.rb
CHANGED
data/lib/switch_user.rb
CHANGED
metadata
CHANGED
@@ -1,49 +1,34 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: switch_user
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
- 0
|
10
|
-
version: 0.6.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Richard Huang
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-03-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: bundler
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70197516282760 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 23
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 0
|
33
|
-
- 0
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
34
21
|
version: 1.0.0
|
35
22
|
type: :development
|
36
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70197516282760
|
37
25
|
description: Easily switch current user to speed up development
|
38
|
-
email:
|
26
|
+
email:
|
39
27
|
- flyerhzm@gmail.com
|
40
28
|
executables: []
|
41
|
-
|
42
29
|
extensions: []
|
43
|
-
|
44
30
|
extra_rdoc_files: []
|
45
|
-
|
46
|
-
files:
|
31
|
+
files:
|
47
32
|
- .gitignore
|
48
33
|
- Gemfile
|
49
34
|
- Gemfile.lock
|
@@ -57,41 +42,28 @@ files:
|
|
57
42
|
- lib/switch_user/version.rb
|
58
43
|
- rails/init.rb
|
59
44
|
- switch_user.gemspec
|
60
|
-
has_rdoc: true
|
61
45
|
homepage: http://rubygems.org/gems/switch_user
|
62
46
|
licenses: []
|
63
|
-
|
64
47
|
post_install_message:
|
65
48
|
rdoc_options: []
|
66
|
-
|
67
|
-
require_paths:
|
49
|
+
require_paths:
|
68
50
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
52
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
|
76
|
-
- 0
|
77
|
-
version: "0"
|
78
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
58
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
hash: 23
|
84
|
-
segments:
|
85
|
-
- 1
|
86
|
-
- 3
|
87
|
-
- 6
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
88
62
|
version: 1.3.6
|
89
63
|
requirements: []
|
90
|
-
|
91
64
|
rubyforge_project: switch_user
|
92
|
-
rubygems_version: 1.
|
65
|
+
rubygems_version: 1.8.17
|
93
66
|
signing_key:
|
94
67
|
specification_version: 3
|
95
68
|
summary: Easily switch current user to speed up development
|
96
69
|
test_files: []
|
97
|
-
|