diff --git a/app/controllers/admin/ldap_users_controller.rb b/app/controllers/admin/ldap_users_controller.rb
index 2e2c3dd..5109041 100644
--- a/app/controllers/admin/ldap_users_controller.rb
+++ b/app/controllers/admin/ldap_users_controller.rb
@@ -2,43 +2,18 @@ class Admin::LdapUsersController < Admin::BaseController
before_action :set_current_section
def index
- attributes = %w{dn cn uid mail admin}
- filter = Net::LDAP::Filter.eq("uid", "*")
-
+ ldap = LdapService.new
@ou = params[:ou] || "kosmos.org"
- treebase = "ou=#{@ou},cn=users,dc=kosmos,dc=org"
-
- entries = ldap_client.search(base: treebase, filter: filter, attributes: attributes)
- entries.sort_by! { |e| e.cn[0] }
-
- @entries = entries.collect do |e|
- {
- uid: e.uid.first,
- mail: e.try(:mail) ? e.mail.first : nil,
- admin: e.try(:admin) ? 'admin' : nil
- # password: e.userpassword.first
- }
- end
- # ldap_client.get_operation_result
+ @orgs = ldap.fetch_organizations
+ @entries = ldap.fetch_users(ou: @ou)
+ @stats = {
+ users_confirmed: User.where(ou: @ou).confirmed.count,
+ users_pending: User.where(ou: @ou).pending.count
+ }
end
private
- def ldap_client
- ldap_client ||= Net::LDAP.new host: ldap_config['host'],
- port: ldap_config['port'],
- # encryption: ldap_config['ssl'],
- auth: {
- method: :simple,
- username: ldap_config['admin_user'],
- password: ldap_config['admin_password']
- }
- end
-
- def ldap_config
- ldap_config ||= YAML.load(ERB.new(File.read("#{Rails.root}/config/ldap.yml")).result)[Rails.env]
- end
-
def set_current_section
@current_section = :ldap_users
end
diff --git a/app/models/user.rb b/app/models/user.rb
index e9237c2..40d5f20 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -15,6 +15,9 @@ class User < ApplicationRecord
validates_uniqueness_of :email
validates :email, email: true
+ scope :confirmed, -> { where.not(confirmed_at: nil) }
+ scope :pending, -> { where(confirmed_at: nil) }
+
lockbox_encrypts :ln_login
lockbox_encrypts :ln_password
diff --git a/app/views/admin/ldap_users/index.html.erb b/app/views/admin/ldap_users/index.html.erb
index 85637b0..e39bd6f 100644
--- a/app/views/admin/ldap_users/index.html.erb
+++ b/app/views/admin/ldap_users/index.html.erb
@@ -1,34 +1,54 @@
<%= render HeaderComponent.new(title: "LDAP Users: #{@ou}") %>
<%= render MainSimpleComponent.new do %>
-
Domains
-
- -
- <%= link_to 'kosmos.org', admin_ldap_users_path, class: "ks-text-link" %>
-
- -
- <%= link_to '5apps.com', admin_ldap_users_path(ou: '5apps.com'), class: "ks-text-link" %>
-
-
+
+ <%= render QuickstatsContainerComponent.new do %>
+ <%= render QuickstatsItemComponent.new(
+ type: :number,
+ title: 'Confirmed',
+ value: @stats[:users_confirmed],
+ ) %>
+ <%= render QuickstatsItemComponent.new(
+ type: :number,
+ title: 'Pending',
+ value: @stats[:users_pending],
+ ) %>
+ <% end %>
+
-
-
-
- UID |
- E-Mail |
- Admin |
-
-
-
-
- <% @entries.each do |entry| %>
-
- <%= entry[:uid] %> |
- <%= entry[:mail] %> |
- <%= entry[:admin] %> |
-
-
- <% end %>
-
-
+ <% if @orgs.length > 1 %>
+
+ Domains
+
+ <% @orgs.each do |org| %>
+ -
+ <%= link_to org[:ou], admin_ldap_users_path(ou: org[:ou]), class: "ks-text-link" %>
+
+ <% end %>
+
+
+ <% end %>
+
+
+
+
+
+ UID |
+ E-Mail |
+ Admin |
+
+
+
+
+ <% @entries.each do |entry| %>
+
+ <%= entry[:uid] %> |
+ <%= entry[:mail] %> |
+ <%= entry[:admin] %> |
+
+
+ <% end %>
+
+
+
<% end %>
diff --git a/spec/components/wallet_summary_component_spec.rb b/spec/components/wallet_summary_component_spec.rb
index 7acdb04..a253964 100644
--- a/spec/components/wallet_summary_component_spec.rb
+++ b/spec/components/wallet_summary_component_spec.rb
@@ -5,7 +5,7 @@ RSpec.describe WalletSummaryComponent, type: :component do
expect(
render_inline(described_class.new(balance: 2301000)) {}.css("section").to_html
).to include(
- "2,301,000 sats"
+ "2,301,000"
)
end
end