Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot
2022-08-06 21:11:04 +00:00
parent c01e203d86
commit 9a4d4b7b99
3 changed files with 79 additions and 5 deletions

View File

@ -0,0 +1,18 @@
# frozen_string_literal: true
module Groups
class GroupPathChangedEvent < ::Gitlab::EventStore::Event
def schema
{
'type' => 'object',
'properties' => {
'group_id' => { 'type' => 'integer' },
'root_namespace_id' => { 'type' => 'integer' },
'old_path' => { 'type' => 'string' },
'new_path' => { 'type' => 'string' }
},
'required' => %w[group_id root_namespace_id old_path new_path]
}
end
end
end

View File

@ -61,15 +61,18 @@ module Groups
end
def before_assignment_hook(group, params)
# overridden in EE
@full_path_before = group.full_path
@path_before = group.path
end
def renaming_group_with_container_registry_images?
renaming? && group.has_container_repository_including_subgroups?
end
def renaming?
new_path = params[:path]
new_path &&
new_path != group.path &&
group.has_container_repository_including_subgroups?
new_path && new_path != @path_before
end
def container_images_error
@ -83,6 +86,8 @@ module Groups
end
update_two_factor_requirement_for_subgroups
publish_event
end
def update_two_factor_requirement_for_subgroups
@ -154,6 +159,21 @@ module Groups
group.errors.add(:update_shared_runners, result[:message])
false
end
def publish_event
return unless renaming?
event = Groups::GroupPathChangedEvent.new(
data: {
group_id: group.id,
root_namespace_id: group.root_ancestor.id,
old_path: @full_path_before,
new_path: group.full_path
}
)
Gitlab::EventStore.publish(event)
end
end
end

View File

@ -339,8 +339,44 @@ RSpec.describe Groups::UpdateService do
end
end
context 'EventStore' do
let(:service) { described_class.new(group, user, **params) }
let(:root_group) { create(:group, path: 'root') }
let(:group) do
create(:group, parent: root_group, path: 'old-path').tap { |g| g.add_owner(user) }
end
context 'when changing a group path' do
let(:new_path) { SecureRandom.hex }
let(:params) { { path: new_path } }
it 'publishes a GroupPathChangedEvent' do
old_path = group.full_path
expect { service.execute }
.to publish_event(Groups::GroupPathChangedEvent)
.with(
group_id: group.id,
root_namespace_id: group.root_ancestor.id,
old_path: old_path,
new_path: "root/#{new_path}"
)
end
end
context 'when not changing a group path' do
let(:params) { { name: 'very-new-name' } }
it 'does not publish a GroupPathChangedEvent' do
expect { service.execute }
.not_to publish_event(Groups::GroupPathChangedEvent)
end
end
end
context 'rename group' do
let!(:service) { described_class.new(internal_group, user, path: SecureRandom.hex) }
let(:new_path) { SecureRandom.hex }
let!(:service) { described_class.new(internal_group, user, path: new_path) }
before do
internal_group.add_member(user, Gitlab::Access::MAINTAINER)