summaryrefslogtreecommitdiff
path: root/app/finders
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-03-01 12:22:29 -0300
committerFelipe Artur <felipefac@gmail.com>2016-03-10 10:38:36 -0300
commitf2a9ee258e0ee3a6fe0cb614e4b73c56dcd7339d (patch)
tree84e668890ee51355f7ac9275012fbee3e295f5c4 /app/finders
parent60ddd5ef34686e1ea9edc82a6915a9e4738bee50 (diff)
downloadgitlab-ce-f2a9ee258e0ee3a6fe0cb614e4b73c56dcd7339d.tar.gz
Add permission level to groups
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/groups_finder.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/finders/groups_finder.rb b/app/finders/groups_finder.rb
new file mode 100644
index 00000000000..a3a8cd541de
--- /dev/null
+++ b/app/finders/groups_finder.rb
@@ -0,0 +1,31 @@
+class GroupsFinder
+ def execute(current_user = nil)
+
+ segments = all_groups(current_user)
+
+ if segments.length > 1
+ union = Gitlab::SQL::Union.new(segments.map { |s| s.select(:id) })
+ Group.where("namespaces.id IN (#{union.to_sql})").order_id_desc
+ else
+ segments.first
+ end
+ end
+
+ private
+
+ def all_groups(current_user)
+ if current_user
+ [current_user.authorized_groups, public_and_internal_groups]
+ else
+ [Group.public_only]
+ end
+ end
+
+ def public_groups
+ Group.unscoped.public_only
+ end
+
+ def public_and_internal_groups
+ Group.unscoped.public_and_internal_only
+ end
+end