thecore_ui_rails_admin 3.5.4 → 3.5.5

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: 2e25d04c3b840bf878381f5e3a3e6d18bdd7dc5d22f1f50f26c8e3853c8406ba
4
- data.tar.gz: 700433ded03b3f772826542c0538cb208e6e6948c852838c97e74fcfa494d40d
3
+ metadata.gz: ee26f7626aa5d9fe655b1b9adf800507d5ff7628985926577ed12741a9c9243d
4
+ data.tar.gz: b17ec42cddf7f44951c0234d1d445c968a5d9f35116f4d4c84f5ac4682fe75e8
5
5
  SHA512:
6
- metadata.gz: 9134ec81516e589c99927f777a95a93afb4e8536ebb4c819be6fa5c31bbbfe73c90a72918b9178d49c667396834c7f411f46d0dc8acd618ce0eba53fcb12f602
7
- data.tar.gz: 4c49d4697527d85773c940f2e5560acc34200e7b8d7cea001bedfc085ca3d1b8a9f8bf9ece6f76c77840b42bf3f844a0ebdf7b325e487b2433a683ba60a71dfe
6
+ metadata.gz: 7bbce89f9c60dccff3a1fc235166fdbcc2c7d9817336d0982d280b807231f2ae64bc80ae918f6789b1c91e1716296047de6d2c8a20631223ade6578f81b1cae8
7
+ data.tar.gz: ef4f4b943bbf0437dc89852df5ee0c49db52181242bdd78a3e22983a05bccf894d3c4a5dfe062960ca303eb865f3524211921fdee8c2e9b3c37addc09d87361e
@@ -25,7 +25,7 @@
25
25
  <h5>Test LDAP Connection with Custom Credentials</h5>
26
26
  </div>
27
27
  <div class="card-body">
28
- <%= form_with url: rails_admin.test_ldap_server_path, method: :post, local: true do |form| %>
28
+ <%= form_with url: rails_admin.test_ldap_server_path, method: :post, remote: true, local: false do |form| %>
29
29
  <div class="mb-3">
30
30
  <%= form.label :email, 'Email', class: 'form-label' %>
31
31
  <%= form.email_field :email, class: 'form-control', required: true %>
@@ -34,26 +34,35 @@
34
34
  <%= form.label :password, 'Password', class: 'form-label' %>
35
35
  <%= form.password_field :password, class: 'form-control', required: true %>
36
36
  </div>
37
- <%= form.submit 'Test Connection', class: 'btn btn-primary' %>
37
+ <%= form.submit 'Test Connection', class: 'btn btn-primary', id: "test-connection" %>
38
38
  <% end %>
39
39
  </div>
40
40
  </div>
41
41
 
42
- <!-- In the @ldap_user variable, if present, show the details of the authenticated user -->
43
- <% if @ldap_user %>
44
- <div class="card mt-4">
45
- <div class="card-header">
46
- <h5>Authenticated LDAP User Details</h5>
47
- </div>
48
- <div class="card-body">
49
- <p><strong>DN:</strong> <%= @ldap_user.dn %></p>
50
- <p><strong>Attributes:</strong></p>
51
- <ul>
52
- <% @ldap_user.each_attribute do |key, values| %>
53
- <li><strong><%= key %>:</strong> <%= values.join(', ') %></li>
54
- <% end %>
55
- </ul>
56
-
57
- </div>
42
+ <!-- In the @ldap_user variable, if present, show the details of the authenticated user, I'll fill these via JS -->
43
+ <div class="card mt-4 visually-hidden" id="ldap-user-details">
44
+ <div class="card-header">
45
+ <h5>Authenticated LDAP User Details</h5>
46
+ </div>
47
+ <div class="card-body">
48
+ <p><strong>DN:</strong> <span id="ldap-user-dn"></span></p>
49
+ <p><strong>Attributes:</strong></p>
50
+ <ul id="ldap-user-attributes">
51
+ </ul>
58
52
  </div>
