ucb_rails_user 8.1.0 → 9.1.1

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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -9
  3. data/app/assets/javascripts/ucb_rails_user/esm/ucb_rails_user.js +1 -111
  4. data/app/assets/javascripts/ucb_rails_user/scripts.js +2 -15
  5. data/app/assets/javascripts/ucb_rails_user/ucb_rails_user.js +1 -103
  6. data/app/assets/stylesheets/ucb_rails_user/components/impersonations.css +26 -0
  7. data/app/assets/stylesheets/ucb_rails_user/components/users_table.css +52 -3
  8. data/app/assets/stylesheets/ucb_rails_user/typeahead_tweaks.css +51 -0
  9. data/app/controllers/concerns/ucb_rails_user/users_controller_concerns.rb +26 -5
  10. data/app/models/ucb_rails_user/ldap_person/finder.rb +1 -1
  11. data/app/views/ucb_rails_user/impersonations/index.html.erb +17 -5
  12. data/app/views/ucb_rails_user/users/_user.html.erb +2 -4
  13. data/app/views/ucb_rails_user/users/edit.html.erb +4 -2
  14. data/app/views/ucb_rails_user/users/impersonate_search.html.erb +25 -0
  15. data/app/views/ucb_rails_user/users/index.html.erb +115 -30
  16. data/app/views/ucb_rails_user/users/new.html.erb +15 -17
  17. data/app/views/ucb_rails_user/users/search.html.erb +15 -0
  18. data/config/importmap.rb +2 -0
  19. data/lib/ucb_rails_user/configuration/cas.rb +6 -7
  20. data/lib/ucb_rails_user/engine.rb +3 -2
  21. data/lib/ucb_rails_user/spec_helpers.rb +1 -1
  22. data/lib/ucb_rails_user/version.rb +1 -1
  23. data/lib/ucb_rails_user.rb +1 -0
  24. metadata +78 -65
  25. data/app/assets/javascripts/ucb_rails_user/datatables.js +0 -16891
  26. data/app/assets/javascripts/ucb_rails_user/esm/bloodhound.js +0 -953
  27. data/app/assets/javascripts/ucb_rails_user/esm/datatables.js +0 -28437
  28. data/app/assets/javascripts/ucb_rails_user/esm/typeahead.js +0 -1538
  29. data/app/assets/javascripts/ucb_rails_user/typeahead.bundle.js +0 -2451
  30. data/app/assets/stylesheets/ucb_rails_user/pagy_tailwind.css +0 -21
  31. data/app/assets/stylesheets/ucb_rails_user/typeahead_tweaks.sass +0 -43
  32. data/app/views/ucb_rails_user/users/search.js.erb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09287b7395b9051f836da163e113b19e79b97f2ca1a4244ac647fb01de4ef398'
4
- data.tar.gz: 91ed2a6b9f2d2aa7a1a8d41c16bca50d179e17eeaec497fce684d606eef3d9ce
3
+ metadata.gz: a16af9946da1457ed822b986c77efb97beeebe928d54218b2006e173ce62c960
4
+ data.tar.gz: fa3300037e1cdbfd5feeafbb3de13158207803f852a7e08f8fa78db770870ad2
5
5
  SHA512:
