Commit 712fd7f3 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '357645_add_a_method_to_determine_inactive_projects' into 'master'

Add a function to determine if a project is inactive

See merge request gitlab-org/gitlab!84935
parents 29515da8 2f6374cd
......@@ -2876,6 +2876,11 @@ class Project < ApplicationRecord
Projects::RecordTargetPlatformsWorker.perform_async(id)
end
def inactive?
(statistics || build_statistics).storage_size > ::Gitlab::CurrentSettings.inactive_projects_min_size_mb.megabytes &&
last_activity_at < ::Gitlab::CurrentSettings.inactive_projects_send_warning_email_after_months.months.ago
end
private
# overridden in EE
......
......@@ -867,6 +867,11 @@ module EE
].compact
end
override :inactive?
def inactive?
::Gitlab.com? && root_namespace.paid? ? false : super
end
private
def ci_minutes_usage
......
......@@ -3338,4 +3338,35 @@ RSpec.describe Project do
end
end
end
describe '#inactive?' do
context 'when Gitlab.com', :saas do
context 'when project belongs to paid namespace' do
before do
stub_application_setting(inactive_projects_min_size_mb: 5)
stub_application_setting(inactive_projects_send_warning_email_after_months: 24)
end
it 'returns false' do
ultimate_group = create(:group_with_plan, plan: :ultimate_plan)
ultimate_project = create(:project, last_activity_at: 3.years.ago, namespace: ultimate_group)
expect(ultimate_project.inactive?).to eq(false)
end
end
context 'when project belongs to free namespace' do
let_it_be(:no_plan_group) { create(:group_with_plan, plan: nil) }
let_it_be_with_reload(:project) { create(:project, namespace: no_plan_group) }
it_behaves_like 'returns true if project is inactive'
end
end
context 'when not Gitlab.com' do
let_it_be_with_reload(:project) { create(:project, name: 'test-project') }
it_behaves_like 'returns true if project is inactive'
end
end
end
......@@ -8235,6 +8235,12 @@ RSpec.describe Project, factory_default: :keep do
end
end
describe '#inactive?' do
let_it_be_with_reload(:project) { create(:project, name: 'test-project') }
it_behaves_like 'returns true if project is inactive'
end
private
def finish_job(export_job)
......
# frozen_string_literal: true
RSpec.shared_examples 'returns true if project is inactive' do
using RSpec::Parameterized::TableSyntax
where(:storage_size, :last_activity_at, :expected_result) do
1.megabyte | 1.month.ago | false
1.megabyte | 3.years.ago | false
8.megabytes | 1.month.ago | false
8.megabytes | 3.years.ago | true
end
with_them do
before do
stub_application_setting(inactive_projects_min_size_mb: 5)
stub_application_setting(inactive_projects_send_warning_email_after_months: 24)
project.statistics.storage_size = storage_size
project.last_activity_at = last_activity_at
project.save!
end
it 'returns expected result' do
expect(project.inactive?).to eq(expected_result)
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