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 ...@@ -743,6 +743,7 @@ module ProjectsHelper
operations#show operations#show
badges#index badges#index
pages#show pages#show
packages_and_registries#index
] ]
end end
...@@ -782,6 +783,16 @@ module ProjectsHelper ...@@ -782,6 +783,16 @@ module ProjectsHelper
end end
def settings_container_registry_expiration_policy_available?(project) 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 && Gitlab.config.registry.enabled &&
can?(current_user, :destroy_container_image, project) can?(current_user, :destroy_container_image, project)
end end
......
...@@ -274,6 +274,11 @@ ...@@ -274,6 +274,11 @@
= link_to project_pages_path(@project), title: _('Pages') do = link_to project_pages_path(@project), title: _('Pages') do
%span %span
= _('Pages') = _('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 -# Shortcut to Project > Activity
%li.hidden %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 ...@@ -129,6 +129,8 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
put :revoke put :revoke
end end
end end
resources :packages_and_registries, only: [:index]
end end
resources :autocomplete_sources, only: [] do resources :autocomplete_sources, only: [] do
......
...@@ -61,6 +61,7 @@ RSpec.describe 'Project navbar' do ...@@ -61,6 +61,7 @@ RSpec.describe 'Project navbar' do
context 'when packages are available' do context 'when packages are available' do
before do before do
stub_config(packages: { enabled: true }, registry: { enabled: false }) stub_config(packages: { enabled: true }, registry: { enabled: false })
stub_feature_flags(sidebar_refactor: false)
visit project_path(project) visit project_path(project)
end end
......
...@@ -12,6 +12,7 @@ RSpec.describe 'Project navbar' do ...@@ -12,6 +12,7 @@ RSpec.describe 'Project navbar' do
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
before do before do
stub_feature_flags(sidebar_refactor: false)
insert_package_nav(_('Operations')) insert_package_nav(_('Operations'))
insert_infrastructure_registry_nav insert_infrastructure_registry_nav
stub_config(registry: { enabled: false }) stub_config(registry: { enabled: false })
...@@ -69,4 +70,23 @@ RSpec.describe 'Project navbar' do ...@@ -69,4 +70,23 @@ RSpec.describe 'Project navbar' do
it_behaves_like 'verified navigation bar' it_behaves_like 'verified navigation bar'
end 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 end
...@@ -11,105 +11,125 @@ RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration p ...@@ -11,105 +11,125 @@ RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration p
let(:container_registry_enabled) { true } let(:container_registry_enabled) { true }
let(:container_registry_enabled_on_project) { 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 sign_in(user)
project.update!(container_registry_enabled: container_registry_enabled_on_project) stub_container_registry_config(enabled: container_registry_enabled)
project.container_expiration_policy.update!(enabled: true) end
sign_in(user) context 'as owner' do
stub_container_registry_config(enabled: container_registry_enabled) it 'shows available section' do
end subject
context 'as owner' do settings_block = find('#js-registry-policies')
it 'shows available section' do expect(settings_block).to have_text 'Clean up image tags'
subject end
settings_block = find('#js-registry-policies') it 'saves cleanup policy submit the form' do
expect(settings_block).to have_text 'Clean up image tags' subject
end
it 'saves cleanup policy submit the form' do within '#js-registry-policies' do
subject 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 expect(find('.gl-toast')).to have_content('Cleanup policy successfully saved.')
select('Every day', from: 'Run cleanup') end
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"') it 'does not save cleanup policy submit form with invalid regex' do
expect(submit_button).not_to be_disabled subject
submit_button.click
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 end
toast = find('.gl-toast')
expect(toast).to have_content('Cleanup policy successfully saved.')
end end
it 'does not save cleanup policy submit form with invalid regex' do context 'with a project without expiration policy' do
subject 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 with_them do
fill_in('Remove tags matching:', with: '*-production') 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"') it 'displays the expected result' do
expect(submit_button).not_to be_disabled subject
submit_button.click
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 end
toast = find('.gl-toast')
expect(toast).to have_content('Something went wrong while updating the cleanup policy.')
end end
end
context 'with a project without expiration policy' do context 'when registry is disabled' do
where(:application_setting, :feature_flag, :result) do let(:container_registry_enabled) { false }
true | true | :available_section
true | false | :available_section it 'does not exists' do
false | true | :available_section subject
false | false | :disabled_message
end
with_them do expect(page).not_to have_selector('#js-registry-policies')
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 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 subject
within '#js-registry-policies' do expect(page).not_to have_selector('#js-registry-policies')
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
end end
end end
context 'when registry is disabled' do context 'with sidebar feature flag off' do
let(:container_registry_enabled) { false } subject { visit project_settings_ci_cd_path(project) }
it 'does not exists' do before do
subject stub_feature_flags(sidebar_refactor: false)
expect(page).not_to have_selector('#js-registry-policies')
end end
end
context 'when container registry is disabled on project' do it_behaves_like 'an expiration policy form'
let(:container_registry_enabled_on_project) { false } end
it 'does not exists' do context 'with sidebar feature flag on' do
subject 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 end
it_behaves_like 'an expiration policy form'
end 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