Commit 641151e0 authored by huzaifaiftikhar1's avatar huzaifaiftikhar1 Committed by Huzaifa Iftikhar

Add a method named 'inactive?' to determine if a project is inactive

Inactive projects are defined as follows:

Self-managed projects with any license (Free, Premium, or Ultimate) or
GitLab SaaS projects that have a Free license where the project meets
both of the following criteria:

1. The project repository size exceeds the size threshold defined in
the instance settings.
2. The project has not had any comments, commits, MRs, new issues, or
other activity for the length of time defined in the instance settings.
parent 537afcc7
......@@ -2868,6 +2868,11 @@ class Project < ApplicationRecord
Projects::RecordTargetPlatformsWorker.perform_async(id)
end
def inactive?
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(: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(:project) { create(:project, name: 'test-project') }
it_behaves_like 'returns true if project is inactive'
end
end
end
......@@ -8178,6 +8178,12 @@ RSpec.describe Project, factory_default: :keep do
end
end
describe '#inactive?' do
let_it_be(: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
104857 | 1.month.ago | false
104857 | 3.years.ago | false
8388600 | 1.month.ago | false
8388600 | 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