ucb_rails_user 2.0.1 → 3.0.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.
- checksums.yaml +4 -4
- data/README.md +46 -17
- data/app/assets/javascripts/ucb_rails_user/typeahead.bundle.js +2451 -0
- data/app/assets/javascripts/ucb_rails_user/ucb_rails_user.js +55 -0
- data/app/assets/stylesheets/ucb_rails_user/components/_impersonations.sass +12 -0
- data/app/assets/stylesheets/ucb_rails_user/main.sass +1 -0
- data/app/assets/stylesheets/ucb_rails_user/typeahead_tweaks.sass +67 -0
- data/app/controllers/ucb_rails_user/concerns/controller_methods.rb +10 -6
- data/app/controllers/ucb_rails_user/concerns/impersonations_controller.rb +43 -0
- data/app/controllers/ucb_rails_user/concerns/sessions_controller.rb +0 -1
- data/app/controllers/ucb_rails_user/concerns/users_controller.rb +5 -0
- data/app/controllers/ucb_rails_user/impersonations_controller.rb +8 -0
- data/app/models/concerns/user_concerns.rb +72 -0
- data/app/models/ucb_rails_user/concerns/impersonation_concerns.rb +10 -0
- data/app/models/ucb_rails_user/impersonation.rb +9 -0
- data/app/models/ucb_rails_user/user_search.rb +22 -0
- data/app/views/ucb_rails_user/impersonations/index.html.haml +20 -0
- data/config/routes.rb +6 -0
- data/db/migrate/20190807231505_create_impersonations.rb +10 -0
- data/lib/ucb_rails_user/engine.rb +2 -0
- data/lib/ucb_rails_user/spec_helpers.rb +6 -0
- data/lib/ucb_rails_user/version.rb +1 -1
- metadata +111 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22dfe957a0a20c8e4d3d0696e8deabb8e2c1080cbb6bf20cce37dd8ec60c29c2
|
4
|
+
data.tar.gz: a63c08a5433c35ef7cb9de21b86411d660315f6300acf777ab76b3c83acef3aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da3cedb8edd90425af6d8e0bb3d700bc1aa560ff1f76072bf6809b070c383f06956bf676fdbb4a8f6d2408d5562ac053ae545e5e69e76b4480bc292af7d03323
|
7
|
+
data.tar.gz: e899dd9644a2f493233a7891ed188b500fcd5b793f46ce0c453b652b82ed6de9cb72181e913dcf7c2c08cb990ede6c7407e3e1cebbccca373a8f14b6ad0a4dee
|
data/README.md
CHANGED
@@ -8,13 +8,18 @@ A [Rails engine](http://guides.rubyonrails.org/engines.html) that provides authe
|
|
8
8
|
* controller filters that block access to resources unless user is logged in
|
9
9
|
* a default home page that reflects user's login status
|
10
10
|
* admin screens for updating and deleting user records
|
11
|
+
* ability for admins to impersonate other users
|
11
12
|
|
12
|
-
This engine also includes the [Datatables](https://datatables.net/) JQuery plug-in, which is used in the user management screens. Host apps can make use of
|
13
|
+
This engine also includes the [Datatables](https://datatables.net/) JQuery plug-in, which is used in the user management screens, and [typeahead.js](https://github.com/twitter/typeahead.js) for autocomplete. Host apps can make use of these libraries as well.
|
13
14
|
|
14
15
|
## Conversion to UCPath
|
15
16
|
|
16
17
|
Version 2.0 and greater of this gem sets a user's `employee_id` to the new UCPath employee id, rather than the legacy HCM employee id. If you need to use the older ID, use version 1.1.3 of this gem, or lower.
|
17
18
|
|
19
|
+
## Upgrading to version 3.0 from version 2.x
|
20
|
+
|
21
|
+
See [this wiki page](https://github.com/ucb-ist-eas/ucb_rails_user/wiki/Upgrading-to-version-3.0) for details.
|
22
|
+
|
18
23
|
## Prerequisites
|
19
24
|
|
20
25
|
* Ruby >= 2.3
|
@@ -33,7 +38,6 @@ But if you need to add this to an already-existing app, do the following:
|
|
33
38
|
```ruby
|
34
39
|
gem "ucb_rails_user", github: "ucb-ist-eas/ucb_rails_user"
|
35
40
|
gem "ucb_ldap", github: "ucb-ist-eas/ucb-ldap"
|
36
|
-
gem "rails_view_helpers", github: "ucb-ist-eas/rails_view_helpers", branch: "rails5"
|
37
41
|
```
|
38
42
|
|
39
43
|
then run `bundler` to install them:
|
@@ -42,17 +46,7 @@ then run `bundler` to install them:
|
|
42
46
|
bundle install
|
43
47
|
```
|
44
48
|
|
45
|
-
2.
|
46
|
-
|
47
|
-
```yml
|
48
|
-
ldap:
|
49
|
-
username: LDAP_USERNAME
|
50
|
-
password: LDAP_PASSWORD
|
51
|
-
```
|
52
|
-
|
53
|
-
Replace `LDAP_USERNAME` and `LDAP_PASSWORD` with the proper credentials - you can get these from another developer.
|
54
|
-
|
55
|
-
**IMPORTANT** Be sure to add `config/config.yml` to your `.gitignore` so that the username and password are not saved to source control.
|
49
|
+
2. Set the `RAILS_MASTER_KEY` environment variable and setup an encrypted credentials file containing (at least) the credentials needed to connect to LDAP (ask another dev to help get this setup for you).
|
56
50
|
|
57
51
|
3. Add this line to your host app's `ApplicationController:`
|
58
52
|
|
@@ -68,7 +62,7 @@ include UcbRailsUser::Concerns::ControllerMethods
|
|
68
62
|
root to: UcbRailsUser::HomeController.action(:index)
|
69
63
|
```
|
70
64
|
|
71
|
-
6. Copy the migrations for the `User`
|
65
|
+
6. Copy the migrations for the `User` and `Impersonation` models from the engine into your host app, and run them:
|
72
66
|
|
73
67
|
```
|
74
68
|
bin/rails railties:install:migrations
|
@@ -97,6 +91,8 @@ You should be able to access the following routes:
|
|
97
91
|
* `/login`: this should redirect you to the main CAS login page
|
98
92
|
* `/logout`: this should log you out of CAS and redirect you back to the host app
|
99
93
|
* `/admin/users`: this should display the user management screen, if your user account has the `superuser` flag set; otherwise, you'll see a 401 page
|
94
|
+
* `/admin/impersonations`: this is the page used to start impersonating another user (see below)
|
95
|
+
* `/admin/stop_impersonation`: this stops an active impersonation
|
100
96
|
* `/admin/users/toggle_superuser`: in dev mode, you can use this url to turn the superuser flag of your account on and off
|
101
97
|
|
102
98
|
## Routing
|
@@ -109,18 +105,49 @@ For example, if the admin screens for your app are under the `/backend` path rat
|
|
109
105
|
resources :users, controller: "ucb_rails_user/users", path: "backend/users", as: :backend_users
|
110
106
|
```
|
111
107
|
|
108
|
+
## User Impersonation
|
109
|
+
|
110
|
+
The impersonation feature allows admins to be logged in as a different user in the system. This is useful when trying to diagnose data-specific problems, as the admin can see exactly what the user sees.
|
111
|
+
|
112
|
+
### Impersonation Permissions
|
113
|
+
|
114
|
+
By default, this feature is only available to superusers, but you can change this by overriding the `User#can_impersonate?` method and implementing any logic you prefer. See "Overriding Model And Controller Behavior" to see how to override methods in the `User` class.
|
115
|
+
|
116
|
+
### Determining Who The Real User Is
|
117
|
+
|
118
|
+
In the past, this gem provided a controller and helper method called `current_user` which returned the `User` record associated with the logged-in user. With the impersonation feature in place, this behavior changes slightly.
|
119
|
+
|
120
|
+
As of version 3.0, `current_user` returns the currently logged-in user, unless that user is impersonating another user. In that case, `current_user` will return the impersonated user (referred to as the impersonation "target" in the code). Most of our existing apps rely on `current_user` to determine what should or should not be displayed, so the impersonation feature will work best for existing apps if `current_user` returns the impersonated user.
|
121
|
+
|
122
|
+
Version 3.0 also adds a new method called `logged_in_user` that always returns the actual logged-in user (whether or not that user is impersonating someone else).
|
123
|
+
|
124
|
+
For example:
|
125
|
+
|
126
|
+
Alice is an admin who has logged into the system:
|
127
|
+
* `logged_in_user` returns Alice
|
128
|
+
* `current_user` returns Alice
|
129
|
+
|
130
|
+
Alice then starts impersonating Bob:
|
131
|
+
* `logged_in_user` returns Alice
|
132
|
+
* `current_user` returns Bob
|
133
|
+
|
134
|
+
Alice stops impersonating Bob:
|
135
|
+
* `logged_in_user` returns Alice
|
136
|
+
* `current_user` returns Alice
|
137
|
+
|
112
138
|
## Controller Methods
|
113
139
|
|
114
140
|
If you followed the setup instructions above, your `ApplicationController` should be including `UcbRails::Concerns::ControllerMethods.` This provides a number of utility methods you can use in your controllers:
|
115
141
|
|
116
|
-
* `current_user`: returns the `User` instance for the currently logged-in user, or `nil` if user is not logged in
|
142
|
+
* `current_user`: returns the `User` instance for the currently logged-in user, or `nil` if user is not logged in. If the logged-in user is impersonating another user, this will return the impersonated user
|
143
|
+
* `logged_in_user`: this returns the user who logged in with their Calnet credentials, even if that user is impersonating another user
|
117
144
|
* `current_ldap_person`: returns the `UCB::LDAP::Person` instance for the currently logged-in user, or `nil` if user is not logged in
|
118
145
|
* `logged_in?`: returns true if the user is logged in
|
119
146
|
* `superuser?`: returns true if the current user has the superuser flag set to true
|
120
147
|
* `ensure_authenticated_user`: returns a 401 error if the user is not logged in
|
121
148
|
* `ensure_admin_user`: returns a 401 error if the user is not a superuser
|
122
149
|
|
123
|
-
`current_user`, `current_ldap_person`, `logged_in?` and `superuser?` are all helper methods, so you can use them in views as well as controllers.
|
150
|
+
`current_user`, `logged_in_user`, `current_ldap_person`, `logged_in?` and `superuser?` are all helper methods, so you can use them in views as well as controllers.
|
124
151
|
|
125
152
|
`ensure_authenticated_user` is set as a `before_filter` so by default, all pages will require a login (except the `HomeController` included in this gem).
|
126
153
|
|
@@ -158,7 +185,7 @@ RSpec.configure do |config|
|
|
158
185
|
end
|
159
186
|
```
|
160
187
|
|
161
|
-
Then, from within any request
|
188
|
+
Then, from within any request spec, you should be able to do this:
|
162
189
|
|
163
190
|
```ruby
|
164
191
|
it "should do some neato feature" do
|
@@ -169,6 +196,8 @@ Then, from within any request or integration spec, you should be able to do this
|
|
169
196
|
|
170
197
|
and the user should now be logged in.
|
171
198
|
|
199
|
+
*NOTE:* For system specs, the logic is a little different - use `system_login_user` rather than `login_user` in these specs.
|
200
|
+
|
172
201
|
|
173
202
|
## Overriding Model And Controller Behavior
|
174
203
|
|