diff options
author | Mario de la Ossa <mariodelaossa@gmail.com> | 2018-04-26 13:53:13 -0600 |
---|---|---|
committer | Mario de la Ossa <mariodelaossa@gmail.com> | 2018-05-04 11:33:09 -0600 |
commit | 5c2078838bb9de710f9025513c4b6ec664bba313 (patch) | |
tree | 338656dae97b6c6687e6794b583b0ae431aa5e2f /app/models/group.rb | |
parent | e71351d4f463715fccd80ddbcb4dade67e80f34b (diff) | |
download | gitlab-ce-5c2078838bb9de710f9025513c4b6ec664bba313.tar.gz |
Backport of 4084-epics-username-autocomplete
Diffstat (limited to 'app/models/group.rb')
-rw-r--r-- | app/models/group.rb | 31 |
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? |