ucb_rails_user 9.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75e8941c6eeaa787837b82537e117f7d22b3e0079123184f9d5f14efa6da7591
4
- data.tar.gz: a1596b62abdff937aec92813bb61374350b6c9cd9a08c01317c0f6749929fda8
3
+ metadata.gz: a16af9946da1457ed822b986c77efb97beeebe928d54218b2006e173ce62c960
4
+ data.tar.gz: fa3300037e1cdbfd5feeafbb3de13158207803f852a7e08f8fa78db770870ad2
5
5
  SHA512:
6
- metadata.gz: f661aad5319ba644f93195afdc2737ca7db8e5c11d9d56330ea4440e3dedc52a9fb0f71d67dafd2fde1a433c294e6452afc378aa5cac6bbb309d201baa3f8045
7
- data.tar.gz: 752153a3da59b7254ab0bb1956f07539e1883f051c04ece5d1667c43dac46592bb528a1980235b45d80fafcb95f1f73bded8fa96c41de1830d8a89a148311d48
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,27 +83,15 @@ 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
- ```
91
-
92
- 9. Enable Turbo (required for admin user search functionality)
93
-
94
- The admin user search uses Turbo Frames for seamless searching without page reloads. Add this to your application layout (typically `app/views/layouts/application.html.erb`):
88
+ 9. Load Turbo (required for user search, impersonation and delete confirmation)
95
89
 
96
- ```erb
97
- <%= turbo_include_tags %>
98
- ```
99
-
100
- Also update any `data-turbolinks-track` attributes to use `data-turbo-track` instead:
101
-
102
- ```erb
103
- <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
104
- ```
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"`
105
93
 
106
- If your app doesn't already include Turbo, make sure the `turbo-rails` gem is in your Gemfile (it's included as a dependency of this gem).
94
+ If your app's JavaScript isn't written for Turbo Drive, add `Turbo.session.drive = false` after loading it.
107
95
 
108
96
  10. Restart your host app as usual
109
97
 
@@ -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,47 +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
- $( window ).on("load", function() {
39
- // the datatable calling was failing intermittently, but adding the timeout
40
- // seemed to fix it, so ¯\_(ツ)_/¯
41
- window.setTimeout(addDatatablesToUsersTable, 100)
42
-
43
- $('.user-search-form').on('submit', function() {
44
- $('.search-results').hide()
45
- $('.ucb-rails-user-loader').show()
46
- })
47
- })
1
+ // Empty since 9.1.1; kept so existing imports and requires still resolve.
@@ -8,9 +8,11 @@ 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
- @sort = params[:sort] || "last_name"
13
- @sort_dir = params[:dir] || "asc"
14
+ @sort = SORTABLE_COLUMNS.include?(params[:sort]) ? params[:sort] : "last_name"
15
+ @sort_dir = params[:dir] == "desc" ? "desc" : "asc"
14
16
 
15
17
  # Build the query
16
18
  users = if !params[:query].blank?
@@ -20,7 +22,7 @@ module UcbRailsUser::UsersControllerConcerns
20
22
  end
21
23
 
22
24
  # Apply sorting
23
- users = users.order("#{@sort} #{@sort_dir}")
25
+ users = users.order(@sort => @sort_dir)
24
26
 
25
27
  @pagy, @users = pagy(users, limit: params[:count])
26
28
  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
@@ -11,6 +11,6 @@
11
11
  <%= link_to 'edit', edit_admin_user_path(user), class: 'btn btn-primary', id: dom_id(user, 'edit'), role: 'button', data: { turbo_frame: "users" } %>
12
12
  </td>
13
13
  <td>
14
- <%= 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" %>
15
15
  </td>
16
16
  </tr>
@@ -9,7 +9,7 @@ module UcbRailsUser
9
9
  g.fixture_replacement :factory_bot
10
10
  g.factory_bot dir: "spec/factories"
11
11
  end
12
- # importmap-rails is optional: hosts on Sprockets/esbuild don't need it
12
+ # importmap-rails is optional: hosts on Sprockets/esbuild don't need it.
13
13
  initializer "ucb_rails_user.importmap", before: "importmap" do |app|
14
14
  next unless app.config.respond_to?(:importmap)
15
15
 
@@ -1,3 +1,3 @@
1
1
  module UcbRailsUser
2
- VERSION = '9.1.0'
2
+ VERSION = '9.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ucb_rails_user
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.1.0
4
+ version: 9.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Downey
@@ -412,7 +412,6 @@ files:
412
412
  - app/views/ucb_rails_user/users/index.html.erb
413
413
  - app/views/ucb_rails_user/users/new.html.erb
414
414
  - app/views/ucb_rails_user/users/search.html.erb
415
- - app/views/ucb_rails_user/users/search.js.erb
416
415
  - config/importmap.rb
417
416
  - config/initializers/simple_form.rb
418
417
  - config/initializers/simple_form_bootstrap.rb
@@ -1,4 +0,0 @@
1
- $('.ucb-rails-user-loader').hide();
2
- $('.search-results').html("<%= j render(partial: 'search_results') %>");
3
- addDatatablesToNewUserSearchResults();
4
- $('.search-results').show();