Add user page to admin panel, improve other admin pages #88

Merged
raucao merged 15 commits from feature/admin_user_details into master 2023-02-26 14:16:41 +00:00
2 changed files with 11 additions and 11 deletions
Showing only changes of commit 8eb487600c - Show all commits

View File

@ -3,10 +3,11 @@ class Admin::UsersController < Admin::BaseController
before_action :set_current_section
def index
ldap = LdapService.new
@ou = params[:ou] || "kosmos.org"
@orgs = ldap.fetch_organizations
@entries = ldap.fetch_users(ou: @ou)
ldap = LdapService.new
@ou = params[:ou] || "kosmos.org"
@orgs = ldap.fetch_organizations
@users = User.where(ou: @ou).order(cn: :asc).to_a
@stats = {
users_confirmed: User.where(ou: @ou).confirmed.count,
users_pending: User.where(ou: @ou).pending.count
Review

Isn't this creating a new DB COUNT query? Since the @users are already there, wouldn't a @users.pending.size be more performant?

Isn't this creating a new DB `COUNT` query? Since the `@users` are already there, wouldn't a `@users.pending.size` be more performant?
Review

@users is not filtered by pending at that point, so .pending would actually create a query that selects all fields from the table using that filter, and then .size would convert the results into an array and count the contained items I believe. So .count should be more performant if that is correct.

`@users` is not filtered by pending at that point, so `.pending` would actually create a query that selects all fields from the table using that filter, and then `.size` would convert the results into an array and count the contained items I believe. So `.count` should be more performant if that is correct.

View File

@ -34,18 +34,17 @@
<thead>
<tr>
<th>UID</th>
<th>E-Mail</th>
<th>Admin</th>
<th>Status</th>
<th>Roles</th>
<!-- <th>Password</th> -->
</tr>
</thead>
<tbody>
<% @entries.each do |entry| %>
<% @users.each do |user| %>
<tr>
<td><%= entry[:uid] %></td>
<td><%= entry[:mail] %></td>
<td><%= entry[:admin] %></td>
<!-- <td><%= entry[:password] %></td> -->
<td><%= link_to(user.cn, admin_user_path(user.address), class: 'ks-text-link') %></td>
<td><%= user.confirmed_at.nil? ? badge("pending", :yellow) : "" %></td>
<td><%= user.is_admin? ? badge("admin", :red) : "" %></td>
</tr>
<% end %>
</tbody>