diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /app/models/group.rb | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'app/models/group.rb')
-rw-r--r-- | app/models/group.rb | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/app/models/group.rb b/app/models/group.rb index f8cbaa2495c..c0f145997cc 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -20,8 +20,10 @@ class Group < Namespace UpdateSharedRunnersError = Class.new(StandardError) - has_many :group_members, -> { where(requested_at: nil) }, dependent: :destroy, as: :source # rubocop:disable Cop/ActiveRecordDependent + has_many :all_group_members, -> { where(requested_at: nil) }, dependent: :destroy, as: :source, class_name: 'GroupMember' # rubocop:disable Cop/ActiveRecordDependent + has_many :group_members, -> { where(requested_at: nil).where.not(members: { access_level: Gitlab::Access::MINIMAL_ACCESS }) }, dependent: :destroy, as: :source # rubocop:disable Cop/ActiveRecordDependent alias_method :members, :group_members + has_many :users, through: :group_members has_many :owners, -> { where(members: { access_level: Gitlab::Access::OWNER }) }, @@ -33,6 +35,7 @@ class Group < Namespace has_many :milestones has_many :iterations + has_many :services has_many :shared_group_links, foreign_key: :shared_with_group_id, class_name: 'GroupGroupLink' has_many :shared_with_group_links, foreign_key: :shared_group_id, class_name: 'GroupGroupLink' has_many :shared_groups, through: :shared_group_links, source: :shared_group @@ -395,6 +398,10 @@ class Group < Namespace ]) end + def users_count + members.count + end + # Returns all users that are members of projects # belonging to the current group or sub-groups def project_users_with_descendants @@ -403,10 +410,17 @@ class Group < Namespace .where(namespaces: { id: self_and_descendants.select(:id) }) end - def max_member_access_for_user(user) + # Return the highest access level for a user + # + # A special case is handled here when the user is a GitLab admin + # which implies it has "OWNER" access everywhere, but should not + # officially appear as a member of a group unless specifically added to it + # + # @param user [User] + # @param only_concrete_membership [Bool] whether require admin concrete membership status + def max_member_access_for_user(user, only_concrete_membership: false) return GroupMember::NO_ACCESS unless user - - return GroupMember::OWNER if user.admin? + return GroupMember::OWNER if user.admin? && !only_concrete_membership max_member_access = members_with_parents.where(user_id: user) .reorder(access_level: :desc) @@ -630,6 +644,7 @@ class Group < Namespace .where(group_member_table[:requested_at].eq(nil)) .where(group_member_table[:source_id].eq(group_group_link_table[:shared_with_group_id])) .where(group_member_table[:source_type].eq('Namespace')) + .non_minimal_access end def smallest_value_arel(args, column_alias) |