about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2020-01-20 18:00:54 +0100
committerGitHub <noreply@github.com>2020-01-20 18:00:54 +0100
commit02063c245c8a2a09e741cbce8302edf3ec14feef (patch)
tree979a6075ec33f43ef840acab32fe0cafa7d06ee2 /app/models
parent91e4955e08506abc5fa70dadc9ffa6956b1fb0bc (diff)
Fix not all of account's active IPs showing up in admin UI (#12909)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/user.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index a1753784d..a43e63b2e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -290,6 +290,21 @@ class User < ApplicationRecord
     setting_display_media == 'hide_all'
   end
 
+  def recent_ips
+    @recent_ips ||= begin
+      arr = []
+
+      session_activations.each do |session_activation|
+        arr << [session_activation.updated_at, session_activation.ip]
+      end
+
+      arr << [current_sign_in_at, current_sign_in_ip] if current_sign_in_ip.present?
+      arr << [last_sign_in_at, last_sign_in_ip] if last_sign_in_ip.present?
+
+      arr.sort_by(&:first).uniq(&:last).reverse!
+    end
+  end
+
   protected
 
   def send_devise_notification(notification, *args)