diff options
author | ThibG <thib@sitedethib.com> | 2020-01-20 19:20:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-20 19:20:40 +0100 |
commit | a8c109baca4d02cc8aed454e231518c1f8ec1844 (patch) | |
tree | a828f3968b151924656061bfc709b00565aff877 /app/models | |
parent | ddcf78d8d3e2a8cb9aa04f8ff42f9d8e185b0354 (diff) | |
parent | dc2ab6e646bb721ef2e1be268b876bd00e8fa802 (diff) |
Merge pull request #1264 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account_filter.rb | 17 | ||||
-rw-r--r-- | app/models/custom_emoji_filter.rb | 7 | ||||
-rw-r--r-- | app/models/instance_filter.rb | 5 | ||||
-rw-r--r-- | app/models/invite_filter.rb | 5 | ||||
-rw-r--r-- | app/models/relationship_filter.rb | 11 | ||||
-rw-r--r-- | app/models/report_filter.rb | 7 | ||||
-rw-r--r-- | app/models/tag_filter.rb | 10 | ||||
-rw-r--r-- | app/models/user.rb | 16 |
8 files changed, 77 insertions, 1 deletions
diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb index c3b1fe08d..c7bf07787 100644 --- a/app/models/account_filter.rb +++ b/app/models/account_filter.rb @@ -1,6 +1,21 @@ # frozen_string_literal: true class AccountFilter + KEYS = %i( + local + remote + by_domain + active + pending + silenced + suspended + username + display_name + email + ip + staff + ).freeze + attr_reader :params def initialize(params) @@ -50,7 +65,7 @@ class AccountFilter when 'email' accounts_with_users.merge User.matches_email(value) when 'ip' - valid_ip?(value) ? accounts_with_users.where('users.current_sign_in_ip <<= ?', value) : Account.none + valid_ip?(value) ? accounts_with_users.merge(User.matches_ip(value)) : Account.none when 'staff' accounts_with_users.merge User.staff else diff --git a/app/models/custom_emoji_filter.rb b/app/models/custom_emoji_filter.rb index 15b8da1d1..414e1fcdd 100644 --- a/app/models/custom_emoji_filter.rb +++ b/app/models/custom_emoji_filter.rb @@ -1,6 +1,13 @@ # frozen_string_literal: true class CustomEmojiFilter + KEYS = %i( + local + remote + by_domain + shortcode + ).freeze + attr_reader :params def initialize(params) diff --git a/app/models/instance_filter.rb b/app/models/instance_filter.rb index 8bfab826d..9c467bc27 100644 --- a/app/models/instance_filter.rb +++ b/app/models/instance_filter.rb @@ -1,6 +1,11 @@ # frozen_string_literal: true class InstanceFilter + KEYS = %i( + limited + by_domain + ).freeze + attr_reader :params def initialize(params) diff --git a/app/models/invite_filter.rb b/app/models/invite_filter.rb index 7d89bad4a..9685d4abb 100644 --- a/app/models/invite_filter.rb +++ b/app/models/invite_filter.rb @@ -1,6 +1,11 @@ # frozen_string_literal: true class InviteFilter + KEYS = %i( + available + expired + ).freeze + attr_reader :params def initialize(params) diff --git a/app/models/relationship_filter.rb b/app/models/relationship_filter.rb new file mode 100644 index 000000000..51640f494 --- /dev/null +++ b/app/models/relationship_filter.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class RelationshipFilter + KEYS = %i( + relationship + status + by_domain + activity + order + ).freeze +end diff --git a/app/models/report_filter.rb b/app/models/report_filter.rb index abf53cbab..c32d4359e 100644 --- a/app/models/report_filter.rb +++ b/app/models/report_filter.rb @@ -1,6 +1,13 @@ # frozen_string_literal: true class ReportFilter + KEYS = %i( + resolved + account_id + target_account_id + by_target_domain + ).freeze + attr_reader :params def initialize(params) diff --git a/app/models/tag_filter.rb b/app/models/tag_filter.rb index 8921e186b..a9ff5b703 100644 --- a/app/models/tag_filter.rb +++ b/app/models/tag_filter.rb @@ -1,6 +1,16 @@ # frozen_string_literal: true class TagFilter + KEYS = %i( + directory + reviewed + unreviewed + pending_review + popular + active + name + ).freeze + attr_reader :params def initialize(params) 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) |