Commit 2b36a30a authored by Illya Klymov's avatar Illya Klymov

Merge branch 'jc-show-all-storages' into 'master'

Show all storages in settings

Closes #220825

See merge request gitlab-org/gitlab!34093
parents 0e550529 d99cf575
......@@ -26,6 +26,17 @@ module ApplicationSettingsHelper
end
end
def storage_weights
ApplicationSetting.repository_storages_weighted_attributes.map do |attribute|
storage = attribute.to_s.delete_prefix('repository_storages_weighted_')
{
name: attribute,
label: storage,
value: @application_setting.repository_storages_weighted[storage] || 0
}
end
end
def all_protocols_enabled?
Gitlab::CurrentSettings.enabled_git_access_protocol.blank?
end
......
......@@ -15,12 +15,12 @@
.form-group
.form-text
%p.text-secondary
= _('Select the configured storage available for new repositories to be placed on.')
= _('Select a weight for the storage new repositories will be placed on.')
= link_to icon('question-circle'), help_page_path('administration/repository_storage_paths')
.form-check
- @application_setting.repository_storages_weighted.each_key do |storage|
= f.text_field "repository_storages_weighted_#{storage}".to_sym, class: 'form-text-input'
= f.label storage, storage, class: 'label-bold form-check-label'
- storage_weights.each do |attribute|
= f.text_field attribute[:name], class: 'form-text-input', value: attribute[:value]
= f.label attribute[:label], attribute[:label], class: 'label-bold form-check-label'
%br
= f.submit _('Save changes'), class: "btn btn-success qa-save-changes-button"
---
title: Show all storages in settings
merge_request: 34093
author:
type: fixed
......@@ -19905,6 +19905,9 @@ msgstr ""
msgid "Select a timezone"
msgstr ""
msgid "Select a weight for the storage new repositories will be placed on."
msgstr ""
msgid "Select all"
msgstr ""
......@@ -19986,9 +19989,6 @@ msgstr ""
msgid "Select the branch you want to set as the default for this project. All merge requests and commits will automatically be made against this branch unless you specify a different one."
msgstr ""
msgid "Select the configured storage available for new repositories to be placed on."
msgstr ""
msgid "Select the custom project template source group."
msgstr ""
......
......@@ -123,4 +123,27 @@ describe ApplicationSettingsHelper do
end
end
end
describe '.storage_weights' do
let(:application_setting) { build(:application_setting) }
before do
helper.instance_variable_set(:@application_setting, application_setting)
stub_storage_settings({ 'default': {}, 'storage_1': {}, 'storage_2': {} })
allow(ApplicationSetting).to receive(:repository_storages_weighted_attributes).and_return(
[:repository_storages_weighted_default,
:repository_storages_weighted_storage_1,
:repository_storages_weighted_storage_2])
stub_application_setting(repository_storages_weighted: { 'default' => 100, 'storage_1' => 50, 'storage_2' => nil })
end
it 'returns storages correctly' do
expect(helper.storage_weights).to eq([
{ name: :repository_storages_weighted_default, label: 'default', value: 100 },
{ name: :repository_storages_weighted_storage_1, label: 'storage_1', value: 50 },
{ name: :repository_storages_weighted_storage_2, label: 'storage_2', value: 0 }
])
end
end
end
......@@ -4,10 +4,11 @@ require 'spec_helper'
describe 'admin/application_settings/_repository_storage.html.haml' do
let(:app_settings) { create(:application_setting) }
let(:repository_storages_weighted_attributes) { [:repository_storages_weighted_default, :repository_storages_weighted_mepmep, :repository_storages_weighted_foobar]}
let(:repository_storages_weighted) do
{
"mepmep" => 100,
"foobar" => 50
"default" => 100,
"mepmep" => 50
}
end
......@@ -16,15 +17,20 @@ describe 'admin/application_settings/_repository_storage.html.haml' do
allow(app_settings).to receive(:repository_storages_weighted_mepmep).and_return(100)
allow(app_settings).to receive(:repository_storages_weighted_foobar).and_return(50)
assign(:application_setting, app_settings)
allow(ApplicationSetting).to receive(:repository_storages_weighted_attributes).and_return(repository_storages_weighted_attributes)
end
context 'when multiple storages are available' do
it 'lists them all' do
render
# lists storages that are saved with weights
repository_storages_weighted.each do |storage_name, storage_weight|
expect(rendered).to have_content(storage_name)
end
# lists storage not saved with weight
expect(rendered).to have_content('foobar')
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