diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-06-05 21:37:35 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-06-05 21:37:35 +0400 |
commit | 0fdce4a52b1a9ba9e0efd98f00e558e4f07daeb5 (patch) | |
tree | 9305a29f92c3d6763d6b7038ac65a71ec67e087e /app/finders/projects_finder.rb | |
parent | 4ca6ebf017e93686ee885ee1a28dc5c6934c9d39 (diff) |
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/projects_finder.rb')
-rw-r--r-- | app/finders/projects_finder.rb | 36 |
1 files changed, 32 insertions, 4 deletions
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 |