59
- <% end %>
53
+ </div>
54
+
55
+ <span id="spinner" class="spinner-grow spinner-grow-sm visually-hidden" role="status" aria-hidden="true"></span>
56
+
57
+ <script>
58
+ // This is the javascript that will update the div with the new token //-->
59
+ document.addEventListener("turbo:load", function() {
60
+ $('#test-connection').on('click', function(e, data, status, xhr) {
61
+ $('#spinner').removeClass("visually-hidden");
62
+ // Clear the previous user details
63
+ $("#ldap-user-dn").text("");
64
+ $("#ldap-user-attributes").empty();
65
+ $("#ldap-user-details").addClass("visually-hidden");
66
+ });
67
+ });
68
+ </script>
@@ -0,0 +1,19 @@
1
+ $('#spinner').addClass("visually-hidden");
2
+
3
+ console.log("LDAP Test: Received response from server.");
4
+
5
+ // If @ldap_user exists, authentication succeeded, translate the following Ruby code to jQuery
6
+ <% if @ldap_user %>
7
+ <% @ldap_attributes.each do |key, values| %>
8
+ $("#ldap-user-attributes").append("<li><strong><%= j key %>:</strong> <%= j values.join(', ') %></li>");
9
+ <% end %>
10
+
11
+ // Remove the visually-hidden class to show the user details section from the #ldap-user-details div
12
+ $("#ldap-user-details").removeClass("visually-hidden");
13
+
14
+ // Set the DN span text to the user's DN
15
+ $("#ldap-user-dn").text("<%= j @ldap_user.dn %>");
16
+ <% else %>
17
+ // If no @ldap_user, hide the user details section
18
+ $("#ldap-user-details").addClass("visually-hidden");
19
+ <% end %>
@@ -1,56 +1,56 @@
1
1
  Rails.application.configure do
2
- config.after_initialize do
3
- puts "ThecoreUiRailsAdmin after_initialize"
4
-
5
- RailsAdmin::ApplicationController.send(:include, ConcernCommonApplicationController)
6
- ApplicationController.send(:include, ConcernRAApplicationController)
7
- RailsAdmin::ApplicationController.send(:include, ConcernRAApplicationController)
8
- ## Rails Admin
9
- require 'rails_admin_abstract_controller'
10
- RailsAdmin::Config.parent_controller = '::RailsAdminAbstractController'
11
- ### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
12
- ## == Devise ==
13
- RailsAdmin::Config.authenticate_with do
14
- warden.authenticate! scope: :user
15
- end
16
- RailsAdmin::Config.current_user_method(&:current_user)
17
-
18
- ## == Cancan ==
19
- RailsAdmin::Config.authorize_with :cancancan
20
-
21
- RailsAdmin::Config.main_app_name = Proc.new { |controller| [ ((ThecoreSettings::Setting.where(ns: :main, key: :app_name).pluck(:raw).first.presence || ENV["APP_NAME"]) rescue "Thecore"), "" ] }
22
-
23
- RailsAdmin::Config.show_gravatar = false
24
-
25
- RailsAdmin::Config.label_methods.unshift(:display_name)
26
-
27
- RailsAdmin::Config.excluded_models << ActionText::RichText
28
- RailsAdmin::Config.excluded_models << ActionText::EncryptedRichText
29
- RailsAdmin::Config.excluded_models << ActiveStorage::Blob
30
- RailsAdmin::Config.excluded_models << ActiveStorage::Attachment
31
- RailsAdmin::Config.excluded_models << ActiveStorage::VariantRecord
32
- RailsAdmin::Config.excluded_models << ActionMailbox::InboundEmail
33
- RailsAdmin::Config.excluded_models << UsedToken rescue puts "No UsedToken Model it could be normal: maybe model_driven_api is not installed"
34
-
35
- RailsAdmin::Config::Actions::Export.send(:include, ExportConcern)
36
- RailsAdmin::Config::Actions::BulkDelete.send(:include, BulkDeleteConcern)
37
-
38
- Role.send :include, ThecoreUiRailsAdminRoleConcern
39
- User.send :include, ThecoreUiRailsAdminUserConcern
40
- RoleUser.send :include, ThecoreUiRailsAdminRoleUserConcern
41
- Action.send :include, ThecoreUiRailsAdminActionConcern
42
- PermissionRole.send :include, ThecoreUiRailsAdminPermissionRoleConcern
43
- Permission.send :include, ThecoreUiRailsAdminPermissionConcern
44
- Predicate.send :include, ThecoreUiRailsAdminPredicateConcern
45
- Target.send :include, ThecoreUiRailsAdminTargetConcern
46
- ThecoreSettings::Setting.send :include, ThecoreUiRailsAdminSettingsConcern
47
-
48
- require 'root_actions/general_computation'
49
- require 'root_actions/active_job_monitor'
50
- require 'member_actions/change_password'
51
- require 'member_actions/test_ldap_server'
52
- require 'member_actions/import_users_from_ldap'
53
- require 'collection_actions/save_filters'
54
- require 'collection_actions/load_filters'
2
+ config.after_initialize do
3
+ puts "ThecoreUiRailsAdmin after_initialize"
4
+
5
+ RailsAdmin::ApplicationController.send(:include, ConcernCommonApplicationController)
6
+ ApplicationController.send(:include, ConcernRAApplicationController)
7
+ RailsAdmin::ApplicationController.send(:include, ConcernRAApplicationController)
8
+ ## Rails Admin
9
+ require "rails_admin_abstract_controller"
10
+ RailsAdmin::Config.parent_controller = "::RailsAdminAbstractController"
11
+ ### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
12
+ ## == Devise ==
13
+ RailsAdmin::Config.authenticate_with do
14
+ warden.authenticate! scope: :user
55
15
  end
