Commit 6468b7ed authored by Michael Kozono's avatar Michael Kozono

Geo: Add hashed storage warnings

Hashed storage is now a requirement of Geo. This is
one part of deprecating non-hashed storage for Geo.
parent c662ec7b
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,61 @@ 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.html_safe, 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.html_safe, GEO_MIGRATE_HASHED_STORAGE)
end
def show_enable_hashed_storage_warning?
return if user_dismissed?(GEO_ENABLE_HASHED_STORAGE)
hashed_storage_disabled?
end
def show_migrate_hashed_storage_warning?
return if user_dismissed?(GEO_MIGRATE_HASHED_STORAGE)
return if hashed_storage_disabled?
any_project_not_in_hashed_storage?
end
private
def hashed_storage_disabled?
!::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')
message % { migrate_link: migrate_link }
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'
......
......@@ -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,137 @@ 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) }
before do
expect(helper).to receive(:current_user).and_return(user)
end
context 'when the enable warning has not been dismissed' do
context 'when hashed storage is disabled' do
before do
stub_application_setting(hashed_storage_enabled: false)
end
it { is_expected.to be_truthy }
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
context 'when the enable warning was dismissed' do
it 'does not render the enable warning' do
create(:user_callout, user: user, feature_name: described_class::GEO_ENABLE_HASHED_STORAGE)
expect(helper).not_to receive(:render_flash_user_callout)
helper.render_enable_hashed_storage_warning
end
end
end
describe '.show_migrate_hashed_storage_warning?' do
subject { helper.show_migrate_hashed_storage_warning? }
let(:user) { create(:user) }
before do
expect(helper).to receive(:current_user).and_return(user)
end
context 'when the migrate warning has not been dismissed' do
context 'when hashed storage is disabled' do
before do
expect(helper).to receive(:hashed_storage_disabled?).and_return(true)
end
it { is_expected.to be_falsy }
end
context 'when hashed storage is enabled' do
before do
expect(helper).to receive(:hashed_storage_disabled?).and_return(false)
end
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
end
context 'when the migrate warning was dismissed' do
it 'does not render the migrate warning' do
create(:user_callout, user: user, feature_name: described_class::GEO_ENABLE_HASHED_STORAGE)
expect(helper).not_to receive(:render_flash_user_callout)
helper.render_migrate_hashed_storage_warning
end
end
end
end
......@@ -3866,6 +3866,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 ""
......@@ -6551,9 +6554,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