Commit cf7bfda0 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '25970-mirror-pull-for-archived-projects' into 'master'

Disable mirror importing when the project is archived

See merge request gitlab-org/gitlab!24029
parents 580c2829 ea87a772
---
title: Disable pull mirror importing for archived projects
merge_request: 24029
author:
type: fixed
......@@ -97,6 +97,7 @@ module EE
def mirror_update_due?
return false unless project.mirror_with_content?
return false if project.archived?
return false if hard_failed?
return false if updating_mirror?
......
......@@ -22,7 +22,7 @@
= clipboard_button(text: ssh_public_key, class: 'btn btn-default rspec-copy-ssh-public-key', title: _('Copy SSH public key'), qa_selector: 'copy_public_key_button')
- if import_state.mirror_update_due? || import_state.updating_mirror?
%button.btn.disabled{ type: 'button', data: { container: 'body', toggle: 'tooltip', qa_selector: 'updating_button' }, title: _('Updating') }= icon("refresh spin")
- else
- elsif !@project.archived?
= link_to update_now_project_mirror_path(@project), method: :post, class: 'btn js-force-update-mirror', data: { container: 'body', toggle: 'tooltip', qa_selector: 'update_now_button' }, title: _('Update now') do
= icon("refresh")
%button.js-delete-mirror.js-delete-pull-mirror.btn.btn-danger{ type: 'button', data: { toggle: 'tooltip', container: 'body' }, title: _('Remove') }= icon('trash-o')
......@@ -93,6 +93,7 @@ class UpdateAllMirrorsWorker
# rubocop: disable CodeReuse/ActiveRecord
def pull_mirrors_batch(freeze_at:, batch_size:, offset_at: nil)
relation = Project
.non_archived
.mirrors_to_sync(freeze_at)
.reorder('import_state.next_execution_timestamp')
.limit(batch_size)
......
......@@ -230,6 +230,24 @@ describe ProjectImportState, type: :model do
end
end
context 'when the project is archived' do
let(:import_state) do
create(:import_state,
:finished,
:mirror,
:repository,
next_execution_timestamp: Time.now - 2.minutes)
end
before do
import_state.project.update!(archived: true)
end
it 'returns false' do
expect(import_state.mirror_update_due?).to be false
end
end
context 'when mirror has no content' do
it 'returns false' do
import_state = create(:import_state, :finished, :mirror)
......
......@@ -182,6 +182,16 @@ describe UpdateAllMirrorsWorker do
schedule_mirrors!(capacity: 4)
end
it "does not schedule a mirror of an archived project" do
licensed_project1.update!(archived: true)
schedule_mirrors!(capacity: 4)
expect_import_scheduled(licensed_project2, licensed_project3)
expect_import_not_scheduled(licensed_project1)
expect_import_not_scheduled(*unlicensed_projects)
end
end
context 'when capacity is exacly sufficient' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment