diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-05-07 08:26:44 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-05-07 08:26:44 +0000 |
commit | 67c9f822dd60ef55323082cd0b17ccd6108a24c6 (patch) | |
tree | 716d434e45d4b43161e889d99c37b31415e22049 /app/models/group.rb | |
parent | 6a052a14e938ef073977afd808dd12a801f44369 (diff) | |
parent | cfa92112d189dce1028bce7145a5cbe609c389a8 (diff) | |
download | gitlab-ce-67c9f822dd60ef55323082cd0b17ccd6108a24c6.tar.gz |
Merge branch '4084-epics-username-autocomplete-ce' into 'master'
Backport CE changes from "autocomplete usernames in Epic comments/description"
See merge request gitlab-org/gitlab-ce!18605
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 f493836a92e..cefca316399 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -241,6 +241,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)) @@ -253,6 +260,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? |