Commit 8c7defd3 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by Douglas Barbosa Alexandre

Move Cleanup Policy settings to new packages & registries settings page

parent c0b13f15
import registrySettingsApp from '~/packages_and_registries/settings/project/registry_settings_bundle';
import initSettingsPanels from '~/settings_panels';
registrySettingsApp();
initSettingsPanels();
# frozen_string_literal: true
module Projects
module Settings
class PackagesAndRegistriesController < Projects::ApplicationController
layout 'project_settings'
before_action :authorize_admin_project!
before_action :packages_and_registries_settings_enabled!
feature_category :package_registry
def index
end
private
def packages_and_registries_settings_enabled!
render_404 unless settings_packages_and_registries_enabled?(project)
end
end
end
end
......@@ -743,6 +743,7 @@ module ProjectsHelper
operations#show
badges#index
pages#show
packages_and_registries#index
]
end
......@@ -782,6 +783,16 @@ module ProjectsHelper
end
def settings_container_registry_expiration_policy_available?(project)
Feature.disabled?(:sidebar_refactor) &&
can_destroy_container_registry_image?(current_user, project)
end
def settings_packages_and_registries_enabled?(project)
Feature.enabled?(:sidebar_refactor) &&
can_destroy_container_registry_image?(current_user, project)
end
def can_destroy_container_registry_image?(current_user, project)
Gitlab.config.registry.enabled &&
can?(current_user, :destroy_container_image, project)
end
......
......@@ -274,6 +274,11 @@
= link_to project_pages_path(@project), title: _('Pages') do
%span
= _('Pages')
- if settings_packages_and_registries_enabled?(@project)
= nav_link(controller: :packages_and_registries) do
= link_to project_settings_packages_and_registries_path(@project), title: _('Packages & Registries'), data: { qa_selector: 'project_package_settings_link' } do
%span
= _('Packages & Registries')
-# Shortcut to Project > Activity
%li.hidden
......
- breadcrumb_title _('Packages & Registries')
- page_title _('Packages & Registries')
- @content_class = 'limit-container-width' unless fluid_layout
- expanded = true
%section.settings.no-animate#js-registry-policies{ class: ('expanded' if expanded) }
.settings-header
%h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only
= _("Clean up image tags")
%button.btn.gl-button.btn-default.js-settings-toggle{ type: 'button' }
= expanded ? _('Collapse') : _('Expand')
%p
= _("Save space and find images in the Container Registry. Remove unneeded tags and keep only the ones you want.")
= link_to _('How does cleanup work?'), help_page_path('user/packages/container_registry/index', anchor: 'cleanup-policy'), target: '_blank', rel: 'noopener noreferrer'
.settings-content
= render 'projects/registry/settings/index'
......@@ -129,6 +129,8 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
put :revoke
end
end
resources :packages_and_registries, only: [:index]
end
resources :autocomplete_sources, only: [] do
......
......@@ -61,6 +61,7 @@ RSpec.describe 'Project navbar' do
context 'when packages are available' do
before do
stub_config(packages: { enabled: true }, registry: { enabled: false })
stub_feature_flags(sidebar_refactor: false)
visit project_path(project)
end
......
......@@ -12,6 +12,7 @@ RSpec.describe 'Project navbar' do
let_it_be(:project) { create(:project, :repository) }
before do
stub_feature_flags(sidebar_refactor: false)
insert_package_nav(_('Operations'))
insert_infrastructure_registry_nav
stub_config(registry: { enabled: false })
......@@ -69,4 +70,23 @@ RSpec.describe 'Project navbar' do
it_behaves_like 'verified navigation bar'
end
context 'when sidebar refactor feature flag is on' do
before do
stub_feature_flags(sidebar_refactor: true)
stub_config(registry: { enabled: true })
insert_container_nav
insert_after_sub_nav_item(
_('Operations'),
within: _('Settings'),
new_sub_nav_item_name: _('Packages & Registries')
)
visit project_path(project)
end
it_behaves_like 'verified navigation bar'
end
end
......@@ -11,105 +11,125 @@ RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration p
let(:container_registry_enabled) { true }
let(:container_registry_enabled_on_project) { true }
subject { visit project_settings_ci_cd_path(project) }
shared_examples 'an expiration policy form' do
before do
project.update!(container_registry_enabled: container_registry_enabled_on_project)
project.container_expiration_policy.update!(enabled: true)
before do
project.update!(container_registry_enabled: container_registry_enabled_on_project)
project.container_expiration_policy.update!(enabled: true)
sign_in(user)
stub_container_registry_config(enabled: container_registry_enabled)
end
sign_in(user)
stub_container_registry_config(enabled: container_registry_enabled)
end
context 'as owner' do
it 'shows available section' do
subject
context 'as owner' do
it 'shows available section' do
subject
settings_block = find('#js-registry-policies')
expect(settings_block).to have_text 'Clean up image tags'
end
settings_block = find('#js-registry-policies')
expect(settings_block).to have_text 'Clean up image tags'
end
it 'saves cleanup policy submit the form' do
subject
it 'saves cleanup policy submit the form' do
subject
within '#js-registry-policies' do
select('Every day', from: 'Run cleanup')
select('50 tags per image name', from: 'Keep the most recent:')
fill_in('Keep tags matching:', with: 'stable')
select('7 days', from: 'Remove tags older than:')
fill_in('Remove tags matching:', with: '.*-production')
submit_button = find('[data-testid="save-button"')
expect(submit_button).not_to be_disabled
submit_button.click
end
within '#js-registry-policies' do
select('Every day', from: 'Run cleanup')
select('50 tags per image name', from: 'Keep the most recent:')
fill_in('Keep tags matching:', with: 'stable')
select('7 days', from: 'Remove tags older than:')
fill_in('Remove tags matching:', with: '.*-production')
expect(find('.gl-toast')).to have_content('Cleanup policy successfully saved.')
end
submit_button = find('[data-testid="save-button"')
expect(submit_button).not_to be_disabled
submit_button.click
it 'does not save cleanup policy submit form with invalid regex' do
subject
within '#js-registry-policies' do
fill_in('Remove tags matching:', with: '*-production')
submit_button = find('[data-testid="save-button"')
expect(submit_button).not_to be_disabled
submit_button.click
end
expect(find('.gl-toast')).to have_content('Something went wrong while updating the cleanup policy.')
end
toast = find('.gl-toast')
expect(toast).to have_content('Cleanup policy successfully saved.')
end
it 'does not save cleanup policy submit form with invalid regex' do
subject
context 'with a project without expiration policy' do
where(:application_setting, :feature_flag, :result) do
true | true | :available_section
true | false | :available_section
false | true | :available_section
false | false | :disabled_message
end
within '#js-registry-policies' do
fill_in('Remove tags matching:', with: '*-production')
with_them do
before do
project.container_expiration_policy.destroy!
stub_feature_flags(container_expiration_policies_historic_entry: false)
stub_application_setting(container_expiration_policies_enable_historic_entries: application_setting)
stub_feature_flags(container_expiration_policies_historic_entry: project) if feature_flag
end
submit_button = find('[data-testid="save-button"')
expect(submit_button).not_to be_disabled
submit_button.click
it 'displays the expected result' do
subject
within '#js-registry-policies' do
case result
when :available_section
expect(find('[data-testid="enable-toggle"]')).to have_content('Disabled - Tags will not be automatically deleted.')
when :disabled_message
expect(find('.gl-alert-title')).to have_content('Cleanup policy for tags is disabled')
end
end
end
end
toast = find('.gl-toast')
expect(toast).to have_content('Something went wrong while updating the cleanup policy.')
end
end
context 'with a project without expiration policy' do
where(:application_setting, :feature_flag, :result) do
true | true | :available_section
true | false | :available_section
false | true | :available_section
false | false | :disabled_message
end
context 'when registry is disabled' do
let(:container_registry_enabled) { false }
it 'does not exists' do
subject
with_them do
before do
project.container_expiration_policy.destroy!
stub_feature_flags(container_expiration_policies_historic_entry: false)
stub_application_setting(container_expiration_policies_enable_historic_entries: application_setting)
stub_feature_flags(container_expiration_policies_historic_entry: project) if feature_flag
expect(page).not_to have_selector('#js-registry-policies')
end
end
it 'displays the expected result' do
context 'when container registry is disabled on project' do
let(:container_registry_enabled_on_project) { false }
it 'does not exists' do
subject
within '#js-registry-policies' do
case result
when :available_section
expect(find('[data-testid="enable-toggle"]')).to have_content('Disabled - Tags will not be automatically deleted.')
when :disabled_message
expect(find('.gl-alert-title')).to have_content('Cleanup policy for tags is disabled')
end
end
expect(page).not_to have_selector('#js-registry-policies')
end
end
end
context 'when registry is disabled' do
let(:container_registry_enabled) { false }
context 'with sidebar feature flag off' do
subject { visit project_settings_ci_cd_path(project) }
it 'does not exists' do
subject
expect(page).not_to have_selector('#js-registry-policies')
before do
stub_feature_flags(sidebar_refactor: false)
end
end
context 'when container registry is disabled on project' do
let(:container_registry_enabled_on_project) { false }
it_behaves_like 'an expiration policy form'
end
it 'does not exists' do
subject
context 'with sidebar feature flag on' do
subject { visit project_settings_packages_and_registries_path(project) }
expect(page).not_to have_selector('#js-registry-policies')
before do
stub_feature_flags(sidebar_refactor: true)
end
it_behaves_like 'an expiration policy form'
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