summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2016-06-29 23:35:00 -0400
committerAlejandro Rodríguez <alejorro70@gmail.com>2016-06-29 23:35:00 -0400
commit4a8a69837a9a14fca39bf089099b581602d983f2 (patch)
tree79c028de4c65c580a4f5d462a3ac4202dbcd0e72
parent20b9bb2029972c5f5334d6d684e0d60edb034c5f (diff)
downloadgitlab-ce-shards-config.tar.gz
Add Application Setting to configure default Repository Path for new projectsshards-config
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/admin/application_settings_controller.rb1
-rw-r--r--app/helpers/application_settings_helper.rb8
-rw-r--r--app/models/application_setting.rb5
-rw-r--r--app/models/project.rb1
-rw-r--r--app/views/admin/application_settings/_form.html.haml9
-rw-r--r--db/migrate/20160614182521_add_repository_storage_to_application_settings.rb5
-rw-r--r--db/schema.rb1
-rw-r--r--doc/api/settings.md7
-rw-r--r--lib/api/entities.rb1
-rw-r--r--spec/models/application_setting_spec.rb10
-rw-r--r--spec/models/project_spec.rb15
-rw-r--r--spec/requests/api/settings_spec.rb9
13 files changed, 70 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 6b23ce2b27d..68df9aa6201 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,6 +4,7 @@ v 8.10.0 (unreleased)
- Fix commit builds API, return all builds for all pipelines for given commit. !4849
- Replace Haml with Hamlit to make view rendering faster. !3666
- Refactor repository paths handling to allow multiple git mount points
+ - Add Application Setting to configure default Repository Path for new projects
- Wrap code blocks on Activies and Todos page. !4783 (winniehell)
- Align flash messages with left side of page content !4959 (winniehell)
- Display last commit of deleted branch in push events !4699 (winniehell)
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb
index f4eda864aac..5f65dd3aff0 100644
--- a/app/controllers/admin/application_settings_controller.rb
+++ b/app/controllers/admin/application_settings_controller.rb
@@ -109,6 +109,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:metrics_packet_size,
:send_user_confirmation_email,
:container_registry_token_expire_delay,
+ :repository_storage,
restricted_visibility_levels: [],
import_sources: [],
disabled_oauth_sign_in_sources: []
diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb
index 55313fd8357..6e580c62ccd 100644
--- a/app/helpers/application_settings_helper.rb
+++ b/app/helpers/application_settings_helper.rb
@@ -78,4 +78,12 @@ module ApplicationSettingsHelper
end
end
end
+
+ def repository_storage_options_for_select
+ options = Gitlab.config.repositories.storages.map do |name, path|
+ ["#{name} - #{path}", name]
+ end
+
+ options_for_select(options, @application_setting.repository_storage)
+ end
end
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb
index d914b0b26eb..5fa6eacd234 100644
--- a/app/models/application_setting.rb
+++ b/app/models/application_setting.rb
@@ -55,6 +55,10 @@ class ApplicationSetting < ActiveRecord::Base
presence: true,
numericality: { only_integer: true, greater_than: 0 }
+ validates :repository_storage,
+ presence: true,
+ inclusion: { in: ->(_object) { Gitlab.config.repositories.storages.keys } }
+
validates_each :restricted_visibility_levels do |record, attr, value|
unless value.nil?
value.each do |level|
@@ -134,6 +138,7 @@ class ApplicationSetting < ActiveRecord::Base
disabled_oauth_sign_in_sources: [],
send_user_confirmation_email: false,
container_registry_token_expire_delay: 5,
+ repository_storage: 'default',
)
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 2f6901e0e3e..6a950ee830d 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -24,6 +24,7 @@ class Project < ActiveRecord::Base
default_value_for :wiki_enabled, gitlab_config_features.wiki
default_value_for :snippets_enabled, gitlab_config_features.snippets
default_value_for :container_registry_enabled, gitlab_config_features.container_registry
+ default_value_for(:repository_storage) { current_application_settings.repository_storage }
default_value_for(:shared_runners_enabled) { current_application_settings.shared_runners_enabled }
after_create :ensure_dir_exist
diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml
index 30ab0717164..c1f70bc1866 100644
--- a/app/views/admin/application_settings/_form.html.haml
+++ b/app/views/admin/application_settings/_form.html.haml
@@ -311,6 +311,15 @@
= f.text_field :sentry_dsn, class: 'form-control'
%fieldset
+ %legend Repository Storage
+ .form-group
+ = f.label :repository_storage, 'Storage path for new projects', class: 'control-label col-sm-2'
+ .col-sm-10
+ = f.select :repository_storage, repository_storage_options_for_select, {}, class: 'form-control'
+ .help-block
+ You can manage the repository storage paths in your gitlab.yml configuration file
+
+ %fieldset
%legend Repository Checks
.form-group
.col-sm-offset-2.col-sm-10
diff --git a/db/migrate/20160614182521_add_repository_storage_to_application_settings.rb b/db/migrate/20160614182521_add_repository_storage_to_application_settings.rb
new file mode 100644
index 00000000000..6dae91b700b
--- /dev/null
+++ b/db/migrate/20160614182521_add_repository_storage_to_application_settings.rb
@@ -0,0 +1,5 @@
+class AddRepositoryStorageToApplicationSettings < ActiveRecord::Migration
+ def change
+ add_column :application_settings, :repository_storage, :string, default: 'default'
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a7173116b1b..beb723c3bc5 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -85,6 +85,7 @@ ActiveRecord::Schema.define(version: 20160620115026) do
t.boolean "send_user_confirmation_email", default: false
t.integer "container_registry_token_expire_delay", default: 5
t.text "after_sign_up_text"
+ t.string "repository_storage", default: "default"
end
create_table "audit_events", force: :cascade do |t|
diff --git a/doc/api/settings.md b/doc/api/settings.md
index b5152311f28..741c5a29581 100644
--- a/doc/api/settings.md
+++ b/doc/api/settings.md
@@ -38,7 +38,8 @@ Example response:
"default_project_visibility" : 0,
"gravatar_enabled" : true,
"sign_in_text" : null,
- "container_registry_token_expire_delay": 5
+ "container_registry_token_expire_delay": 5,
+ "repository_storage": "default"
}
```
@@ -66,6 +67,7 @@ PUT /application/settings
| `user_oauth_applications` | boolean | no | Allow users to register any application to use GitLab as an OAuth provider |
| `after_sign_out_path` | string | no | Where to redirect users after logout |
| `container_registry_token_expire_delay` | integer | no | Container Registry token duration in minutes |
+| `repository_storage` | string | no | Storage path for new projects. The value should be the name of one of the repository storage paths defined in your gitlab.yml |
```bash
curl -X PUT -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/application/settings?signup_enabled=false&default_project_visibility=1
@@ -93,6 +95,7 @@ Example response:
"restricted_signup_domains": [],
"user_oauth_applications": true,
"after_sign_out_path": "",
- "container_registry_token_expire_delay": 5
+ "container_registry_token_expire_delay": 5,
+ "repository_storage": "default"
}
```
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 5a23a18fe9c..4e2a43e45e2 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -376,6 +376,7 @@ module API
expose :user_oauth_applications
expose :after_sign_out_path
expose :container_registry_token_expire_delay
+ expose :repository_storage
end
class Release < Grape::Entity
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index d84f3e998f5..2ea1320267c 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -40,6 +40,16 @@ describe ApplicationSetting, models: true do
it_behaves_like 'an object with email-formated attributes', :admin_notification_email do
subject { setting }
end
+
+ context 'repository storages inclussion' do
+ before do
+ storages = { 'custom' => 'tmp/tests/custom_repositories' }
+ allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
+ end
+
+ it { is_expected.to allow_value('custom').for(:repository_storage) }
+ it { is_expected.not_to allow_value('alternative').for(:repository_storage) }
+ end
end
context 'restricted signup domains' do
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index ee1142fa3aa..42308035d8c 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -607,6 +607,21 @@ describe Project, models: true do
end
end
+ context 'repository storage by default' do
+ let(:project) { create(:empty_project) }
+
+ subject { project.repository_storage }
+
+ before do
+ storages = { 'alternative_storage' => '/some/path' }
+ allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
+ stub_application_setting(repository_storage: 'alternative_storage')
+ allow_any_instance_of(Project).to receive(:ensure_dir_exist).and_return(true)
+ end
+
+ it { is_expected.to eq('alternative_storage') }
+ end
+
context 'shared runners by default' do
let(:project) { create(:empty_project) }
diff --git a/spec/requests/api/settings_spec.rb b/spec/requests/api/settings_spec.rb
index f756101c514..6629a5a65e2 100644
--- a/spec/requests/api/settings_spec.rb
+++ b/spec/requests/api/settings_spec.rb
@@ -14,16 +14,23 @@ describe API::API, 'Settings', api: true do
expect(json_response).to be_an Hash
expect(json_response['default_projects_limit']).to eq(42)
expect(json_response['signin_enabled']).to be_truthy
+ expect(json_response['repository_storage']).to eq('default')
end
end
describe "PUT /application/settings" do
+ before do
+ storages = { 'custom' => 'tmp/tests/custom_repositories' }
+ allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
+ end
+
it "should update application settings" do
put api("/application/settings", admin),
- default_projects_limit: 3, signin_enabled: false
+ default_projects_limit: 3, signin_enabled: false, repository_storage: 'custom'
expect(response).to have_http_status(200)
expect(json_response['default_projects_limit']).to eq(3)
expect(json_response['signin_enabled']).to be_falsey
+ expect(json_response['repository_storage']).to eq('custom')
end
end
end