Commit 8b59867e authored by Nick Thomas's avatar Nick Thomas

Merge branch '228781-stop-subgroups-from-being-able-to-create-trials' into 'master'

Omit sub-groups from trial eligibility

See merge request gitlab-org/gitlab!40300
parents 69147041 47ccbc7c
...@@ -40,6 +40,7 @@ module EE ...@@ -40,6 +40,7 @@ module EE
scope :eligible_for_trial, -> do scope :eligible_for_trial, -> do
left_joins(gitlab_subscription: :hosted_plan) left_joins(gitlab_subscription: :hosted_plan)
.where( .where(
parent_id: nil,
gitlab_subscriptions: { trial: [nil, false], trial_ends_on: [nil] }, gitlab_subscriptions: { trial: [nil, false], trial_ends_on: [nil] },
plans: { name: [nil, *::Plan::PLANS_ELIGIBLE_FOR_TRIAL] } plans: { name: [nil, *::Plan::PLANS_ELIGIBLE_FOR_TRIAL] }
) )
......
---
title: Omit sub-groups from trial selection menu
merge_request: 40300
author:
type: fixed
...@@ -64,7 +64,7 @@ RSpec.describe EE::TrialHelper do ...@@ -64,7 +64,7 @@ RSpec.describe EE::TrialHelper do
let_it_be(:subgroup2) { create :group, parent: group2, name: 'Sub-Group 2' } let_it_be(:subgroup2) { create :group, parent: group2, name: 'Sub-Group 2' }
let_it_be(:subsubgroup1) { create :group, parent: subgroup2, name: 'Sub-Sub-Group 1' } let_it_be(:subsubgroup1) { create :group, parent: subgroup2, name: 'Sub-Sub-Group 1' }
let(:all_groups) { [group1, group2, subgroup1, subgroup2, subsubgroup1].map(&:id) } let(:top_level_groups) { [group1, group2].map(&:id) }
before do before do
group1.add_owner(user) group1.add_owner(user)
...@@ -72,7 +72,7 @@ RSpec.describe EE::TrialHelper do ...@@ -72,7 +72,7 @@ RSpec.describe EE::TrialHelper do
end end
context 'and none of the groups have subscriptions' do context 'and none of the groups have subscriptions' do
it { is_expected.to eq(all_groups) } it { is_expected.to eq(top_level_groups) }
end end
context 'and the groups have subscriptions' do context 'and the groups have subscriptions' do
...@@ -89,7 +89,7 @@ RSpec.describe EE::TrialHelper do ...@@ -89,7 +89,7 @@ RSpec.describe EE::TrialHelper do
let!(:subscription_subsubgroup1) { create :gitlab_subscription, :free, *subsubgroup1_traits, namespace: subsubgroup1 } let!(:subscription_subsubgroup1) { create :gitlab_subscription, :free, *subsubgroup1_traits, namespace: subsubgroup1 }
context 'and none of the groups have been trialed yet' do context 'and none of the groups have been trialed yet' do
it { is_expected.to eq(all_groups) } it { is_expected.to eq(top_level_groups) }
end end
context 'and some of the groups are being or have been trialed' do context 'and some of the groups are being or have been trialed' do
...@@ -97,9 +97,7 @@ RSpec.describe EE::TrialHelper do ...@@ -97,9 +97,7 @@ RSpec.describe EE::TrialHelper do
let(:subgroup1_traits) { :expired_trial } let(:subgroup1_traits) { :expired_trial }
let(:subgroup2_traits) { :active_trial } let(:subgroup2_traits) { :active_trial }
let(:some_groups) { [group2, subsubgroup1].map(&:id) } it { is_expected.to eq([group2.id]) }
it { is_expected.to eq(some_groups) }
end end
context 'and all of the groups are being or have been trialed' do context 'and all of the groups are being or have been trialed' do
......
...@@ -1058,6 +1058,7 @@ RSpec.describe User do ...@@ -1058,6 +1058,7 @@ RSpec.describe User do
let_it_be(:non_trialed_group_z) { create :group, name: 'Zeta', gitlab_subscription: create(:gitlab_subscription, :free) } let_it_be(:non_trialed_group_z) { create :group, name: 'Zeta', gitlab_subscription: create(:gitlab_subscription, :free) }
let_it_be(:non_trialed_group_a) { create :group, name: 'Alpha', gitlab_subscription: create(:gitlab_subscription, :free) } let_it_be(:non_trialed_group_a) { create :group, name: 'Alpha', gitlab_subscription: create(:gitlab_subscription, :free) }
let_it_be(:trialed_group) { create :group, name: 'Omitted', gitlab_subscription: create(:gitlab_subscription, :free, trial: true) } let_it_be(:trialed_group) { create :group, name: 'Omitted', gitlab_subscription: create(:gitlab_subscription, :free, trial: true) }
let_it_be(:non_trialed_subgroup) { create :group, name: 'Sub-group', gitlab_subscription: create(:gitlab_subscription, :free), parent: non_trialed_group_a }
subject { user.manageable_groups_eligible_for_trial } subject { user.manageable_groups_eligible_for_trial }
...@@ -1105,6 +1106,14 @@ RSpec.describe User do ...@@ -1105,6 +1106,14 @@ RSpec.describe User do
it { is_expected.to eq [non_trialed_group_a, non_trialed_group_z] } it { is_expected.to eq [non_trialed_group_a, non_trialed_group_z] }
end end
context 'owner of a top-level group with a sub-group' do
before do
non_trialed_group_a.add_owner(user)
end
it { is_expected.to eq [non_trialed_group_a] }
end
end end
describe '#active_for_authentication?' do describe '#active_for_authentication?' 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