6
- metadata.gz: 14686fd6c41309f33ae5d16d427c7d6270f6a0f1601d2f2ded8d22562c4cfd124e92f2ca3e3d59a5079309cc1413514c1448c1ce6583b3c51e005c02d5799cb7
7
- data.tar.gz: 5273939befe8db63989e4e4f6940ec23e93f9cecaf1a7aeb20c7acbcad60cd415154b0e4b87b25391bb7dc3a05f3e80c04759d64e7fcc5ce335d6e17a0bc9ff1
6
+ metadata.gz: 4c45a997c96df4496042555db4ffa9cafc7935628efb1e12ca30642c824bc3b2c3ff40706d32ef817dde9eae3b669aee69e9c04d7dcc755c9206f0978592fba2
7
+ data.tar.gz: 37617680e96dcb298b755b22aeda678fd77981665329b96052c6d906f39069c39506e9ba25d2ffbcbafc23abd79d7ede9ba352b3fefc0d733f6300d972d9cc04
data/README.md CHANGED
@@ -10,7 +10,7 @@ A [Rails engine](http://guides.rubyonrails.org/engines.html) that provides authe
10
10
  * ability for admins to impersonate other users
11
11
  * optional generator to create a users table that's compatible with this gem
12
12
 
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
+ The admin screens use Turbo and Pagy. The engine ships no JavaScript; the host app must load Turbo (Installation step 9).
14
14
 
15
15
  ## Conversion to UCPath
16
16
 
@@ -26,8 +26,8 @@ See [this wiki page](https://github.com/ucb-ist-eas/ucb_rails_user/wiki/Upgradin
26
26
 
27
27
  ## Prerequisites
28
28
 
29
- * Ruby >= 3.0
30
- * Rails >= 8.0
29
+ * Ruby >= 3.4.3
30
+ * Rails >= 8.1
31
31
 
32
32
  Older versions may work as well, but they haven't been tested.
33
33
 
@@ -83,13 +83,17 @@ In `application.css` add this line:
83
83
  *= require ucb_rails_user/main
84
84
  ```
85
85
 
86
- And in `application.js` add this line:
86
+ No JavaScript from this gem is needed; remove any `ucb_rails_user` imports or requires.
87
87
 
88
- ```
89
- //= require ucb_rails_user/scripts
90
- ```
88
+ 9. Load Turbo (required for user search, impersonation and delete confirmation)
89
+
90
+ * Propshaft + importmap: `pin "@hotwired/turbo-rails", to: "turbo.min.js"` and `import "@hotwired/turbo-rails"`
91
+ * Sprockets: `<%= javascript_include_tag "turbo", type: "module" %>` in your layout
92
+ * jsbundling: `import "@hotwired/turbo-rails"`
91
93
 
92
- 9. Restart your host app as usual
94
+ If your app's JavaScript isn't written for Turbo Drive, add `Turbo.session.drive = false` after loading it.
95
+
96
+ 10. Restart your host app as usual
93
97
 
94
98
  You should be able to access the following routes:
95
99
 
@@ -131,7 +135,7 @@ resources :users, controller: "ucb_rails_user/users", path: "backend/users", as:
131
135
 
132
136
  ## Session Managers
133
137
 
134
- Authentication during login is handled by UCB's central auth system and this gem uses the [omniauth-cas](https://github.com/dlindahl/omniauth-cas) to manage the handshake. Once that is completed, we're handed the LDAP uid of the authenticated user, and, by default, this gem will attempt to pull the user's employee data and create or update a `User` record for them in the local database.
138
+ Authentication during login is handled by UCB's central auth system and this gem uses [omniauth-cas](https://github.com/dlindahl/omniauth-cas) (OmniAuth 2.x) to manage the handshake. Login starts at `login_path` (`GET /login`), which renders a page with a CSRF-protected button that POSTs to `/auth/cas`. Always link to `login_path`, never to `/auth/cas` directly: OmniAuth 2 rejects GET requests there. Once that is completed, we're handed the LDAP uid of the authenticated user, and, by default, this gem will attempt to pull the user's employee data and create or update a `User` record for them in the local database.
135
139
 
136
140
  This behavior can be customized by writing your own user session manager. There are two steps to do this:
137
141
 
@@ -290,3 +294,5 @@ There is a new session timeout gem that can be used as well. It has a nice Javas
290
294
  ## Version 8+
291
295
 
292
296
  This version removes both the emailing setup functionality as well as the error reporting functionality. Those are both in the [UcbRailsDefaults] (https://gitlab.com/ucb-bit/cad/aa/ucb_rails_defaults) gem. This gem's dependencies have been slimmed down so that only the basics to run the gem are required. This makes it easier to upgrade the including apps.
297
+
298
+ Versions 8.0.x use the new standard of Turbo, importmaps, and propshaft. The 8.0.x versions do not have the latest CAS upgrades in them and are used for Rails 8 apps that are in maintenance mode.
@@ -1,111 +1 @@
1
- import Bloodhound from "ucb_rails_user/bloodhound"
2
-
3
- // the users table has width set to auto, but the pagination tries to stretch to full width - this
4
- // forces the pagination to match the table
5
- var resizePagination = function () {
6
- //var paginationDiv = $('.dataTables_info').parents('.row').first()
7
- //paginationDiv.width($('.dataTable').width())
8
- }
9
-
10
- var addDatatablesToNewUserSearchResults = function () {
11
- $('.add-user-search-results-table').dataTable({
12
- searching: true,
13
- order: [[ 2, "asc" ]],
14
- columnDefs: [ {
15
- targets: 3,
16
- orderable: false
17
- }]
18
- })
19
- resizePagination()
20
- }
21
-
22
- var addDatatablesToUsersTable = function () {
23
- var unsorted_columns = $('.ucb-rails-users-table th.unsorted').map((i, e) => $(e).index()).toArray()
24
- if (unsorted_columns == []) {
25
- var unsorted_columns = $(".ucb-rails-users-table th:contains('Edit'),.ucb-rails-users-table th:contains('Delete')").map((i, e) => $(e).index()).toArray()
26
- }
27
-
28
- $('.ucb-rails-users-table').dataTable({
29
- searching: true,
30
- order: [[ 3, "asc" ]],
31
- columnDefs: [ {
32
- targets: unsorted_columns,
33
- orderable: false
34
- }],
35
- })
36
- var addNewHtml = '&nbsp;&nbsp;<a href="/admin/users/new" class="btn btn-primary">Add New</a>'
37
- $('.ucb-rails-users-table-wrapper #DataTables_Table_0_filter').append(addNewHtml)
38
- }
39
-
40
- var resetImpersonateButton = function() {
41
- var targetId = $('#ucb_rails_user_impersonation_target_id').val()
42
- if (targetId != null && targetId.toString().length > 0) {
43
- $('input[data-impersonate-button]').removeAttr('disabled')
44
- } else {
45
- $('input[data-impersonate-button]').attr('disabled', 'disabled')
46
- }
47
- }
48
-
49
- var clearImpersonateSelection = function() {
50
- $('#ucb_rails_user_impersonation_target_id').val('')
51
- resetImpersonateButton()
52
- }
53
-
54
- $( window ).on("load", function() {
55
- // the datatable calling was failing intermittently, but adding the timeout
56
- // seemed to fix it, so ¯\_(ツ)_/¯
57
- window.setTimeout(addDatatablesToUsersTable, 100)
58
-
59
- $('.user-search-form').on('submit', function() {
60
- $('.search-results').hide()
61
- $('.ucb-rails-user-loader').show()
62
- })
63
-
64
- var usersSource = new Bloodhound({
65
- datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
66
- queryTokenizer: Bloodhound.tokenizers.whitespace,
67
- remote: {
68
- url: '/admin/users/impersonate_search?q=%QUERY',
69
- wildcard: '%QUERY'
70
- }
71
- });
72
-
73
- $('#ucb_rails_user_impersonation_target').typeahead(null, {
74
- name: 'users',
75
- source: usersSource,
76
- display: 'name',
77
- limit: 7, // any higher than this, and the results don't display properly
78
- templates: {
79
- empty: [
80
- '<div class="empty-message">',
81
- 'No match found',
82
- '</div>'
83
- ].join('\n'),
84
- suggestion: function (data) {
85
- return '<div><strong>' + data.name + '</strong> (' + data.uid + ')</div>'
86
- }
87
- }
88
- });
89
-
90
- $('#ucb_rails_user_impersonation_target').keyup(function(event) {
91
- if ($(event.target).val().length == 0) {
92
- clearImpersonateSelection()
93
- }
94
- })
95
-
96
- $('#ucb_rails_user_impersonation_target').bind('typeahead:open', function(event, suggestion) {
97
- clearImpersonateSelection()
98
- })
99
-
100
- $('#ucb_rails_user_impersonation_target').bind('typeahead:select', function(event, suggestion) {
101
- $('#ucb_rails_user_impersonation_target_id').val(suggestion.id)
102
- resetImpersonateButton()
103
- })
104
-
105
- })
106
-
107
- // hack to make this work better with ES modules
108
- window.resizePagination = resizePagination
109
- window.addDatatablesToNewUserSearchResults = addDatatablesToNewUserSearchResults
110
- window.resetImpersonateButton = resetImpersonateButton
111
- window.clearImpersonateSelection = clearImpersonateSelection
1
+ // Empty since 9.1.1; kept so existing imports and requires still resolve.
@@ -1,16 +1,3 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
5
- // vendor/assets/javascripts directory can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
- //
10
- // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
1
+ // Empty since 9.1.1; kept so existing imports and requires still resolve.
2
+ // rails-ujs stays for hosts that relied on this file to load it.
13
3
  //= require rails-ujs
14
- //= require ucb_rails_user/datatables
15
- //= require ucb_rails_user/typeahead.bundle
16
- //= require ucb_rails_user/ucb_rails_user
@@ -1,103 +1 @@
1
- // the users table has width set to auto, but the pagination tries to stretch to full width - this
2
- // forces the pagination to match the table
3
- var resizePagination = function () {
4
- //var paginationDiv = $('.dataTables_info').parents('.row').first()
5
- //paginationDiv.width($('.dataTable').width())
6
- }
7
-
8
- var addDatatablesToNewUserSearchResults = function () {
9
- $('.add-user-search-results-table').dataTable({
10
- searching: true,
11
- order: [[ 2, "asc" ]],
12
- columnDefs: [ {
13
- targets: 3,
14
- orderable: false
15
- }]
16
- })
17
- resizePagination()
18
- }
19
-
20
- var addDatatablesToUsersTable = function () {
21
- var unsorted_columns = $('.ucb-rails-users-table th.unsorted').map((i, e) => $(e).index()).toArray()
22
- if (unsorted_columns == []) {
23
- var unsorted_columns = $(".ucb-rails-users-table th:contains('Edit'),.ucb-rails-users-table th:contains('Delete')").map((i, e) => $(e).index()).toArray()
24
- }
25
-
26
- $('.ucb-rails-users-table').dataTable({
27
- searching: true,
28
- order: [[ 3, "asc" ]],
29
- columnDefs: [ {
30
- targets: unsorted_columns,
31
- orderable: false
32
- }],
33
- })
34
- var addNewHtml = '&nbsp;&nbsp;<a href="/admin/users/new" class="btn btn-primary">Add New</a>'
35
- $('.ucb-rails-users-table-wrapper #DataTables_Table_0_filter').append(addNewHtml)
36
- }
37
-
38
- var resetImpersonateButton = function() {
39
- var targetId = $('#ucb_rails_user_impersonation_target_id').val()
40
- if (targetId != null && targetId.toString().length > 0) {
41
- $('input[data-impersonate-button]').removeAttr('disabled')
42
- } else {
43
- $('input[data-impersonate-button]').attr('disabled', 'disabled')
44
- }
45
- }
46
-
47
- var clearImpersonateSelection = function() {
48
- $('#ucb_rails_user_impersonation_target_id').val('')
49
- resetImpersonateButton()
50
- }
51
-
52
- $( window ).on("load", function() {
53
- // the datatable calling was failing intermittently, but adding the timeout
54
- // seemed to fix it, so ¯\_(ツ)_/¯
55
- window.setTimeout(addDatatablesToUsersTable, 100)
56
-
57
- $('.user-search-form').on('submit', function() {
58
- $('.search-results').hide()
59
- $('.ucb-rails-user-loader').show()
60
- })
61
-
62
- var usersSource = new Bloodhound({
63
- datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
64
- queryTokenizer: Bloodhound.tokenizers.whitespace,
65
- remote: {
66
- url: '/admin/users/impersonate_search?q=%QUERY',
67
- wildcard: '%QUERY'
68
- }
69
- });
70
-
71
- $('#ucb_rails_user_impersonation_target').typeahead(null, {
72
- name: 'users',
73
- source: usersSource,
74
- display: 'name',
75
- limit: 7, // any higher than this, and the results don't display properly
76
- templates: {
77
- empty: [
78
- '<div class="empty-message">',
79
- 'No match found',
80
- '</div>'
81
- ].join('\n'),
82
- suggestion: function (data) {
83
- return '<div><strong>' + data.name + '</strong> (' + data.uid + ')</div>'
84
- }
85
- }
86
- });
87
-
88
- $('#ucb_rails_user_impersonation_target').keyup(function(event) {
89
- if ($(event.target).val().length == 0) {
90
- clearImpersonateSelection()
91
- }
92
- })
93
-
94
- $('#ucb_rails_user_impersonation_target').bind('typeahead:open', function(event, suggestion) {
95
- clearImpersonateSelection()
96
- })
97
-
98
- $('#ucb_rails_user_impersonation_target').bind('typeahead:select', function(event, suggestion) {
99
- $('#ucb_rails_user_impersonation_target_id').val(suggestion.id)
100
- resetImpersonateButton()
101
- })
102
-
103
- })
1
+ // Empty since 9.1.1; kept so existing imports and requires still resolve.
@@ -10,3 +10,29 @@
10
10
  .recent-impersonations li {
11
11
  list-style-type: none;
12
12
  font-size: 110%; }
13
+
14
+ .impersonate_search_results_container {
15
+ margin-top: 10px;
16
+ }
17
+
18
+ .impersonate_result_list {
19
+ list-style: none;
20
+ padding: 0;
21
+ margin-top: 10px;
22
+ }
23
+
24
+ .impersonate_result_list_item {
25
+ padding: 8px;
26
+ border-bottom: 1px solid #eee;
27
+ }
28
+
29
+ .impersonate_no_results_found {
30
+ margin-top: 10px;
31
+ color: #999;
32
+ }
33
+
34
+ .impersonate_before_search {
35
+ margin-top: 10px;
36
+ color: #666;
37
+ }
38
+
@@ -1,13 +1,26 @@
1
1
  .ucb-rails-users-table-header {
2
2
  margin-top: 16px;
3
- margin-bottom: 16px; }
3
+ margin-bottom: 8px; }
4
4
 
5
5
  .ucb-rails-users-table-header a {
6
- margin-top: 16px; }
6
+ margin-top: 0px; }
7
+
8
+ .ucb-rails-users-table-header form {
9
+ display: flex !important;
10
+ gap: 15px;
11
+ align-items: center;
12
+ flex-direction: row;
13
+ }
14
+
15
+ .ucb-rails-users-table-header form span,
16
+ .ucb-rails-users-table-header form select,
17
+ .ucb-rails-users-table-header form input {
18
+ vertical-align: middle;
19
+ }
7
20
 
8
21
  table.ucb-rails-users-table {
9
22
  border-spacing: 0px;
10
- margin-top: 16px;
23
+ margin-top: 8px;
11
24
  }
12
25
 
13
26
  table.ucb-rails-users-table th {
@@ -52,3 +65,39 @@ h1 {
52
65
  padding-left: 10px;
53
66
  padding-right: 10px;
54
67
  }
68
+
69
+ .user_sort {
70
+ text-decoration: none;
71
+ color: inherit;
72
+ }
73
+
74
+ .user_form_container {
75
+ margin-top: 10px;
76
+ overflow: auto;
77
+ margin-bottom: 10px;
78
+ vertical-align: middle;
79
+ }
80
+
81
+ .user_form_base_style {
82
+ display: flex;
83
+ gap: 10px;
84
+ align-items:
85
+ center; flex-grow: 1;
86
+ }
87
+
88
+ .user_form_return_count {
89
+ float: left;
90
+ padding-right: 15px;
91
+ }
92
+
93
+ .user_form_search_box {
94
+ float: left;
95
+ }
96
+
97
+ .user_form_add_user_link {
98
+ float: right;
99
+ }
100
+
101
+ .user_turbo_frame_users {
102
+ margin-bottom: 10px;
103
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Ironically, Bootstrap 3.x breaks styles in typeahead.js - these styles provide the needed repair
3
+ * source: https://gist.github.com/AntMooreWebDev/2f7e423a11bc74359323995df4494167
4
+ */
5
+
6
+ .twitter-typeahead .tt-query,
7
+ .twitter-typeahead .tt-hint {
8
+ margin-bottom: 0;
9
+ }
10
+
11
+ .twitter-typeahead {
12
+ display: block !important;
13
+ }
14
+
15
+ .tt-menu {
16
+ /* make this wide enough to accomodate the org unit code and name */
17
+ width: 400px;
18
+ min-width: 160px;
19
+ margin-top: 2px;
20
+ padding: 5px;
21
+ background-color: #ffffff;
22
+ border: 1px solid #cccccc;
23
+ border: 1px solid rgba(0, 0, 0, 0.15);
24
+ border-radius: 4px;
25
+ -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
26
+ box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
27
+ background-clip: padding-box;
28
+ }
29
+
30
+ .tt-suggestion {
31
+ display: block;
32
+ padding: 3px 20px;
33
+ width: 100%;
34
+ }
35
+
36
+ .tt-suggestion.tt-selectable {
37
+ margin: 5px 0px 5px 0px;
38
+ }
39
+
40
+ .tt-suggestion.tt-cursor {
41
+ color: #fff;
42
+ background-color: #428bca;
43
+ }
44
+
45
+ .tt-suggestion.tt-cursor a {
46
+ color: #fff;
47
+ }
48
+
49
+ .tt-suggestion p {
50
+ margin: 0;
51
+ }
@@ -8,8 +8,23 @@ module UcbRailsUser::UsersControllerConcerns
8
8
  skip_before_action :ensure_admin_user, if: ->{ action_name == "toggle_superuser" && Rails.env.development? }, raise: false
9
9
  end
10
10
 
11
+ SORTABLE_COLUMNS = %w[superuser_flag inactive_flag first_name last_name email last_login_at ldap_uid employee_id].freeze
12
+
11
13
  def index
12
- @pagy, @users = pagy(UcbRailsUser.user_class.all, limit: params[:count])
14
+ @sort = SORTABLE_COLUMNS.include?(params[:sort]) ? params[:sort] : "last_name"
15
+ @sort_dir = params[:dir] == "desc" ? "desc" : "asc"
16
+
17
+ # Build the query
18
+ users = if !params[:query].blank?
19
+ search_user_table(params[:query])
20
+ else
21
+ UcbRailsUser.user_class.all
22
+ end
23
+
24
+ # Apply sorting
25
+ users = users.order(@sort => @sort_dir)
26
+
27
+ @pagy, @users = pagy(users, limit: params[:count])
13
28
  end
14
29
 
15
30
  def search
@@ -24,8 +39,12 @@ module UcbRailsUser::UsersControllerConcerns
24
39
  end
25
40
 
26
41
  def impersonate_search
27
- result = UcbRailsUser::UserSearch.find_users_by_name(params[:q])
28
- render json: result.map { |u| { name: u.full_name, id: u.id, uid: u.ldap_uid } }
42
+ @query = params[:q]
43
+ @results = if @query.present? && @query.length >= 2
44
+ UcbRailsUser::UserSearch.find_users_by_name(@query)
45
+ else
46
+ []
47
+ end
29
48
  end
30
49
 
31
50
  def edit
@@ -91,7 +110,6 @@ module UcbRailsUser::UsersControllerConcerns
91
110
  @lps_existing_uids = UcbRailsUser.user_class.where(ldap_uid: uid_strings).pluck(:uid)
92
111
  render 'ucb_rails_user/lps/search'
93
112
  end
94
-
95
113
  end
96
114
 
97
115
  def typeahead_search
@@ -111,6 +129,10 @@ module UcbRailsUser::UsersControllerConcerns
111
129
 
112
130
  private
113
131
 
132
+ def search_user_table(query)
133
+ UcbRailsUser.user_class.where('lower(first_name) like lower(:q) or lower(last_name) like lower(:q) or lower(email) like lower(:q) or lower(alternate_email) like lower(:q) or ldap_uid like :q or ldap_uid like :q or employee_id like :q', q: '%' + query + '%')
134
+ end
135
+
114
136
  def user_params(extra_params = [])
115
137
  params.require(:user).permit([
116
138
  :superuser_flag,
@@ -130,5 +152,4 @@ module UcbRailsUser::UsersControllerConcerns
130
152
  def find_user
131
153
  @user ||= UcbRailsUser.user_class.find(params.fetch(:id))
132
154
  end
133
-
134
155
  end
@@ -5,7 +5,7 @@ module UcbRailsUser::LdapPerson
5
5
 
6
6
  def benchmark(message = "Benchmarking")
7
7
  result = nil
8
- ms = Benchmark.ms { result = yield }
8
+ ms = ActiveSupport::Benchmark.realtime(:float_millisecond) { result = yield }
9
9
  Rails.logger.debug "#{message} #{ms}"
10
10
  result
11
11
  end
@@ -6,10 +6,22 @@
6
6
  </div>
7
7
  <% else %>
8
8
  <div class="impersonation-form">
9
- <%= simple_form_for UcbRailsUser::Impersonation.new, url: admin_impersonations_path, method: :post do |f| %>
10
- <%= f.input :target, label: "User", input_html: { class: "typeahead" } %>
11
- <%= f.input :target_id, as: :hidden %>
12
- <%= f.button :submit, value: "Impersonate", class: "btn btn-primary", disabled: true, data: { impersonate_button: true } %>
9
+ <%= form_with url: admin_user_impersonate_search_path, method: :get, data: { turbo_frame: "search_results" } do |f| %>
10
+ <%= f.label :q, "Search for user:" %>
11
+ <%= f.search_field :q, placeholder: "Enter name...", oninput: "
12
+ clearTimeout(window.impersonateSearchTimer);
13
+ window.impersonateSearchTimer = setTimeout(() => {
14
+ if (this.value.length >= 2) {
15
+ this.form.requestSubmit();
16
+ }
17
+ }, 300);
18
+ " %>
19
+ <% end %>
20
+
21
+ <%= turbo_frame_tag "search_results" do %>
22
+ <div style="margin-top: 10px; color: #666;">
23
+ Type at least 2 characters to search for a user...
24
+ </div>
13
25
  <% end %>
14
26
  </div>
15
27
  <% end %>
@@ -20,7 +32,7 @@
20
32
  <ul>
21
33
  <% current_user.recent_impersonations.each do |imp| %>
22
34
  <li>
23
- <%= link_to full_name_with_uid(imp.target), "#{admin_impersonations_path}?ucb_rails_user_impersonation[target_id]=#{imp.target.id}", method: :post %>
35
+ <%= link_to full_name_with_uid(imp.target), admin_impersonations_path(ucb_rails_user_impersonation: { target_id: imp.target.id }), data: { turbo_method: :post, turbo_frame: "_top" } %>
24
36
  </li>
25
37
  <% end %>
26
38
  </ul>
@@ -1,4 +1,3 @@
1
- <%= turbo_frame_tag "users" do %>
2
1
  <tr id="user_<%=user.id%>" class="user">
3
2
  <td><%= checkmark(user.superuser?) %></td>
4
3
  <td><%= checkmark(user.inactive?) %></td>
@@ -9,10 +8,9 @@
9
8
  <td class="min"><%= user.ldap_uid %></td>
10
9
  <td class="min"><%= user.employee_id %></td>
11
10
  <td>
12
- <%= link_to 'edit', edit_admin_user_path(user), class: 'btn btn-blue', id: dom_id(user, 'edit') %>
11
+ <%= link_to 'edit', edit_admin_user_path(user), class: 'btn btn-primary', id: dom_id(user, 'edit'), role: 'button', data: { turbo_frame: "users" } %>
13
12
  </td>
14
13
  <td>
15
- <%= button_to 'delete', admin_user_path(user), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %>
14
+ <%= button_to 'delete', admin_user_path(user), method: :delete, form: { data: { turbo_confirm: "Are you sure?" } }, class: "btn btn-danger" %>
16
15
  </td>
17
16
  </tr>
18
- <% end %>
@@ -1,3 +1,5 @@
1
- <h1>Edit User</h1>
1
+ <%= turbo_frame_tag "users" do %>
2
+ <h1>Edit User</h1>
2
3
 
3
- <%= render partial: 'form', locals: { url: admin_user_path(@user), method: :put } %>
4
+ <%= render partial: 'form', locals: { url: admin_user_path(@user), method: :put } %>
5
+ <% end %>
@@ -0,0 +1,25 @@
1
+ <%= turbo_frame_tag "search_results" do %>
2
+ <% if @results.any? %>
3
+ <div class="impersonate_search_results_container">
4
+ <strong>Search results for "<%= @query %>":</strong>
5
+ <ul class="impersonate_result_list">
6
+ <% @results.each do |user| %>
7
+ <li class="impersonate_result_list_item">
8
+ <%= link_to admin_impersonations_path(ucb_rails_user_impersonation: { target_id: user.id }), data: { turbo_method: :post, turbo_frame: "_top" }, style: "text-decoration: none; color: inherit; display: block;" do %>
9
+ <strong><%= user.full_name %></strong>
10
+ <span style="color: #666; margin-left: 10px;">(<%= user.ldap_uid %>)</span>
11
+ <% end %>
12
+ </li>
13
+ <% end %>
14
+ </ul>
15
+ </div>
16
+ <% elsif @query.present? && @query.length >= 2 %>
17
+ <div class="impersonate_no_results_found">
18
+ No users found matching "<%= @query %>"
19
+ </div
20
+ <% else %>
21
+ <div class="impersonate_before_search">
22
+ Type at least 2 characters to search for a user...
23
+ </div>
24
+ <% end %>
25
+ <% end %>