Commit 432bf763 authored by Aishwarya Subramanian's avatar Aishwarya Subramanian

List only active project templates

Adds a fix to only display project templates
that are active. It discards projects that are scheduled
to be deleted in the future via delayed deletion.
parent b550582c
......@@ -165,7 +165,7 @@ module EE
def group_project_templates_count(group_id)
allowed_subgroups = current_user.available_subgroups_with_custom_project_templates(group_id)
::Project.in_namespace(allowed_subgroups).count
::Project.in_namespace(allowed_subgroups).not_aimed_for_deletion.count
end
def project_security_dashboard_config(project)
......
......@@ -143,6 +143,7 @@ module EE
scope :with_slack_slash_commands_service, -> { joins(:slack_slash_commands_service) }
scope :with_prometheus_service, -> { joins(:prometheus_service) }
scope :aimed_for_deletion, -> (date) { where('marked_for_deletion_at <= ?', date).without_deleted }
scope :not_aimed_for_deletion, -> { where(marked_for_deletion_at: nil) }
scope :with_repos_templates, -> { where(namespace_id: ::Gitlab::CurrentSettings.current_application_settings.custom_project_templates_group_id) }
scope :with_groups_level_repos_templates, -> { joins("INNER JOIN namespaces ON projects.namespace_id = namespaces.custom_project_templates_group_id") }
scope :with_designs, -> { where(id: ::DesignManagement::Design.select(:project_id).distinct) }
......
.custom-project-templates
- if groups_with_project_templates.present?
- groups_with_project_templates.each do |group|
- projects = group.projects.not_aimed_for_deletion
.template-group-options.js-template-group-options{ class: ('expanded border-top-0' if groups_with_project_templates.first == group) }
.template-header.d-flex.align-items-center
.template-subgroup.d-flex.flex-fill.align-items-center
......@@ -17,9 +18,9 @@
.template-subgroup-project-count
%span.badge.badge-pill
%strong
= group.projects.count
= projects.count
- group.projects.each do |project|
- projects.each do |project|
.template-option.align-items-center.qa-template-option-row
.avatar-container.s40
= project_icon(project, alt: project.name, class: 'btn-template-icon avatar s40 avatar-tile', lazy: false)
......
---
title: Permit new projects to be created from active project templates only
merge_request: 38335
author:
type: fixed
......@@ -87,6 +87,36 @@ RSpec.describe ProjectsHelper do
end
end
describe '#group_project_templates_count' do
let_it_be(:user) { create(:user) }
let_it_be(:parent_group) { create(:group, name: 'parent-group') }
let_it_be(:template_group) { create(:group, parent: parent_group, name: 'template-group') }
let_it_be(:template_project) { create(:project, group: template_group, name: 'template-project') }
before_all do
parent_group.update!(custom_project_templates_group_id: template_group.id)
parent_group.add_owner(user)
end
before do
allow(helper).to receive(:current_user).and_return(user)
end
it do
expect(helper.group_project_templates_count(parent_group.id)).to eq 1
end
context 'when template project is pending deletion' do
before do
template_project.update!(marked_for_deletion_at: Date.current)
end
it do
expect(helper.group_project_templates_count(parent_group.id)).to eq 0
end
end
end
describe '#project_security_dashboard_config' do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
......
......@@ -230,6 +230,15 @@ RSpec.describe Project do
it { is_expected.to contain_exactly(project_1) }
end
describe '.not_aimed_for_deletion' do
let_it_be(:project) { create(:project) }
let_it_be(:delayed_deletion_project) { create(:project, marked_for_deletion_at: Date.current) }
it do
expect(described_class.not_aimed_for_deletion).to contain_exactly(project)
end
end
end
describe 'validations' 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