From c2b6cb7ea85d79ab1b18c198c4d4576b529a90f2 Mon Sep 17 00:00:00 2001 From: gtanzillo Date: Mon, 24 Aug 2020 15:04:51 -0400 Subject: [PATCH] Link user to the sessions create to enable lookup of all sessions by user Fixes https://github.com/ManageIQ/manageiq/issues/20476 --- app/models/user.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index ebb9a9a2219a..31e1888f6693 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -26,6 +26,7 @@ class User < ApplicationRecord has_many :unseen_notification_recipients, -> { unseen }, :class_name => 'NotificationRecipient' has_many :unseen_notifications, :through => :unseen_notification_recipients, :source => :notification has_many :authentications, :foreign_key => :evm_owner_id, :dependent => :nullify, :inverse_of => :evm_owner + has_many :sessions, :dependent => :destroy belongs_to :current_group, :class_name => "MiqGroup" has_and_belongs_to_many :miq_groups scope :superadmins, lambda { @@ -206,7 +207,17 @@ def self.authenticator(username = nil) end def self.authenticate(username, password, request = nil, options = {}) - authenticator(username).authenticate(username, password, request, options) + user = authenticator(username).authenticate(username, password, request, options) + user.try(:link_user_to_session, request) + + user + end + + def link_user_to_session(request) + return unless request + + session_id = request.session_options[:id] + sessions << Session.find_or_create_by(:session_id => session_id) end def self.authenticate_with_http_basic(username, password, request = nil, options = {})