56
- end
16
+ RailsAdmin::Config.current_user_method(&:current_user)
17
+
18
+ ## == Cancan ==
19
+ RailsAdmin::Config.authorize_with :cancancan
20
+
21
+ RailsAdmin::Config.main_app_name = Proc.new { |controller| [((ThecoreSettings::Setting.where(ns: :main, key: :app_name).pluck(:raw).first.presence || ENV["APP_NAME"]) rescue "Thecore"), ""] }
22
+
23
+ RailsAdmin::Config.show_gravatar = false
24
+
25
+ RailsAdmin::Config.label_methods.unshift(:display_name)
26
+
27
+ RailsAdmin::Config.excluded_models << ActionText::RichText
28
+ RailsAdmin::Config.excluded_models << ActionText::EncryptedRichText
29
+ RailsAdmin::Config.excluded_models << ActiveStorage::Blob
30
+ RailsAdmin::Config.excluded_models << ActiveStorage::Attachment
31
+ RailsAdmin::Config.excluded_models << ActiveStorage::VariantRecord
32
+ RailsAdmin::Config.excluded_models << ActionMailbox::InboundEmail
33
+ RailsAdmin::Config.excluded_models << UsedToken rescue puts "No UsedToken Model it could be normal: maybe model_driven_api is not installed"
34
+
35
+ RailsAdmin::Config::Actions::Export.send(:include, ExportConcern)
36
+ RailsAdmin::Config::Actions::BulkDelete.send(:include, BulkDeleteConcern)
37
+
38
+ Role.send :include, ThecoreUiRailsAdminRoleConcern
39
+ User.send :include, ThecoreUiRailsAdminUserConcern
40
+ RoleUser.send :include, ThecoreUiRailsAdminRoleUserConcern
41
+ Action.send :include, ThecoreUiRailsAdminActionConcern
42
+ PermissionRole.send :include, ThecoreUiRailsAdminPermissionRoleConcern
43
+ Permission.send :include, ThecoreUiRailsAdminPermissionConcern
44
+ Predicate.send :include, ThecoreUiRailsAdminPredicateConcern
45
+ Target.send :include, ThecoreUiRailsAdminTargetConcern
46
+ ThecoreSettings::Setting.send :include, ThecoreUiRailsAdminSettingsConcern
47
+
48
+ require "root_actions/general_computation"
49
+ require "root_actions/active_job_monitor"
50
+ require "member_actions/change_password"
51
+ require "member_actions/test_ldap_server"
52
+ # require 'member_actions/import_users_from_ldap' # Disabled as it's a bit risky to have it in the UI
53
+ require "collection_actions/save_filters"
54
+ require "collection_actions/load_filters"
55
+ end
56
+ end
@@ -10,38 +10,50 @@ RailsAdmin::Config::Actions.add_action "test_ldap_server", :base, :member do
10
10
  # Adding the controller which is needed to compute calls from the ui
