summaryrefslogtreecommitdiff
path: root/app/models/group.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/group.rb')
-rw-r--r--app/models/group.rb64
1 files changed, 52 insertions, 12 deletions
diff --git a/app/models/group.rb b/app/models/group.rb
index 1eaa4499eb5..9f8a9996f31 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -33,7 +33,6 @@ class Group < Namespace
has_many :members_and_requesters, as: :source, class_name: 'GroupMember'
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'
@@ -341,6 +340,13 @@ class Group < Namespace
has_owner?(user) && members_with_parents.owners.size == 1
end
+ def last_blocked_owner?(user)
+ return false if members_with_parents.owners.any?
+
+ blocked_owners = members.blocked.where(access_level: Gitlab::Access::OWNER)
+ blocked_owners.size == 1 && blocked_owners.exists?(user_id: user)
+ end
+
def ldap_synced?
false
end
@@ -364,15 +370,30 @@ class Group < Namespace
# rubocop: enable CodeReuse/ServiceClass
# rubocop: disable CodeReuse/ServiceClass
- def refresh_members_authorized_projects(blocking: true, priority: UserProjectAccessChangedService::HIGH_PRIORITY)
+ def refresh_members_authorized_projects(
+ blocking: true,
+ priority: UserProjectAccessChangedService::HIGH_PRIORITY,
+ direct_members_only: false
+ )
+
+ user_ids = if direct_members_only
+ users_ids_of_direct_members
+ else
+ user_ids_for_project_authorizations
+ end
+
UserProjectAccessChangedService
- .new(user_ids_for_project_authorizations)
+ .new(user_ids)
.execute(blocking: blocking, priority: priority)
end
# rubocop: enable CodeReuse/ServiceClass
+ def users_ids_of_direct_members
+ direct_members.pluck(:user_id)
+ end
+
def user_ids_for_project_authorizations
- members_with_parents.pluck(:user_id)
+ members_with_parents.pluck(Arel.sql('DISTINCT members.user_id'))
end
def self_and_ancestors_ids
@@ -381,6 +402,12 @@ class Group < Namespace
end
end
+ def direct_members
+ GroupMember.active_without_invites_and_requests
+ .non_minimal_access
+ .where(source_id: id)
+ end
+
def members_with_parents
# Avoids an unnecessary SELECT when the group has no parents
source_ids =
@@ -485,7 +512,7 @@ class Group < Namespace
# @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? && !only_concrete_membership
+ return GroupMember::OWNER if user.can_admin_all_resources? && !only_concrete_membership
max_member_access = members_with_parents.where(user_id: user)
.reorder(access_level: :desc)
@@ -505,15 +532,11 @@ class Group < Namespace
}
end
- def ci_variables_for(ref, project)
- cache_key = "ci_variables_for:group:#{self&.id}:project:#{project&.id}:ref:#{ref}"
+ def ci_variables_for(ref, project, environment: nil)
+ cache_key = "ci_variables_for:group:#{self&.id}:project:#{project&.id}:ref:#{ref}:environment:#{environment}"
::Gitlab::SafeRequestStore.fetch(cache_key) do
- list_of_ids = [self] + ancestors
- variables = Ci::GroupVariable.where(group: list_of_ids)
- variables = variables.unprotected unless project.protected_for?(ref)
- variables = variables.group_by(&:group_id)
- list_of_ids.reverse.flat_map { |group| variables[group.id] }.compact
+ uncached_ci_variables_for(ref, project, environment: environment)
end
end
@@ -755,6 +778,23 @@ class Group < Namespace
def enable_shared_runners!
update!(shared_runners_enabled: true)
end
+
+ def uncached_ci_variables_for(ref, project, environment: nil)
+ list_of_ids = [self] + ancestors
+ variables = Ci::GroupVariable.where(group: list_of_ids)
+ variables = variables.unprotected unless project.protected_for?(ref)
+
+ if Feature.enabled?(:scoped_group_variables, self, default_enabled: :yaml)
+ variables = if environment
+ variables.on_environment(environment)
+ else
+ variables.where(environment_scope: '*')
+ end
+ end
+
+ variables = variables.group_by(&:group_id)
+ list_of_ids.reverse.flat_map { |group| variables[group.id] }.compact
+ end
end
Group.prepend_if_ee('EE::Group')