diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-06-05 20:37:35 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-06-05 20:37:35 +0300 |
commit | 0fdce4a52b1a9ba9e0efd98f00e558e4f07daeb5 (patch) | |
tree | 9305a29f92c3d6763d6b7038ac65a71ec67e087e /app/finders | |
parent | 4ca6ebf017e93686ee885ee1a28dc5c6934c9d39 (diff) | |
download | gitlab-ce-0fdce4a52b1a9ba9e0efd98f00e558e4f07daeb5.tar.gz |
Refactor some search scopes to prevent wierd behaviour and PG::Error issues
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/base_finder.rb | 2 | ||||
-rw-r--r-- | app/finders/projects_finder.rb | 36 |
2 files changed, 33 insertions, 5 deletions
diff --git a/app/finders/base_finder.rb b/app/finders/base_finder.rb index 7fc5840561c..7150bb2e31b 100644 --- a/app/finders/base_finder.rb +++ b/app/finders/base_finder.rb @@ -49,7 +49,7 @@ class BaseFinder elsif current_user && params[:authorized_only].presence klass.of_projects(current_user.authorized_projects).references(:project) else - klass.of_projects(Project.accessible_to(current_user)).references(:project) + klass.of_projects(ProjectsFinder.new.execute(current_user)).references(:project) end end diff --git a/app/finders/projects_finder.rb b/app/finders/projects_finder.rb index bfaba758788..26898bad493 100644 --- a/app/finders/projects_finder.rb +++ b/app/finders/projects_finder.rb @@ -1,5 +1,5 @@ class ProjectsFinder - def execute(current_user, options) + def execute(current_user, options = {}) group = options[:group] if group @@ -56,8 +56,36 @@ class ProjectsFinder end end - def all_projects - # TODO: implement - raise 'Not implemented yet' + def all_projects(current_user) + if current_user + if current_user.authorized_projects.any? + # User has access to private projects + # + # Return only: + # public projects + # internal projects + # joined projects + # + Project.where( + "projects.id IN (?) OR projects.visibility_level IN (?)", + current_user.authorized_projects.pluck(:id), + Project.public_and_internal_levels + ) + else + # User has no access to private projects + # + # Return only: + # public projects + # internal projects + # + Project.public_and_internal_only + end + else + # Not authenticated + # + # Return only: + # public projects + Project.public_only + end end end |