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
end
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?
end
......@@ -60,6 +60,10 @@ module Ci
::Ci::Minutes::RefreshCachedDataService.new(namespace).execute
::Ci::Minutes::RefreshCachedDataService.new(target).execute
end
def owner_ids_for(namespace)
namespace.user? ? Array(namespace.owner_id) : namespace.owner_ids
end
end
end
end
......
......@@ -5,9 +5,8 @@ require 'spec_helper'
RSpec.describe Ci::Minutes::AdditionalPacks::ChangeNamespaceService do
describe '#execute' do
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(:existing_packs) { create_list(:ci_minutes_additional_pack, 5, namespace: namespace) }
let_it_be(:admin) { create(:user, :admin) }
let_it_be(:non_admin) { build(:user) }
......@@ -24,32 +23,29 @@ RSpec.describe Ci::Minutes::AdditionalPacks::ChangeNamespaceService do
context 'with an admin user' do
let(:user) { admin }
context 'with valid namespace and target namespace' do
before do
namespace.add_owner(admin)
target.add_owner(admin)
end
shared_examples 'namespace change' do
context 'when updating is successful' do
it 'moves all existing packs to the target namespace', :aggregate_failures do
expect(target.ci_minutes_additional_packs).to be_empty
it 'moves all existing packs to the target namespace', :aggregate_failures do
expect(target.ci_minutes_additional_packs).to be_empty
change_namespace
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)
expect(existing_packs.first.reload.namespace).to eq target
expect(change_namespace[:status]).to eq :success
end
it 'kicks off refresh ci minutes service for namespace and target' do
expect_next_instance_of(::Ci::Minutes::RefreshCachedDataService, namespace) do |instance|
expect(instance).to receive(:execute)
end
it 'kicks off refresh ci minutes service for namespace and target' do
expect_next_instance_of(::Ci::Minutes::RefreshCachedDataService, namespace) do |instance|
expect(instance).to receive(:execute)
end
expect_next_instance_of(::Ci::Minutes::RefreshCachedDataService, target) do |instance|
expect(instance).to receive(:execute)
end
expect_next_instance_of(::Ci::Minutes::RefreshCachedDataService, target) do |instance|
expect(instance).to receive(:execute)
change_namespace
end
change_namespace
end
context 'when updating packs fails' do
......@@ -79,6 +75,39 @@ RSpec.describe Ci::Minutes::AdditionalPacks::ChangeNamespaceService do
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
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