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:
authorMario de la Ossa <mariodelaossa@gmail.com>2018-04-26 22:53:13 +0300
committerMario de la Ossa <mariodelaossa@gmail.com>2018-05-04 20:33:09 +0300
commit5c2078838bb9de710f9025513c4b6ec664bba313 (patch)
tree338656dae97b6c6687e6794b583b0ae431aa5e2f /app/models/group.rb
parente71351d4f463715fccd80ddbcb4dade67e80f34b (diff)
Backport of 4084-epics-username-autocomplete
Diffstat (limited to 'app/models/group.rb')
-rw-r--r--app/models/group.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/models/group.rb b/app/models/group.rb
index 9b42bbf99be..66b4398858e 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -238,6 +238,13 @@ class Group < Namespace
.where(source_id: self_and_descendants.reorder(nil).select(:id))
end
+ # Returns all members that are part of the group, it's subgroups, and ancestor groups
+ def direct_and_indirect_members
+ GroupMember
+ .active_without_invites_and_requests
+ .where(source_id: self_and_hierarchy.reorder(nil).select(:id))
+ end
+
def users_with_parents
User
.where(id: members_with_parents.select(:user_id))
@@ -250,6 +257,30 @@ class Group < Namespace
.reorder(nil)
end
+ # Returns all users that are members of the group because:
+ # 1. They belong to the group
+ # 2. They belong to a project that belongs to the group
+ # 3. They belong to a sub-group or project in such sub-group
+ # 4. They belong to an ancestor group
+ def direct_and_indirect_users
+ union = Gitlab::SQL::Union.new([
+ User
+ .where(id: direct_and_indirect_members.select(:user_id))
+ .reorder(nil),
+ project_users_with_descendants
+ ])
+
+ User.from("(#{union.to_sql}) #{User.table_name}")
+ end
+
+ # Returns all users that are members of projects
+ # belonging to the current group or sub-groups
+ def project_users_with_descendants
+ User
+ .joins(projects: :group)
+ .where(namespaces: { id: self_and_descendants.select(:id) })
+ end
+
def max_member_access_for_user(user)
return GroupMember::OWNER if user.admin?