switch_user 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,16 @@
1
1
  switch_user
2
2
  ===========
3
3
 
4
- Inspired from [hobo][0], switch_user provides a convenient way to switch current user that speeds up your development, you don't waste your time to logout, login and input login or passowrd any more.
4
+ Inspired from [hobo][0], switch_user provides a convenient way to switch current user that speeds up your development.
5
+
6
+ Use Case
7
+ --------
8
+
9
+ switch_user is very useful in such use cases
10
+
11
+ 1. switch current users in development so that you don't waste your time to logout, login and input email (login) or password any more.
12
+
13
+ 2. reproduce the user specified error in production. Sometimes the error is only raised for specified user, which is difficult to reproduce for developers, switch_user can help you reproduce it by login as that user.
5
14
 
6
15
  Example
7
16
  -------
@@ -24,18 +33,23 @@ erb
24
33
 
25
34
  <%= switch_user_select %>
26
35
 
27
- haml
36
+ or haml
28
37
 
29
38
  = switch_user_select
39
+
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
+
42
+ <%= link_to user.login, "/switch_user?scope_id=user_#{user.id}" %>
43
+ <%= link_to admin.login, "/switch_user?scope_id=admin_#{admin.id}" %>
44
+
45
+ = link_to user.login, "/switch_user?scope_id=user_#{user.id}"
46
+ = link_to admin.login, "/switch_user?scope_id=admin_#{admin.id}"
30
47
 
31
48
  Configuration
32
49
  -------------
33
50
 
34
- By default, you can switch between Guest and all users in users table.
35
-
36
- But if you want to use different scope users in devise or you want to customize the users that can be switched, The following is the default configuration.
51
+ 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.
37
52
 
38
- # config/initializers/switch_user.rb
39
53
  SwitchUser.setup do |config|
40
54
  # provider may be :devise or :authologic
41
55
  config.provider = :devise
@@ -51,11 +65,13 @@ But if you want to use different scope users in devise or you want to customize
51
65
  # controller_guard is a block,
52
66
  # if it returns true, the request will continue,
53
67
  # else the request will be refused and returns "Permission Denied"
68
+ # if you switch from "admin" to user, the current_user param is "admin"
54
69
  config.controller_guard = lambda { |current_user, request| Rails_env == "development" }
55
70
 
56
71
  # view_guard is a block,
57
72
  # if it returns true, the switch user select box will be shown,
58
73
  # else the select box will not be shown
74
+ # if you switch from admin to "user", the current_user param is "user"
59
75
  config.view_guard == lambda { |current_user, request| Rails.env == "development" }
60
76
 
61
77
  # redirect_path is a block, it returns which page will be redirected
@@ -63,6 +79,28 @@ But if you want to use different scope users in devise or you want to customize
63
79
  config.redirect_path = lambda { |request, params| '/' }
64
80
  end
65
81
 
82
+ If the default configuration can't meet your requirement, you can define your customized configuration in <code>config/initializaers/switch_user.rb</code>
83
+
84
+ If you want to switch both available users and available admins
85
+
86
+ config.available_users = { :user => lambda { User.available }, :admin => lambda { Admin.available } }
87
+
88
+ If you want to display the login field in switch user select box
89
+
90
+ config.display_field = :login
91
+
92
+ If you only allow switching from admin to user in production environment
93
+
94
+ config.controller_guard = lambda { |current_user, request| Rails.env == "production" and current_user.admin? }
95
+
96
+ If you only want to display switch user select box for admins in production environment
97
+
98
+ config.view_guard = lambda { |current_user, request| Rails.env == "production" and current_user and current_user.admin? }
99
+
100
+ If you want to redirect user to "/dashboard" page
101
+
102
+ config.redirect_path = lambda { |request, params| "/dashboard" }
103
+
66
104
 
67
105
  Copyright © 2010 Richard Huang (flyerhzm@gmail.com), released under the MIT license
68
106
 
data/lib/switch_user.rb CHANGED
@@ -19,7 +19,7 @@ module SwitchUser
19
19
  mattr_accessor :controller_guard
20
20
  self.controller_guard = lambda { Rails.env == "development" }
21
21
  mattr_accessor :view_guard
22
- self.view_guard = lambda { Rails.evn == "development" }
22
+ self.view_guard = lambda { Rails.env == "development" }
23
23
 
24
24
  mattr_accessor :redirect_path
25
25
  self.redirect_path = lambda { |request| request.env["HTTP_REFERER"] ? :back : root_path }
@@ -1,3 +1,3 @@
1
1
  module SwitchUser
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switch_user
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Huang