diff options
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 |