From 819ce05f1ba9c9de52adcd31bc1da74cdb2e0065 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Tue, 30 Nov 2021 14:50:26 +0000 Subject: [PATCH] User is trackable --- app/models/user.rb | 13 +++++++++++-- app/views/organisations/show.html.erb | 6 +++--- .../20211130144840_add_user_last_logged_in.rb | 12 ++++++++++++ db/schema.rb | 7 ++++++- 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20211130144840_add_user_last_logged_in.rb diff --git a/app/models/user.rb b/app/models/user.rb index 3640e1829..dce35da8b 100644 --- a/app/models/user.rb +++ b/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 diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb index 7c892a4d6..48b6d13d5 100644 --- a/app/views/organisations/show.html.erb +++ b/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 %> diff --git a/db/migrate/20211130144840_add_user_last_logged_in.rb b/db/migrate/20211130144840_add_user_last_logged_in.rb new file mode 100644 index 000000000..01cebcef9 --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index e88f28f52..ced98cbd5 100644 --- a/db/schema.rb +++ b/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