Commit b794edfa authored by Nick Thomas's avatar Nick Thomas

Merge branch 'mk/geo-deprecate-legacy-storage' into 'master'

Geo: Show hashed storage warnings on geo nodes page

See merge request gitlab-org/gitlab-ee!8433
parents 6a1dc86c 4d433c20
import initGeoNodes from 'ee/geo_nodes';
import PersistentUserCallout from '~/persistent_user_callout';
document.addEventListener('DOMContentLoaded', initGeoNodes);
document.addEventListener('DOMContentLoaded', () => {
const callout = document.querySelector('.user-callout');
if (callout) new PersistentUserCallout(callout); // eslint-disable-line no-new
});
......@@ -2,7 +2,9 @@
module EE
module UserCalloutsHelper
GOLD_TRIAL = 'gold_trial'.freeze
GOLD_TRIAL = 'gold_trial'
GEO_ENABLE_HASHED_STORAGE = 'geo_enable_hashed_storage'
GEO_MIGRATE_HASHED_STORAGE = 'geo_migrate_hashed_storage'
def show_gold_trial?(user = current_user)
return false unless user
......@@ -22,5 +24,62 @@ module EE
!user.any_namespace_with_trial?
end
def render_enable_hashed_storage_warning
return unless show_enable_hashed_storage_warning?
message = enable_hashed_storage_warning_message
render_flash_user_callout(:warning, message, GEO_ENABLE_HASHED_STORAGE)
end
def render_migrate_hashed_storage_warning
return unless show_migrate_hashed_storage_warning?
message = migrate_hashed_storage_warning_message
render_flash_user_callout(:warning, message, GEO_MIGRATE_HASHED_STORAGE)
end
def show_enable_hashed_storage_warning?
return if hashed_storage_enabled?
!user_dismissed?(GEO_ENABLE_HASHED_STORAGE)
end
def show_migrate_hashed_storage_warning?
return unless hashed_storage_enabled?
return if user_dismissed?(GEO_MIGRATE_HASHED_STORAGE)
any_project_not_in_hashed_storage?
end
private
def hashed_storage_enabled?
::Gitlab::CurrentSettings.current_application_settings.hashed_storage_enabled
end
def any_project_not_in_hashed_storage?
::Project.with_unmigrated_storage.exists?
end
def enable_hashed_storage_warning_message
message = _('Please enable and migrate to hashed storage to avoid security issues and ensure data integrity. %{migrate_link}')
add_migrate_to_hashed_storage_link(message)
end
def migrate_hashed_storage_warning_message
message = _('Please migrate all existing projects to hashed storage to avoid security issues and ensure data integrity. %{migrate_link}')
add_migrate_to_hashed_storage_link(message)
end
def add_migrate_to_hashed_storage_link(message)
migrate_link = link_to(_('For more info, read the documentation.'), 'https://docs.gitlab.com/ee/administration/repository_storage_types.html#how-to-migrate-to-hashed-storage', target: '_blank')
linked_message = message % { migrate_link: migrate_link }
linked_message.html_safe
end
end
end
......@@ -9,7 +9,11 @@ module EE
override :feature_names
def feature_names
super.merge(cluster_security_warning: 3, gold_trial: 4)
super.merge(
cluster_security_warning: 3,
gold_trial: 4,
geo_enable_hashed_storage: 5,
geo_migrate_hashed_storage: 6)
end
end
end
......
- page_title 'Geo Nodes'
- @content_class = "geo-admin-container"
= render_enable_hashed_storage_warning
= render_migrate_hashed_storage_warning
%h2.page-title.clearfix
%span.title-text.float-left= _("Geo Nodes")
= link_to s_("GeoNodes|New node"), new_admin_geo_node_path, class: 'btn btn-success float-right'
......
---
title: 'Geo: Show hashed storage warnings on geo nodes page'
merge_request: 8433
author:
type: deprecated
......@@ -8,13 +8,63 @@ describe 'admin Geo Nodes', :js do
sign_in(create(:admin))
end
it 'show all public Geo Nodes and create new node link' do
visit admin_geo_nodes_path
wait_for_requests
describe 'index' do
it 'show all public Geo Nodes and create new node link' do
visit admin_geo_nodes_path
wait_for_requests
expect(page).to have_link('New node', href: new_admin_geo_node_path)
page.within(find('.geo-node-item', match: :first)) do
expect(page).to have_content(geo_node.url)
end
end
context 'hashed storage warnings' do
let(:enable_warning) { 'Please enable and migrate to hashed storage' }
let(:migrate_warning) { 'Please migrate all existing projects' }
let(:user_callout_close_button) { '.user-callout .js-close' }
context 'without hashed storage enabled' do
before do
stub_application_setting(hashed_storage_enabled: false)
end
it 'shows a dismissable warning to enable hashed storage' do
visit admin_geo_nodes_path
expect(page).to have_link('New node', href: new_admin_geo_node_path)
page.within(find('.geo-node-item', match: :first)) do
expect(page).to have_content(geo_node.url)
expect(page).to have_content enable_warning
expect(page).to have_selector user_callout_close_button
end
end
context 'with hashed storage enabled' do
before do
stub_application_setting(hashed_storage_enabled: true)
end
context 'with all projects in hashed storage' do
let!(:project) { create(:project) }
it 'does not show any hashed storage warning' do
visit admin_geo_nodes_path
expect(page).not_to have_content enable_warning
expect(page).not_to have_content migrate_warning
expect(page).not_to have_selector user_callout_close_button
end
end
context 'with at least one project in legacy storage' do
let!(:project) { create(:project, :legacy_storage) }
it 'shows a dismissable warning to migrate to hashed storage' do
visit admin_geo_nodes_path
expect(page).to have_content migrate_warning
expect(page).to have_selector user_callout_close_button
end
end
end
end
end
......
......@@ -7,7 +7,7 @@ describe EE::UserCalloutsHelper do
let(:user) { create(:user) }
before do
allow(helper).to receive(:user_dismissed?).with(EE::UserCalloutsHelper::GOLD_TRIAL).and_return(false)
allow(helper).to receive(:user_dismissed?).with(described_class::GOLD_TRIAL).and_return(false)
allow(Gitlab).to receive(:com?).and_return(true)
allow(Gitlab::Database).to receive(:read_only?).and_return(false)
allow(user).to receive(:any_namespace_with_gold?).and_return(false)
......@@ -24,4 +24,128 @@ describe EE::UserCalloutsHelper do
expect(helper.show_gold_trial?).to be(false)
end
end
describe '.render_enable_hashed_storage_warning' do
context 'when we should show the enable warning' do
it 'renders the enable warning' do
expect(helper).to receive(:show_enable_hashed_storage_warning?).and_return(true)
expect(helper).to receive(:render_flash_user_callout)
.with(:warning,
/Please enable and migrate to hashed/,
EE::UserCalloutsHelper::GEO_ENABLE_HASHED_STORAGE)
helper.render_enable_hashed_storage_warning
end
end
context 'when we should not show the enable warning' do
it 'does not render the enable warning' do
expect(helper).to receive(:show_enable_hashed_storage_warning?).and_return(false)
expect(helper).not_to receive(:render_flash_user_callout)
helper.render_enable_hashed_storage_warning
end
end
end
describe '.render_migrate_hashed_storage_warning' do
context 'when we should show the migrate warning' do
it 'renders the migrate warning' do
expect(helper).to receive(:show_migrate_hashed_storage_warning?).and_return(true)
expect(helper).to receive(:render_flash_user_callout)
.with(:warning,
/Please migrate all existing projects/,
EE::UserCalloutsHelper::GEO_MIGRATE_HASHED_STORAGE)
helper.render_migrate_hashed_storage_warning
end
end
context 'when we should not show the migrate warning' do
it 'does not render the migrate warning' do
expect(helper).to receive(:show_migrate_hashed_storage_warning?).and_return(false)
expect(helper).not_to receive(:render_flash_user_callout)
helper.render_migrate_hashed_storage_warning
end
end
end
describe '.show_enable_hashed_storage_warning?' do
subject { helper.show_enable_hashed_storage_warning? }
let(:user) { create(:user) }
context 'when hashed storage is disabled' do
before do
stub_application_setting(hashed_storage_enabled: false)
expect(helper).to receive(:current_user).and_return(user)
end
context 'when the enable warning has not been dismissed' do
it { is_expected.to be_truthy }
end
context 'when the enable warning was dismissed' do
before do
create(:user_callout, user: user, feature_name: described_class::GEO_ENABLE_HASHED_STORAGE)
end
it { is_expected.to be_falsy }
end
end
context 'when hashed storage is enabled' do
before do
stub_application_setting(hashed_storage_enabled: true)
end
it { is_expected.to be_falsy }
end
end
describe '.show_migrate_hashed_storage_warning?' do
subject { helper.show_migrate_hashed_storage_warning? }
let(:user) { create(:user) }
context 'when hashed storage is disabled' do
before do
stub_application_setting(hashed_storage_enabled: false)
end
it { is_expected.to be_falsy }
end
context 'when hashed storage is enabled' do
before do
stub_application_setting(hashed_storage_enabled: true)
expect(helper).to receive(:current_user).and_return(user)
end
context 'when the enable warning has not been dismissed' do
context 'when there is a project in non-hashed-storage' do
before do
create(:project, :legacy_storage)
end
it { is_expected.to be_truthy }
end
context 'when there are NO projects in non-hashed-storage' do
it { is_expected.to be_falsy }
end
end
context 'when the enable warning was dismissed' do
before do
create(:user_callout, user: user, feature_name: described_class::GEO_MIGRATE_HASHED_STORAGE)
end
it { is_expected.to be_falsy }
end
end
end
end
......@@ -3869,6 +3869,9 @@ msgstr ""
msgid "For internal projects, any logged in user can view pipelines and access job details (output logs and artifacts)"
msgstr ""
msgid "For more info, read the documentation."
msgstr ""
msgid "For more information, go to the "
msgstr ""
......@@ -6554,9 +6557,15 @@ msgstr ""
msgid "Please convert them to Git on Google Code, and go through the %{link_to_import_flow} again."
msgstr ""
msgid "Please enable and migrate to hashed storage to avoid security issues and ensure data integrity. %{migrate_link}"
msgstr ""
msgid "Please fill in a descriptive name for your group."
msgstr ""
msgid "Please migrate all existing projects to hashed storage to avoid security issues and ensure data integrity. %{migrate_link}"
msgstr ""
msgid "Please note that this application is not provided by GitLab and you should verify its authenticity before allowing access."
msgstr ""
......
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