Browse Source

User is trackable

pull/120/head
baarkerlounger 4 years ago
parent
commit
819ce05f1b
  1. 13
      app/models/user.rb
  2. 6
      app/views/organisations/show.html.erb
  3. 12
      db/migrate/20211130144840_add_user_last_logged_in.rb
  4. 7
      db/schema.rb

13
app/models/user.rb

@ -1,7 +1,8 @@
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :recoverable, :rememberable, :validatable
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :recoverable, :rememberable, :validatable,
:trackable
belongs_to :organisation
has_many :owned_case_logs, through: :organisation
@ -18,4 +19,12 @@ class User < ApplicationRecord
def not_completed_case_logs
case_logs.not_completed
end
def name_email_display
%i[name email].map { |field| public_send(field) }.join("\n")
end
def org_role_display
[organisation.name, role].join("\n")
end
end

6
app/views/organisations/show.html.erb

@ -32,9 +32,9 @@
<% @organisation.users.each do |user| %>
<%= table.body do |body| %>
<%= body.row do |row|
row.cell(text: user.email)
row.cell(text: "Data provider")
row.cell(text: "date")
row.cell(text: simple_format(user.name_email_display, {}, wrapper_tag: "div"))
row.cell(text: simple_format(user.org_role_display, {}, wrapper_tag: "div"))
row.cell(text: user.last_sign_in_at )
end %>
<% end %>
<% end %>

12
db/migrate/20211130144840_add_user_last_logged_in.rb

@ -0,0 +1,12 @@
class AddUserLastLoggedIn < ActiveRecord::Migration[6.1]
def change
change_table :users, bulk: true do |t|
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
end
end
end

7
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_11_26_142105) do
ActiveRecord::Schema.define(version: 2021_11_30_144840) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -199,6 +199,11 @@ ActiveRecord::Schema.define(version: 2021_11_26_142105) do
t.string "name"
t.string "role"
t.bigint "organisation_id"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["organisation_id"], name: "index_users_on_organisation_id"
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

Loading…
Cancel
Save