diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-11-16 19:37:51 -0200 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-12-16 20:28:38 -0200 |
commit | 59d43bea80b56faff54630934694b317cda9f899 (patch) | |
tree | 201fb66b0bc930dfc722008d6220ef9fbc8b2b6e /app/models/member.rb | |
parent | f54ddbf1ecb91ea96b52e18f87ff5ed10ad45747 (diff) | |
download | gitlab-ce-59d43bea80b56faff54630934694b317cda9f899.tar.gz |
Fix sort functionality for group/project members
Diffstat (limited to 'app/models/member.rb')
-rw-r--r-- | app/models/member.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/models/member.rb b/app/models/member.rb index 3b65587c66b..b82b16e6f33 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -57,6 +57,11 @@ class Member < ActiveRecord::Base scope :owners, -> { active.where(access_level: OWNER) } scope :owners_and_masters, -> { active.where(access_level: [OWNER, MASTER]) } + scope :order_name_asc, -> { joins(:user).merge(User.order_name_asc) } + scope :order_name_desc, -> { joins(:user).merge(User.order_name_desc) } + scope :order_recent_sign_in, -> { joins(:user).merge(User.order_recent_sign_in) } + scope :order_oldest_sign_in, -> { joins(:user).merge(User.order_oldest_sign_in) } + before_validation :generate_invite_token, on: :create, if: -> (member) { member.invite_email.present? } after_create :send_invite, if: :invite?, unless: :importing? @@ -72,6 +77,21 @@ class Member < ActiveRecord::Base default_value_for :notification_level, NotificationSetting.levels[:global] class << self + def search(query) + joins(:user).merge(User.search(query)) + end + + def sort(method) + case method.to_s + when 'recent_sign_in' then order_recent_sign_in + when 'oldest_sign_in' then order_oldest_sign_in + when 'last_joined' then order_created_desc + when 'oldest_joined' then order_created_asc + else + order_by(method) + end + end + def access_for_user_ids(user_ids) where(user_id: user_ids).has_access.pluck(:user_id, :access_level).to_h end |