Add latest changes from gitlab-org/security/gitlab@16-2-stable-ee

This commit is contained in:
GitLab Bot 2023-09-27 22:36:23 +00:00
parent 190831bff0
commit 7b43295cef
8 changed files with 152 additions and 37 deletions

View File

@ -35,7 +35,7 @@ module Groups
user_ids_for_project_authorizations_refresh = obtain_user_ids_for_project_authorizations_refresh
destroy_group_bots
destroy_associated_users
group.destroy
@ -82,9 +82,9 @@ module Groups
end
# rubocop:disable CodeReuse/ActiveRecord
def destroy_group_bots
bot_ids = group.members_and_requesters.joins(:user).merge(User.project_bot).pluck(:user_id)
def destroy_associated_users
current_user_id = current_user.id
bot_ids = users_to_destroy
group.run_after_commit do
bot_ids.each do |user_id|
@ -94,6 +94,12 @@ module Groups
end
# rubocop:enable CodeReuse/ActiveRecord
# rubocop:disable CodeReuse/ActiveRecord
def users_to_destroy
group.members_and_requesters.joins(:user).merge(User.project_bot).pluck(:user_id)
end
# rubocop:enable CodeReuse/ActiveRecord
def publish_event
event = Groups::GroupDeletedEvent.new(
data: {

View File

@ -174,7 +174,6 @@ included_attributes:
- :cron_timezone
- :description
- :next_run_at
- :owner_id
- :project_id
- :ref
- :updated_at
@ -378,7 +377,6 @@ included_attributes:
- :updated_by_id
- :merge_error
- :merge_params
- :merge_when_pipeline_succeeds
- :merge_user_id
- :merge_commit_sha
- :squash_commit_sha

View File

@ -99,6 +99,7 @@ module Gitlab
when :'ProtectedBranch::PushAccessLevel' then setup_protected_branch_access_level
when :ApprovalProjectRulesProtectedBranch then setup_merge_approval_protected_branch
when :releases then setup_release
when :merge_requests, :MergeRequest, :merge_request then setup_merge_request
end
update_project_references
@ -149,22 +150,30 @@ module Gitlab
end
def setup_pipeline
@relation_hash['status'] = transform_status(@relation_hash['status'])
@relation_hash.fetch('stages', []).each do |stage|
stage.status = transform_status(stage.status)
# old export files have statuses
stage.statuses.each do |status|
status.pipeline = imported_object
stage.statuses.each do |job|
job.status = transform_status(job.status)
job.pipeline = imported_object
end
stage.builds.each do |status|
status.pipeline = imported_object
stage.builds.each do |job|
job.status = transform_status(job.status)
job.pipeline = imported_object
end
stage.bridges.each do |status|
status.pipeline = imported_object
stage.bridges.each do |job|
job.status = transform_status(job.status)
job.pipeline = imported_object
end
stage.generic_commit_statuses.each do |status|
status.pipeline = imported_object
stage.generic_commit_statuses.each do |job|
job.status = transform_status(job.status)
job.pipeline = imported_object
end
end
end
@ -188,6 +197,10 @@ module Gitlab
@relation_hash['active'] = false
end
def setup_merge_request
@relation_hash['merge_when_pipeline_succeeds'] = false
end
def setup_protected_branch_access_level
return if root_group_owner?
return if @relation_hash['access_level'] == Gitlab::Access::NO_ACCESS
@ -227,6 +240,12 @@ module Gitlab
@relation_name == :'Ci::Trigger' && @relation_hash['owner_id'].nil?
end
def transform_status(status)
return 'canceled' if ::Ci::HasStatus::COMPLETED_STATUSES.exclude?(status)
status
end
def preload_keys(object, references, value)
return object unless value

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -172,6 +172,10 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_
it 'has preloaded target project' do
expect(created_object.target_project).to equal(project)
end
it 'has MWPS set to false' do
expect(created_object.merge_when_pipeline_succeeds).to eq(false)
end
end
context 'issue object' do
@ -297,6 +301,38 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_
end
end
context 'pipeline setup' do
let(:relation_sym) { :ci_pipelines }
let(:relation_hash) do
{
"id" => 1,
"status" => status
}
end
subject { created_object }
::Ci::HasStatus::COMPLETED_STATUSES.each do |status|
context "when relation_hash has a completed status of #{status}}" do
let(:status) { status }
it "does not change the created object status" do
expect(created_object.status).to eq(status)
end
end
end
::Ci::HasStatus::CANCELABLE_STATUSES.each do |status|
context "when relation_hash has cancelable status of #{status}}" do
let(:status) { status }
it "sets the created object status to canceled" do
expect(created_object.status).to eq('canceled')
end
end
end
end
context 'pipeline_schedule' do
let(:relation_sym) { :pipeline_schedules }
let(:relation_hash) do

View File

@ -135,6 +135,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer, feature_category: :i
expect(pipeline.merge_request.id).to be > 0
expect(pipeline.merge_request.target_branch).to eq('feature')
expect(pipeline.merge_request.source_branch).to eq('feature_conflict')
expect(pipeline.merge_request.merge_when_pipeline_succeeds).to eq(false)
end
it 'restores pipelines based on ascending id order' do
@ -146,6 +147,9 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer, feature_category: :i
5f923865dde3436854e9ceb9cdb7815618d4e849
d2d430676773caa88cdaf7c55944073b2fd5561a
2ea1f3dec713d940208fb5ce4a38765ecb5d3f73
1b6c4f044c63217d1ed06e514c84d22871bed912
ded178474ef2ba1f80a9964ba15da3ddb3cf664b
fd459e5c514d70dc525c5e70990ca5e0debb3105
]
project = Project.find_by_path('project')
@ -297,6 +301,12 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer, feature_category: :i
end
end
it 'sets MWPS to false for all merge requests' do
MergeRequest.find_each do |merge_request|
expect(merge_request.merge_when_pipeline_succeeds).to eq(false)
end
end
it 'has multiple merge request assignees' do
expect(MergeRequest.find_by(title: 'MR1').assignees).to contain_exactly(@user, *@existing_members)
expect(MergeRequest.find_by(title: 'MR2').assignees).to be_empty
@ -545,9 +555,9 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer, feature_category: :i
end
it 'has the correct number of pipelines and statuses' do
expect(@project.ci_pipelines.size).to eq(7)
expect(@project.ci_pipelines.size).to eq(10)
@project.ci_pipelines.order(:id).zip([2, 0, 2, 3, 2, 2, 0])
@project.ci_pipelines.order(:id).zip([2, 0, 2, 3, 2, 8, 0, 0, 0, 0])
.each do |(pipeline, expected_status_size)|
expect(pipeline.statuses.size).to eq(expected_status_size)
end
@ -555,28 +565,58 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer, feature_category: :i
end
context 'when restoring hierarchy of pipeline, stages and jobs' do
it 'restores pipelines' do
expect(Ci::Pipeline.all.count).to be 7
context 'pipelines' do
it 'restores pipelines' do
expect(Ci::Pipeline.all.count).to be 10
end
it 'marks cancelable pipelines as canceled' do
expect(Ci::Pipeline.where(status: 'canceled').count).to eq 7
end
end
it 'restores pipeline stages' do
expect(Ci::Stage.all.count).to be 6
context 'stages' do
it 'restores pipeline stages' do
expect(Ci::Stage.all.count).to be 7
end
it 'marks cancelable stages as canceled' do
expect(Ci::Stage.where(status: 'canceled').count).to eq 6
end
it 'correctly restores association between stage and a pipeline' do
expect(Ci::Stage.all).to all(have_attributes(pipeline_id: a_value > 0))
end
end
it 'correctly restores association between stage and a pipeline' do
expect(Ci::Stage.all).to all(have_attributes(pipeline_id: a_value > 0))
context 'builds' do
it 'restores builds' do
expect(Ci::Build.all.count).to be 7
end
it 'marks cancelable builds as canceled' do
expect(Ci::Build.where(status: 'canceled').count).to eq 3
end
end
it 'restores builds' do
expect(Ci::Build.all.count).to be 7
context 'bridges' do
it 'restores bridges' do
expect(Ci::Bridge.all.count).to be 5
end
it 'marks cancelable bridges as canceled' do
expect(Ci::Bridge.where(status: 'canceled').count).to eq 4
end
end
it 'restores bridges' do
expect(Ci::Bridge.all.count).to be 1
end
context 'generic commit statuses' do
it 'restores generic commit statuses' do
expect(GenericCommitStatus.all.count).to be 3
end
it 'restores generic commit statuses' do
expect(GenericCommitStatus.all.count).to be 1
it 'marks cancelable generic commit statuses as canceled' do
expect(GenericCommitStatus.where(status: 'canceled').count).to eq 2
end
end
it 'correctly restores association between a stage and a job' do

View File

@ -127,6 +127,10 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver, :with_license, feature_
expect(system_notes.size).to eq(1)
expect(system_notes.first['note']).to eq('merged')
end
it 'has no merge_when_pipeline_succeeds' do
expect(subject.first['merge_when_pipeline_succeeds']).to be_nil
end
end
context 'with snippets' do
@ -301,6 +305,14 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver, :with_license, feature_
it { is_expected.not_to be_empty }
end
context 'with pipeline schedules' do
let(:relation_name) { :pipeline_schedules }
it 'has no owner_id' do
expect(subject.first['owner_id']).to be_nil
end
end
end
describe '#saves project tree' do
@ -535,6 +547,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver, :with_license, feature_
design = create(:design, :with_file, versions_count: 2, issue: issue)
create(:diff_note_on_design, noteable: design, project: project, author: user)
create(:ci_pipeline_schedule, project: project, owner: user)
project
end