11
11
  controller do
12
12
  proc do
13
+ @ldap = ::LdapServer.find(@object.id)
14
+ # begin
15
+ @ldap.test_connection
16
+ @status = "success"
17
+
18
+ @message = I18n.t("admin.actions.test_ldap_server.success")
19
+
13
20
  # From the UI the user can test if the ldap server is reachable and receive a response
14
- if request.get? || request.post?
15
- @ldap = ::LdapServer.find(@object.id)
16
- # begin
17
- @ldap.test_connection
18
- @status = "success"
19
-
20
- @message = I18n.t("admin.actions.test_ldap_server.success")
21
-
22
- # If in the form an email and password are provided, try to authenticate
23
- if params[:email].present? && params[:password].present?
24
- Rails.logger.debug("LDAP Test: Attempting to authenticate user #{params[:email]}")
25
- authenticator = Ldap::Authenticator.new(
26
- email: params[:email],
27
- password: params[:password],
28
- )
29
- @ldap_user = authenticator.auth_on_single_server(@ldap)
30
- Rails.logger.debug("LDAP Test: Authentication result for user #{params[:email]}: #{@ldap_user.inspect}")
31
- # If @ldap_user exists, authentication succeeded
32
- if @ldap_user
33
- @message += " " + I18n.t("admin.actions.test_ldap_server.auth_success", email: params[:email])
34
- else
35
- @message += " " + I18n.t("admin.actions.test_ldap_server.auth_failure", email: params[:email])
36
- @status = "warning"
21
+ if request.xhr? && request.post? && params[:email].present? && params[:password].present?
22
+ Rails.logger.debug("LDAP Test: Attempting to authenticate user #{params[:email]}")
23
+ authenticator = Ldap::Authenticator.new(
24
+ email: params[:email],
25
+ password: params[:password],
26
+ )
27
+ @ldap_user = authenticator.auth_on_single_server(@ldap)
28
+ @ldap_attributes = {}
29
+
30
+ @ldap_user.each_attribute do |key, values|
31
+ safe_values = values.map do |v|
32
+ s = v.to_s
33
+
34
+ # 1. Declare UTF-8
35
+ s.force_encoding("UTF-8")
36
+
37
+ # 2. Replace invalid / undefined bytes
38
+ s.encode!("UTF-8", invalid: :replace, undef: :replace, replace: "�")
39
+
40
+ s
37
41
  end
42
+
43
+ @ldap_attributes[key] = safe_values
44
+ end
45
+ Rails.logger.debug("LDAP Test: Authentication result for user #{params[:email]}: #{@ldap_user.inspect}")
46
+ if @ldap_user
47
+ @message += " " + I18n.t("admin.actions.test_ldap_server.auth_success", email: params[:email])
48
+ else
49
+ @message += " " + I18n.t("admin.actions.test_ldap_server.auth_failure", email: params[:email])
50
+ @status = "warning"
38
51
  end
52
+ # else
39
53
  # rescue => e
40
54
  # @message = I18n.t("admin.actions.test_ldap_server.error", error: e.message)
41
55
  # @status = "danger"
42
56
  # end
43
- # Redirect to the object
44
- # redirect_to index_path(model_name: @abstract_model.to_param)
45
57
  end
46
58
  end
47
59
  end
@@ -1,3 +1,3 @@
1
1
  module ThecoreUiRailsAdmin
2
- VERSION = "3.5.4".freeze
2
+ VERSION = "3.5.5".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_ui_rails_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.4
4
+ version: 3.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
@@ -94,6 +94,7 @@ files:
94
94
  - app/views/rails_admin/main/load_filters.html.erb
95
95
  - app/views/rails_admin/main/save_filter.html.erb
96
96
  - app/views/rails_admin/main/test_ldap_server.html.erb
97
+ - app/views/rails_admin/main/test_ldap_server.js.erb
97
98
  - config/initializers/abilities.rb
98
99
  - config/initializers/add_to_db_migrations.rb
99
100
  - config/initializers/after_initialize.rb