diff options
Diffstat (limited to 'app/finders/personal_projects_finder.rb')
-rw-r--r-- | app/finders/personal_projects_finder.rb | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/app/finders/personal_projects_finder.rb b/app/finders/personal_projects_finder.rb index 0e2d915da54..34f33e2353b 100644 --- a/app/finders/personal_projects_finder.rb +++ b/app/finders/personal_projects_finder.rb @@ -11,7 +11,7 @@ class PersonalProjectsFinder # # Returns an ActiveRecord::Relation. def execute(current_user = nil) - if current_user && !current_user.external? + if current_user relation = projects_visible_to_user(current_user) else relation = public_projects @@ -23,10 +23,7 @@ class PersonalProjectsFinder private def projects_visible_to_user(current_user) - authorized = @user.personal_projects.visible_to_user(current_user) - - union = Gitlab::SQL::Union. - new([authorized.select(:id), public_and_internal_projects.select(:id)]) + union = Gitlab::SQL::Union.new(projects_for_user_ids(current_user)) Project.where("projects.id IN (#{union.to_sql})") end @@ -38,4 +35,14 @@ class PersonalProjectsFinder def public_and_internal_projects @user.personal_projects.public_and_internal_only end + + def projects_for_user_ids(current_user) + authorized = @user.personal_projects.visible_to_user(current_user) + + if current_user.external? + [authorized.select(:id), public_projects.select(:id)] + else + [authorized.select(:id), public_and_internal_projects.select(:id)] + end + end end |