diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /app/finders/groups | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'app/finders/groups')
-rw-r--r-- | app/finders/groups/accepting_group_transfers_finder.rb | 69 | ||||
-rw-r--r-- | app/finders/groups/accepting_project_transfers_finder.rb | 4 | ||||
-rw-r--r-- | app/finders/groups/base.rb | 17 | ||||
-rw-r--r-- | app/finders/groups/user_groups_finder.rb | 12 |
4 files changed, 87 insertions, 15 deletions
diff --git a/app/finders/groups/accepting_group_transfers_finder.rb b/app/finders/groups/accepting_group_transfers_finder.rb new file mode 100644 index 00000000000..df67f940d20 --- /dev/null +++ b/app/finders/groups/accepting_group_transfers_finder.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +module Groups + class AcceptingGroupTransfersFinder < Base + include Gitlab::Utils::StrongMemoize + + def initialize(current_user, group_to_be_transferred, params = {}) + @current_user = current_user + @group_to_be_transferred = group_to_be_transferred + @params = params + end + + def execute + return Group.none unless can_transfer_group? + + items = if Feature.enabled?(:include_groups_from_group_shares_in_group_transfer_locations) + find_all_groups + else + find_groups + end + + items = by_search(items) + + sort(items) + end + + private + + attr_reader :current_user, :group_to_be_transferred, :params + + def find_groups + GroupsFinder.new( # rubocop: disable CodeReuse/Finder + current_user, + min_access_level: Gitlab::Access::OWNER, + exclude_group_ids: exclude_groups + ).execute.without_order + end + + def find_all_groups + ::Namespace.from_union( + [ + find_groups, + groups_originating_from_group_shares_with_owner_access + ] + ) + end + + def groups_originating_from_group_shares_with_owner_access + GroupGroupLink + .with_owner_access + .groups_accessible_via( + current_user.owned_groups.select(:id) + ).id_not_in(exclude_groups) + end + + def exclude_groups + strong_memoize(:exclude_groups) do + exclude_groups = group_to_be_transferred.self_and_descendants.pluck_primary_key + exclude_groups << group_to_be_transferred.parent_id if group_to_be_transferred.parent_id + + exclude_groups + end + end + + def can_transfer_group? + Ability.allowed?(current_user, :admin_group, group_to_be_transferred) + end + end +end diff --git a/app/finders/groups/accepting_project_transfers_finder.rb b/app/finders/groups/accepting_project_transfers_finder.rb index 09d3c430641..a3f58a78eca 100644 --- a/app/finders/groups/accepting_project_transfers_finder.rb +++ b/app/finders/groups/accepting_project_transfers_finder.rb @@ -7,10 +7,6 @@ module Groups end def execute - if Feature.disabled?(:include_groups_from_group_shares_in_project_transfer_locations) - return current_user.manageable_groups - end - groups_accepting_project_transfers = [ current_user.manageable_groups, diff --git a/app/finders/groups/base.rb b/app/finders/groups/base.rb new file mode 100644 index 00000000000..d7f56b1a7a6 --- /dev/null +++ b/app/finders/groups/base.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Groups + class Base + private + + def sort(items) + items.order(Group.arel_table[:path].asc, Group.arel_table[:id].asc) # rubocop: disable CodeReuse/ActiveRecord + end + + def by_search(items) + return items if params[:search].blank? + + items.search(params[:search], include_parents: true) + end + end +end diff --git a/app/finders/groups/user_groups_finder.rb b/app/finders/groups/user_groups_finder.rb index bda8b7cc1e0..b58c1323b1f 100644 --- a/app/finders/groups/user_groups_finder.rb +++ b/app/finders/groups/user_groups_finder.rb @@ -13,7 +13,7 @@ # # Initially created to filter user groups and descendants where the user can create projects module Groups - class UserGroupsFinder + class UserGroupsFinder < Base def initialize(current_user, target_user, params = {}) @current_user = current_user @target_user = target_user @@ -34,16 +34,6 @@ module Groups attr_reader :current_user, :target_user, :params - def sort(items) - items.order(Group.arel_table[:path].asc, Group.arel_table[:id].asc) # rubocop: disable CodeReuse/ActiveRecord - end - - def by_search(items) - return items if params[:search].blank? - - items.search(params[:search], include_parents: true) - end - def by_permission_scope if permission_scope_create_projects? target_user.manageable_groups(include_groups_with_developer_maintainer_access: true) |