summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-06-05 20:36:59 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-06-05 20:36:59 +0300
commit4ca6ebf017e93686ee885ee1a28dc5c6934c9d39 (patch)
treee5723ed5d27d133d0cb91e0721d1a59f8eecf341 /app
parent70a6af9328b663c93a5802bf689362525ec4ae87 (diff)
downloadgitlab-ce-4ca6ebf017e93686ee885ee1a28dc5c6934c9d39.tar.gz
Add GroupFinder for collection all groups user has access to
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app')
-rw-r--r--app/finders/groups_finder.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/app/finders/groups_finder.rb b/app/finders/groups_finder.rb
new file mode 100644
index 00000000000..d3597ef0901
--- /dev/null
+++ b/app/finders/groups_finder.rb
@@ -0,0 +1,38 @@
+class GroupsFinder
+ def execute(current_user, options = {})
+ all_groups(current_user)
+ end
+
+ private
+
+ def all_groups(current_user)
+ if current_user
+ if current_user.authorized_groups.any?
+ # User has access to groups
+ #
+ # Return only:
+ # groups with public projects
+ # groups with internal projects
+ # groups with joined projects
+ #
+ group_ids = Project.public_and_internal_only.pluck(:namespace_id) +
+ current_user.authorized_groups.pluck(:id)
+ Group.where(id: group_ids)
+ else
+ # User has no group membership
+ #
+ # Return only:
+ # groups with public projects
+ # groups with internal projects
+ #
+ Group.where(id: Project.public_and_internal_only.pluck(:namespace_id))
+ end
+ else
+ # Not authenticated
+ #
+ # Return only:
+ # groups with public projects
+ Group.where(id: Project.public_only.pluck(:namespace_id))
+ end
+ end
+end