Skip to content

Commit d19dd5f

Browse files
authored
adding last_login_at on sign-in, so it can be used in the admin view and elsewhere later. Also added the overall user count (#75)
Signed-off-by: Kai Wagner <kai.wagner@percona.com>
1 parent b3a28a9 commit d19dd5f

7 files changed

Lines changed: 21 additions & 1 deletion

File tree

app/assets/stylesheets/components/settings.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
margin-bottom: var(--spacing-8);
99
}
1010

11+
.settings-page .settings-page-count {
12+
font-weight: var(--font-weight-regular);
13+
color: var(--color-text-muted);
14+
margin-left: var(--spacing-2);
15+
}
16+
1117
.settings-section {
1218
padding: var(--spacing-6) 0;
1319
border-bottom: var(--border-width) solid var(--color-border);

app/controllers/admin/users_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def active_admin_section
88
end
99

1010
def index
11+
@users_total_count = User.active.count
1112
@users = User.active
1213
.includes(person: [ :default_alias, :aliases ])
1314
.order(created_at: :desc)

app/controllers/omniauth_callbacks_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def google_oauth2
9191

9292
reset_session
9393
session[:user_id] = identity.user_id
94+
identity.user.update_columns(last_login_at: Time.current)
9495
redirect_to root_path, notice: "Signed in with Google"
9596
rescue => e
9697
Rails.logger.error("OIDC error: #{e.class}: #{e.message}")

app/controllers/sessions_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def create
2121
else
2222
reset_session
2323
session[:user_id] = user.id
24+
user.update_columns(last_login_at: Time.current)
2425
redirect_to root_path, notice: "Signed in successfully"
2526
end
2627
end

app/controllers/verifications_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def handle_register(token)
7171

7272
reset_session
7373
session[:user_id] = user.id
74+
user.update_columns(last_login_at: Time.current)
7475
redirect_to root_path, notice: "Registration complete. You are signed in."
7576
end
7677

app/views/admin/users/index.html.slim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
- content_for :title, "Admin — Users"
22

33
.settings-page
4-
h1 Users
4+
h1
5+
| Users
6+
- if @users_total_count
7+
span.settings-page-count = "(#{@users_total_count})"
58

69
.email-table-wrap
710
table.email-table
@@ -11,6 +14,7 @@
1114
th Emails
1215
th Admin
1316
th Created
17+
th Last login
1418
th Actions
1519
tbody
1620
- @users.each do |user|
@@ -41,5 +45,6 @@
4145
= button_to toggle_admin_admin_user_path(user), method: :post, class: "button-secondary button-small", data: { turbo_confirm: "#{user.admin? ? 'Remove' : 'Grant'} admin privileges for #{user.username}?" } do
4246
= user.admin? ? "Remove admin" : "Make admin"
4347
td = user.created_at.strftime('%Y-%m-%d')
48+
td = user.last_login_at ? smart_time_display(user.last_login_at) : ""
4449
td
4550
= link_to "Add email", new_email_admin_user_path(user), class: "button-secondary button-small"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddLastLoginAtToUsers < ActiveRecord::Migration[7.1]
2+
def change
3+
add_column :users, :last_login_at, :datetime
4+
end
5+
end

0 commit comments

Comments
 (0)