summaryrefslogtreecommitdiff
path: root/app/finders/joined_groups_finder.rb
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-12-28 13:32:18 +0200
committerValery Sizov <vsv2711@gmail.com>2016-01-04 16:00:29 +0200
commit8b1844912561a7e6dd0cc361ea1514f2a340e275 (patch)
tree9a6c705fb9ac1c1e6c28f5ed712025c0b020fd1c /app/finders/joined_groups_finder.rb
parent57074d606b20516921ff2297e2f94262b58e3d3e (diff)
downloadgitlab-ce-8b1844912561a7e6dd0cc361ea1514f2a340e275.tar.gz
remove public field from namespace and refactoringnamespace-clean_up
Diffstat (limited to 'app/finders/joined_groups_finder.rb')
-rw-r--r--app/finders/joined_groups_finder.rb49
1 files changed, 0 insertions, 49 deletions
diff --git a/app/finders/joined_groups_finder.rb b/app/finders/joined_groups_finder.rb
deleted file mode 100644
index e7523136fea..00000000000
--- a/app/finders/joined_groups_finder.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-# Class for finding the groups a user is a member of.
-class JoinedGroupsFinder
- def initialize(user = nil)
- @user = user
- end
-
- # Finds the groups of the source user, optionally limited to those visible to
- # the current user.
- #
- # current_user - If given the groups of "@user" will only include the groups
- # "current_user" can also see.
- #
- # Returns an ActiveRecord::Relation.
- def execute(current_user = nil)
- if current_user
- relation = groups_visible_to_user(current_user)
- else
- relation = public_groups
- end
-
- relation.order_id_desc
- end
-
- private
-
- # Returns the groups the user in "current_user" can see.
- #
- # This list includes all public/internal projects as well as the projects of
- # "@user" that "current_user" also has access to.
- def groups_visible_to_user(current_user)
- base = @user.authorized_groups.visible_to_user(current_user)
- extra = public_and_internal_groups
- union = Gitlab::SQL::Union.new([base.select(:id), extra.select(:id)])
-
- Group.where("namespaces.id IN (#{union.to_sql})")
- end
-
- def public_groups
- groups_for_projects(@user.authorized_projects.public_only)
- end
-
- def public_and_internal_groups
- groups_for_projects(@user.authorized_projects.public_and_internal_only)
- end
-
- def groups_for_projects(projects)
- @user.groups.public_and_given_groups(projects.select(:namespace_id))
- end
-end