diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-11-18 20:50:29 +0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-12-17 01:28:39 +0300 |
commit | 621b08d8b5cd5ffe22f5bc7fddecc16821c9bd56 (patch) | |
tree | 870c27d9178647f6b8adc357de3bc4e0a902b0c1 /app/models/member.rb | |
parent | 06f696dd0a6326ca521d81203901618afa0f9a9a (diff) |
Fix sort functionality on project/group members to return invited users
Diffstat (limited to 'app/models/member.rb')
-rw-r--r-- | app/models/member.rb | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/app/models/member.rb b/app/models/member.rb index 8c36a631ac4..0312aef32fa 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -57,10 +57,10 @@ 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) } + scope :order_name_asc, -> { left_join_users.reorder(Gitlab::Database.nulls_last_order('users.name', 'ASC')) } + scope :order_name_desc, -> { left_join_users.reorder(Gitlab::Database.nulls_last_order('users.name', 'DESC')) } + scope :order_recent_sign_in, -> { left_join_users.reorder(Gitlab::Database.nulls_last_order('users.last_sign_in_at', 'DESC')) } + scope :order_oldest_sign_in, -> { left_join_users.reorder(Gitlab::Database.nulls_last_order('users.last_sign_in_at', 'ASC')) } before_validation :generate_invite_token, on: :create, if: -> (member) { member.invite_email.present? } @@ -94,6 +94,17 @@ class Member < ActiveRecord::Base end end + def left_join_users + users = User.arel_table + members = Member.arel_table + + member_users = members.join(users, Arel::Nodes::OuterJoin). + on(members[:user_id].eq(users[:id])). + join_sources + + joins(member_users) + end + def access_for_user_ids(user_ids) where(user_id: user_ids).has_access.pluck(:user_id, :access_level).to_h end |