Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-03-09 03:01:33 +0300
committerFelipe Artur <felipefac@gmail.com>2016-03-10 16:38:36 +0300
commitc3e70280dffe7ee0859ebd73b902d424ca5f809a (patch)
tree06b83a5ab13d19803332253cf50a941501b29317 /app/finders/joined_groups_finder.rb
parentbd59e59d01c5e845c7f7d451feaa1488670f20de (diff)
Prevent projects to have higher visibility than groups
Prevent Groups to have smaller visibility than projects Add default_group_visibility_level to configuration Code improvements
Diffstat (limited to 'app/finders/joined_groups_finder.rb')
-rw-r--r--app/finders/joined_groups_finder.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/app/finders/joined_groups_finder.rb b/app/finders/joined_groups_finder.rb
new file mode 100644
index 00000000000..131b518563e
--- /dev/null
+++ b/app/finders/joined_groups_finder.rb
@@ -0,0 +1,45 @@
+#Shows only authorized groups of a user
+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
+ @user.authorized_groups.public_only
+ end
+
+ def public_and_internal_groups
+ @user.authorized_groups.public_and_internal_only
+ end
+end