Commit 8c965c97 authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'vij-fix-user-ci-mins-tranfers' into 'master'

Allow additional minute transfer for Users

See merge request gitlab-org/gitlab!69556
parents 8a2e578e d4808220
...@@ -51,7 +51,7 @@ module Ci ...@@ -51,7 +51,7 @@ module Ci
end end
def validate_owners! def validate_owners!
shared_ids = namespace.owner_ids & target.owner_ids shared_ids = owner_ids_for(namespace) & owner_ids_for(target)
raise ChangeNamespaceError, 'Both namespaces must share the same owner' unless shared_ids.any? raise ChangeNamespaceError, 'Both namespaces must share the same owner' unless shared_ids.any?
end end
...@@ -60,6 +60,10 @@ module Ci ...@@ -60,6 +60,10 @@ module Ci
::Ci::Minutes::RefreshCachedDataService.new(namespace).execute ::Ci::Minutes::RefreshCachedDataService.new(namespace).execute
::Ci::Minutes::RefreshCachedDataService.new(target).execute ::Ci::Minutes::RefreshCachedDataService.new(target).execute
end end
def owner_ids_for(namespace)
namespace.user? ? Array(namespace.owner_id) : namespace.owner_ids
end
end end
end end
end end
......
...@@ -5,9 +5,8 @@ require 'spec_helper' ...@@ -5,9 +5,8 @@ require 'spec_helper'
RSpec.describe Ci::Minutes::AdditionalPacks::ChangeNamespaceService do RSpec.describe Ci::Minutes::AdditionalPacks::ChangeNamespaceService do
describe '#execute' do describe '#execute' do
let_it_be(:namespace) { create(:group) } let_it_be(:namespace) { create(:group) }
let_it_be(:target) { create(:group) } let_it_be(:target, reload: true) { create(:group) }
let_it_be(:subgroup) { build(:group, :nested) } let_it_be(:subgroup) { build(:group, :nested) }
let_it_be(:existing_packs) { create_list(:ci_minutes_additional_pack, 5, namespace: namespace) }
let_it_be(:admin) { create(:user, :admin) } let_it_be(:admin) { create(:user, :admin) }
let_it_be(:non_admin) { build(:user) } let_it_be(:non_admin) { build(:user) }
...@@ -24,32 +23,29 @@ RSpec.describe Ci::Minutes::AdditionalPacks::ChangeNamespaceService do ...@@ -24,32 +23,29 @@ RSpec.describe Ci::Minutes::AdditionalPacks::ChangeNamespaceService do
context 'with an admin user' do context 'with an admin user' do
let(:user) { admin } let(:user) { admin }
context 'with valid namespace and target namespace' do shared_examples 'namespace change' do
before do context 'when updating is successful' do
namespace.add_owner(admin) it 'moves all existing packs to the target namespace', :aggregate_failures do
target.add_owner(admin) expect(target.ci_minutes_additional_packs).to be_empty
end
it 'moves all existing packs to the target namespace', :aggregate_failures do change_namespace
expect(target.ci_minutes_additional_packs).to be_empty
change_namespace expect(target.ci_minutes_additional_packs).to match_array(existing_packs)
expect(existing_packs.first.reload.namespace).to eq target
expect(change_namespace[:status]).to eq :success
end
expect(target.ci_minutes_additional_packs).to match_array(existing_packs) it 'kicks off refresh ci minutes service for namespace and target' do
expect(existing_packs.first.reload.namespace).to eq target expect_next_instance_of(::Ci::Minutes::RefreshCachedDataService, namespace) do |instance|
expect(change_namespace[:status]).to eq :success expect(instance).to receive(:execute)
end end
it 'kicks off refresh ci minutes service for namespace and target' do expect_next_instance_of(::Ci::Minutes::RefreshCachedDataService, target) do |instance|
expect_next_instance_of(::Ci::Minutes::RefreshCachedDataService, namespace) do |instance| expect(instance).to receive(:execute)
expect(instance).to receive(:execute) end
end
expect_next_instance_of(::Ci::Minutes::RefreshCachedDataService, target) do |instance| change_namespace
expect(instance).to receive(:execute)
end end
change_namespace
end end
context 'when updating packs fails' do context 'when updating packs fails' do
...@@ -79,6 +75,39 @@ RSpec.describe Ci::Minutes::AdditionalPacks::ChangeNamespaceService do ...@@ -79,6 +75,39 @@ RSpec.describe Ci::Minutes::AdditionalPacks::ChangeNamespaceService do
end end
end end
context 'with valid namespace and target namespace' do
let!(:existing_packs) { create_list(:ci_minutes_additional_pack, 5, namespace: namespace) }
context 'when both namespaces are groups' do
before do
namespace.add_owner(admin)
target.add_owner(admin)
end
include_examples 'namespace change'
end
context 'when a namespace is a kind of user' do
let_it_be(:namespace) { admin.namespace }
before do
target.add_owner(admin)
end
include_examples 'namespace change'
end
context 'when a target is a kind of user' do
let(:target) { admin.namespace }
before do
namespace.add_owner(admin)
end
include_examples 'namespace change'
end
end
context 'when the namespace is not provided' do context 'when the namespace is not provided' do
let(:namespace) { nil } let(:namespace) { nil }
......
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