diff options
author | Camil Staps <info@camilstaps.nl> | 2019-08-03 13:57:33 +0300 |
---|---|---|
committer | Camil Staps <info@camilstaps.nl> | 2019-08-07 21:49:37 +0300 |
commit | e726ed5e128893158f102b87e1407ec0a36fc3ce (patch) | |
tree | 279a9ccc0f22a461da6a4298bc803d60cffc32b1 /app/models | |
parent | d2b2486afb5a50ace08bc416be87a1ead12abe3c (diff) |
Handle reviewer comments on !24690
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/user.rb | 14 | ||||
-rw-r--r-- | app/models/users_star_project.rb | 4 |
2 files changed, 10 insertions, 8 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index cfb8cd3819d..ac83c8e3256 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -282,15 +282,17 @@ class User < ApplicationRecord scope :for_todos, -> (todos) { where(id: todos.select(:user_id)) } scope :with_emails, -> { preload(:emails) } scope :with_dashboard, -> (dashboard) { where(dashboard: dashboard) } - scope :with_visible_profile, -> (user) { - if user.nil? - where(private_profile: false) - elsif user.admin? + scope :with_public_profile, -> { where(private_profile: false) } + + def self.with_visible_profile(user) + return with_public_profile if user.nil? + + if user.admin? all else - where(private_profile: false).or where(id: user.id) + with_public_profile.or(where(id: user.id)) end - } + end # Limits the users to those that have TODOs, optionally in the given state. # diff --git a/app/models/users_star_project.rb b/app/models/users_star_project.rb index 04a48739d93..baf055dd6dd 100644 --- a/app/models/users_star_project.rb +++ b/app/models/users_star_project.rb @@ -12,8 +12,8 @@ class UsersStarProject < ApplicationRecord alias_attribute :starred_since, :created_at - scope :order_user_name_asc, -> { joins(:user).reorder('users.name ASC') } - scope :order_user_name_desc, -> { joins(:user).reorder('users.name DESC') } + scope :order_user_name_asc, -> { joins(:user).merge(User.order_name_asc) } + scope :order_user_name_desc, -> { joins(:user).merge(User.order_name_desc) } scope :by_project, -> (project) { where(project_id: project.id) } scope :with_visible_profile, -> (user) { joins(:user).merge(User.with_visible_profile(user)) } |