diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-03-17 19:42:46 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-03-17 19:42:46 -0300 |
commit | 0a7f7161198feaa9a4cae7c16669a0e6187aed33 (patch) | |
tree | 445dcbd9f473be2af293a299b634525725a70666 /app/finders/personal_projects_finder.rb | |
parent | a18ac62756573a2da2c42ca50b6f30033be6fa63 (diff) | |
download | gitlab-ce-0a7f7161198feaa9a4cae7c16669a0e6187aed33.tar.gz |
Code fixes
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 |