Commit 3f7a5f29 authored by Lee Tickett's avatar Lee Tickett Committed by Markus Koller

Removed legacy date check from groups_with_templates_finder

parent ad256ac4
# frozen_string_literal: true
class GroupsWithTemplatesFinder
# We need to provide grace period for users who are now using group_project_template
# feature in free groups.
CUT_OFF_DATE = Date.parse('2019/05/22') + 3.months
def initialize(group_id = nil)
@group_id = group_id
end
def execute
if ::Gitlab::CurrentSettings.should_check_namespace_plan? && Time.zone.now > CUT_OFF_DATE
if ::Gitlab::CurrentSettings.should_check_namespace_plan?
groups = extended_group_search
simple_group_search(groups)
else
......
......@@ -217,8 +217,7 @@ module EE
end
def group_project_template_available?
feature_available?(:group_project_templates) ||
(custom_project_templates_group_id? && Time.zone.now <= GroupsWithTemplatesFinder::CUT_OFF_DATE)
feature_available?(:group_project_templates)
end
def actual_size_limit
......
......@@ -373,35 +373,9 @@ RSpec.describe 'New project' do
let(:template_number) { 2 }
end
end
context 'when creating project with templates' do
let(:url) { new_project_path(namespace_id: group1.id) }
before do
allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { true }
create(:gitlab_subscription, :bronze, namespace: group1)
end
around do |example|
Timecop.freeze(GroupsWithTemplatesFinder::CUT_OFF_DATE - 1.day) do
example.run
end
end
it 'show Group tab in Templates section' do
visit url
click_link 'Create from template'
expect(page).to have_css('.custom-group-project-templates-tab')
end
it_behaves_like 'group templates displayed' do
let(:template_number) { 2 }
end
end
end
context 'when creating project with templates after grace period' do
context 'when not in proper plan' do
let(:url) { new_project_path(namespace_id: group1.id) }
before do
......@@ -409,12 +383,6 @@ RSpec.describe 'New project' do
create(:gitlab_subscription, :bronze, namespace: group1)
end
around do |example|
Timecop.freeze(GroupsWithTemplatesFinder::CUT_OFF_DATE + 1.day) do
example.run
end
end
it 'show Group tab in Templates section' do
visit url
click_link 'Create from template'
......
......@@ -36,16 +36,8 @@ RSpec.describe GroupsWithTemplatesFinder do
allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { true }
end
it 'returns all groups before cut-off date' do
Timecop.freeze(described_class::CUT_OFF_DATE - 1.day) do
expect(described_class.new.execute).to contain_exactly(group_1, group_2, group_3)
end
end
it 'returns groups on gold/silver plan after cut-off date' do
Timecop.freeze(described_class::CUT_OFF_DATE + 1.day) do
expect(described_class.new.execute).to contain_exactly(group_1, group_2)
end
it 'returns groups on gold/silver plan' do
expect(described_class.new.execute).to contain_exactly(group_1, group_2)
end
context 'with subgroup with template' do
......@@ -54,10 +46,8 @@ RSpec.describe GroupsWithTemplatesFinder do
create(:project, namespace: subgroup_5)
end
it 'returns groups on gold/silver plan after cut-off date' do
Timecop.freeze(described_class::CUT_OFF_DATE + 1.day) do
expect(described_class.new.execute).to contain_exactly(group_1, group_2, subgroup_4)
end
it 'returns groups on gold/silver plan' do
expect(described_class.new.execute).to contain_exactly(group_1, group_2, subgroup_4)
end
end
end
......@@ -84,16 +74,8 @@ RSpec.describe GroupsWithTemplatesFinder do
allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { true }
end
it 'returns given group with it descendants before cut-off date' do
Timecop.freeze(described_class::CUT_OFF_DATE - 1.day) do
expect(described_class.new(group_3.id).execute).to contain_exactly(group_3)
end
end
it 'does not return the group after the cut-off date' do
Timecop.freeze(described_class::CUT_OFF_DATE + 1.day) do
expect(described_class.new(group_3.id).execute).to be_empty
end
it 'does not return the group' do
expect(described_class.new(group_3.id).execute).to be_empty
end
context 'with subgroup with template' do
......@@ -103,15 +85,11 @@ RSpec.describe GroupsWithTemplatesFinder do
end
it 'returns only chosen group' do
Timecop.freeze(described_class::CUT_OFF_DATE + 1.day) do
expect(described_class.new(group_1.id).execute).to contain_exactly(group_1)
end
expect(described_class.new(group_1.id).execute).to contain_exactly(group_1)
end
it 'returns only chosen subgroup' do
Timecop.freeze(described_class::CUT_OFF_DATE + 1.day) do
expect(described_class.new(subgroup_4.id).execute).to contain_exactly(group_1, subgroup_4)
end
expect(described_class.new(subgroup_4.id).execute).to contain_exactly(group_1, subgroup_4)
end
end
end
......
......@@ -554,22 +554,11 @@ RSpec.describe Group do
is_expected.to be true
end
it 'returns true for groups with group template already set within grace period' do
it 'returns false for groups with group template already set but not in proper plan' do
group.update!(custom_project_templates_group_id: create(:group, parent: group).id)
group.reload
Timecop.freeze(GroupsWithTemplatesFinder::CUT_OFF_DATE - 1.day) do
is_expected.to be true
end
end
it 'returns false for groups with group template already set after grace period' do
group.update!(custom_project_templates_group_id: create(:group, parent: group).id)
group.reload
Timecop.freeze(GroupsWithTemplatesFinder::CUT_OFF_DATE + 1.day) do
is_expected.to be false
end
is_expected.to be false
end
end
......
......@@ -453,12 +453,10 @@ describe User do
end
it 'returns groups on gold or silver plans' do
Timecop.freeze(GroupsWithTemplatesFinder::CUT_OFF_DATE + 1.day) do
groups = user.available_subgroups_with_custom_project_templates
groups = user.available_subgroups_with_custom_project_templates
expect(groups.size).to eq(1)
expect(groups.map(&:name)).to include('subgroup-2')
end
expect(groups.size).to eq(1)
expect(groups.map(&:name)).to include('subgroup-2')
end
end
end
......
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