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,8 +11,7 @@ RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration p ...@@ -11,8 +11,7 @@ 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 before do
project.update!(container_registry_enabled: container_registry_enabled_on_project) project.update!(container_registry_enabled: container_registry_enabled_on_project)
project.container_expiration_policy.update!(enabled: true) project.container_expiration_policy.update!(enabled: true)
...@@ -43,8 +42,8 @@ RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration p ...@@ -43,8 +42,8 @@ RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration p
expect(submit_button).not_to be_disabled expect(submit_button).not_to be_disabled
submit_button.click submit_button.click
end end
toast = find('.gl-toast')
expect(toast).to have_content('Cleanup policy successfully saved.') expect(find('.gl-toast')).to have_content('Cleanup policy successfully saved.')
end end
it 'does not save cleanup policy submit form with invalid regex' do it 'does not save cleanup policy submit form with invalid regex' do
...@@ -57,8 +56,8 @@ RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration p ...@@ -57,8 +56,8 @@ RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration p
expect(submit_button).not_to be_disabled expect(submit_button).not_to be_disabled
submit_button.click submit_button.click
end end
toast = find('.gl-toast')
expect(toast).to have_content('Something went wrong while updating the cleanup policy.') expect(find('.gl-toast')).to have_content('Something went wrong while updating the cleanup policy.')
end end
end end
...@@ -112,4 +111,25 @@ RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration p ...@@ -112,4 +111,25 @@ RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration p
expect(page).not_to have_selector('#js-registry-policies') expect(page).not_to have_selector('#js-registry-policies')
end end
end end
end
context 'with sidebar feature flag off' do
subject { visit project_settings_ci_cd_path(project) }
before do
stub_feature_flags(sidebar_refactor: false)
end
it_behaves_like 'an expiration policy form'
end
context 'with sidebar feature flag on' do
subject { visit project_settings_packages_and_registries_path(project) }
before do
stub_feature_flags(sidebar_refactor: true)
end
it_behaves_like 'an expiration policy form'
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