diff options
-rw-r--r-- | app/controllers/admin/application_settings_controller.rb | 10 | ||||
-rw-r--r-- | app/helpers/application_settings_helper.rb | 17 | ||||
-rw-r--r-- | app/models/application_setting.rb | 15 | ||||
-rw-r--r-- | app/views/admin/application_settings/_form.html.haml | 14 | ||||
-rw-r--r-- | config/initializers/1_settings.rb | 1 | ||||
-rw-r--r-- | db/migrate/20150812080800_add_settings_import_sources.rb | 11 | ||||
-rw-r--r-- | db/schema.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/current_settings.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/import_sources.rb | 29 |
9 files changed, 100 insertions, 3 deletions
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb index c7c643db401..f38e07af84b 100644 --- a/app/controllers/admin/application_settings_controller.rb +++ b/app/controllers/admin/application_settings_controller.rb @@ -29,6 +29,15 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController end end + import_sources = params[:application_setting][:import_sources] + if import_sources.nil? + params[:application_setting][:import_sources] = [] + else + import_sources.map! do |source| + source.to_str + end + end + params.require(:application_setting).permit( :default_projects_limit, :default_branch_protection, @@ -47,6 +56,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController :version_check_enabled, :user_oauth_applications, restricted_visibility_levels: [], + import_sources: [] ) end end diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 61d14383945..7d6b58ee21a 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -39,4 +39,21 @@ module ApplicationSettingsHelper end end end + + # Return a group of checkboxes that use Bootstrap's button plugin for a + # toggle button effect. + def import_sources_checkboxes(help_block_id) + Gitlab::ImportSources.options.map do |name, source| + checked = current_application_settings.import_sources.include?(source) + css_class = 'btn' + css_class += ' active' if checked + checkbox_name = 'application_setting[import_sources][]' + + label_tag(checkbox_name, class: css_class) do + check_box_tag(checkbox_name, source, checked, + autocomplete: 'off', + 'aria-describedby' => help_block_id) + name + end + end + end end diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 6d1ad82a262..8f27e35d723 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -22,10 +22,12 @@ # user_oauth_applications :boolean default(TRUE) # after_sign_out_path :string(255) # session_expire_delay :integer default(10080), not null +# import_sources :text # class ApplicationSetting < ActiveRecord::Base serialize :restricted_visibility_levels + serialize :import_sources serialize :restricted_signup_domains, Array attr_accessor :restricted_signup_domains_raw @@ -52,6 +54,16 @@ class ApplicationSetting < ActiveRecord::Base end end + validates_each :import_sources do |record, attr, value| + unless value.nil? + value.each do |source| + unless Gitlab::ImportSources.options.has_value?(source) + record.errors.add(attr, "'#{source}' is not a import source") + end + end + end + end + def self.current ApplicationSetting.last end @@ -70,7 +82,8 @@ class ApplicationSetting < ActiveRecord::Base session_expire_delay: Settings.gitlab['session_expire_delay'], default_project_visibility: Settings.gitlab.default_projects_features['visibility_level'], default_snippet_visibility: Settings.gitlab.default_projects_features['visibility_level'], - restricted_signup_domains: Settings.gitlab['restricted_signup_domains'] + restricted_signup_domains: Settings.gitlab['restricted_signup_domains'], + import_sources: ['github','bitbucket','gitlab','gitorious','google_code','git'] ) end diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index b67d2116fa4..330b8bbf9d2 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -28,6 +28,20 @@ = level %span.help-block#restricted-visibility-help Selected levels cannot be used by non-admin users for projects or snippets .form-group + = f.label :import_sources, class: 'control-label col-sm-2' + .col-sm-10 + - data_attrs = { toggle: 'buttons' } + .btn-group{ data: data_attrs } + - import_sources_checkboxes('import-sources-help').each do |source| + = source + %span.help-block#import-sources-help + Enabled sources for code import during project creation. OmniAuth must be configured for GitHub + = link_to "(?)", help_page_path("integration", "github") + , Bitbucket + = link_to "(?)", help_page_path("integration", "bitbucket") + and GitLab.com + = link_to "(?)", help_page_path("integration", "gitlab") + .form-group .col-sm-offset-2.col-sm-10 .checkbox = f.label :version_check_enabled do diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index 026c1a5792c..ef6e074c108 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -148,6 +148,7 @@ Settings.gitlab.default_projects_features['snippets'] = false if Settings. Settings.gitlab.default_projects_features['visibility_level'] = Settings.send(:verify_constant, Gitlab::VisibilityLevel, Settings.gitlab.default_projects_features['visibility_level'], Gitlab::VisibilityLevel::PRIVATE) Settings.gitlab['repository_downloads_path'] = File.absolute_path(Settings.gitlab['repository_downloads_path'] || 'tmp/repositories', Rails.root) Settings.gitlab['restricted_signup_domains'] ||= [] +Settings.gitlab['import_sources'] ||= ['github','bitbucket','gitlab','gitorious','google_code','git'] # # Gravatar diff --git a/db/migrate/20150812080800_add_settings_import_sources.rb b/db/migrate/20150812080800_add_settings_import_sources.rb new file mode 100644 index 00000000000..276d2fdb2b1 --- /dev/null +++ b/db/migrate/20150812080800_add_settings_import_sources.rb @@ -0,0 +1,11 @@ +require 'yaml' + +class AddSettingsImportSources < ActiveRecord::Migration + def change + unless column_exists?(:application_settings, :import_sources) + add_column :application_settings, :import_sources, :text + import_sources = YAML::dump(Settings.gitlab['import_sources']) + execute("update application_settings set import_sources = '#{import_sources}'") + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6e919f2883b..fdf09b3afdb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150806104937) do +ActiveRecord::Schema.define(version: 20150812080800) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -44,6 +44,7 @@ ActiveRecord::Schema.define(version: 20150806104937) do t.boolean "user_oauth_applications", default: true t.string "after_sign_out_path" t.integer "session_expire_delay", default: 10080, null: false + t.text "import_sources" end create_table "audit_events", force: true do |t| diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb index 931d51c55d3..1a2a50a14d0 100644 --- a/lib/gitlab/current_settings.rb +++ b/lib/gitlab/current_settings.rb @@ -22,7 +22,8 @@ module Gitlab sign_in_text: Settings.extra['sign_in_text'], restricted_visibility_levels: Settings.gitlab['restricted_visibility_levels'], max_attachment_size: Settings.gitlab['max_attachment_size'], - session_expire_delay: Settings.gitlab['session_expire_delay'] + session_expire_delay: Settings.gitlab['session_expire_delay'], + import_sources: Settings.gitlab['import_sources'] ) end end diff --git a/lib/gitlab/import_sources.rb b/lib/gitlab/import_sources.rb new file mode 100644 index 00000000000..991b70aab6a --- /dev/null +++ b/lib/gitlab/import_sources.rb @@ -0,0 +1,29 @@ +# Gitlab::ImportSources module +# +# Define import sources that can be used +# during the creation of new project +# +module Gitlab + module ImportSources + extend CurrentSettings + + class << self + def values + options.values + end + + def options + { + 'GitHub' => 'github', + 'Bitbucket' => 'bitbucket', + 'GitLab.com' => 'gitlab', + 'Gitorious.org' => 'gitorious', + 'Google Code' => 'google_code', + 'Any repo by URL' => 'git', + } + end + + end + + end +end |