summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/user.rb9
-rw-r--r--app/models/users_star_project.rb2
2 files changed, 10 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 4630552e02e..d671c291ec5 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -282,6 +282,15 @@ 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, nil])
+ elsif user.admin?
+ all
+ else
+ where(private_profile: [false, nil]).or where(id: user.id)
+ 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 6eabdebd89c..e171a8220d0 100644
--- a/app/models/users_star_project.rb
+++ b/app/models/users_star_project.rb
@@ -15,7 +15,7 @@ class UsersStarProject < ApplicationRecord
scope :order_user_name_asc, -> { joins(:user).reorder('"users"."name" ASC') }
scope :order_user_name_desc, -> { joins(:user).reorder('"users"."name" DESC') }
scope :by_project, -> (project) { where(project_id: project.id) }
- scope :with_visible_profile, -> (user) { joins(:user).where('"users"."private_profile" IS NULL OR "users"."private_profile" = ? OR "users"."id" = ?', false, user.id ) }
+ scope :with_visible_profile, -> (user) { joins(:user).merge(User.with_visible_profile(user)) }
class << self
def sort_by_attribute(method)