diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-03-08 21:01:33 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-03-10 10:38:36 -0300 |
commit | c3e70280dffe7ee0859ebd73b902d424ca5f809a (patch) | |
tree | 06b83a5ab13d19803332253cf50a941501b29317 /app/finders | |
parent | bd59e59d01c5e845c7f7d451feaa1488670f20de (diff) | |
download | gitlab-ce-c3e70280dffe7ee0859ebd73b902d424ca5f809a.tar.gz |
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')
-rw-r--r-- | app/finders/joined_groups_finder.rb | 45 |
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 |