diff options
author | Thibaut Girka <thib@sitedethib.com> | 2020-01-20 18:31:11 +0100 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2020-01-20 18:31:11 +0100 |
commit | dc2ab6e646bb721ef2e1be268b876bd00e8fa802 (patch) | |
tree | a828f3968b151924656061bfc709b00565aff877 /app/models/user.rb | |
parent | eeb8753adc98022a55051d45a137b02a2bff4c23 (diff) | |
parent | 02063c245c8a2a09e741cbce8302edf3ec14feef (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: - `app/javascript/packs/public.js`: Upstream removed an unused function in code that has been refactored a bit. Removed that function in the corresponding places.
Diffstat (limited to 'app/models/user.rb')
-rw-r--r-- | app/models/user.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 49cfc25ca..794c2091c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -93,6 +93,7 @@ class User < ApplicationRecord scope :inactive, -> { where(arel_table[:current_sign_in_at].lt(ACTIVE_DURATION.ago)) } scope :active, -> { confirmed.where(arel_table[:current_sign_in_at].gteq(ACTIVE_DURATION.ago)).joins(:account).where(accounts: { suspended_at: nil }) } scope :matches_email, ->(value) { where(arel_table[:email].matches("#{value}%")) } + scope :matches_ip, ->(value) { left_joins(:session_activations).where('users.current_sign_in_ip <<= ?', value).or(left_joins(:session_activations).where('users.last_sign_in_ip <<= ?', value)).or(left_joins(:session_activations).where('session_activations.ip <<= ?', value)) } scope :emailable, -> { confirmed.enabled.joins(:account).merge(Account.searchable) } before_validation :sanitize_languages @@ -290,6 +291,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) |