Allow Repository.disabled_types to be strings

When passing configuration settings through ENV (e.g., packager), we
can't pass arrays as configuration settings.

This PR allows `Repository.disabled_types` to be set as a String in ENV,
e.g., through
`OPENPROJECT_SCM_SUBVERSION_DISABLED__TYPES='existing,foobar'`.
pull/4157/head
Oliver Günther 9 years ago
parent 49e0db4cbe
commit 04398738f2
  1. 8
      app/models/repository.rb
  2. 1
      config/configuration.yml.example
  3. 10
      spec/models/repository/git_spec.rb
  4. 10
      spec/models/repository/subversion_spec.rb

@ -109,7 +109,13 @@ class Repository < ActiveRecord::Base
# Retrieves the :disabled_types setting from `configuration.yml
# To avoid wrong set operations for string-based configuration, force them to symbols.
def self.disabled_types
(scm_config[:disabled_types] || []).map(&:to_sym)
disabled = scm_config[:disabled_types]
if disabled.is_a?(String)
disabled.split(',')
else
(disabled || [])
end.map(&:to_sym)
end
def vendor

@ -253,6 +253,7 @@ default:
# disabled_types:
# Disable specific repository types for this particular vendor. This allows
# to restrict the available choices a project administrator has for creating repositories
# May be set as a YAML list of types or several types, separated by comma.
# See the example below for available types.
#
# Available types for git:

@ -96,6 +96,16 @@ describe Repository::Git, type: :model do
end
end
context 'with string disabled types' do
let(:config) { { disabled_types: 'managed,local' } }
it 'is no longer manageable' do
expect(instance.class.available_types).to eq([])
expect(instance.class.disabled_types).to eq([:managed, :local])
expect(instance.manageable?).to be false
end
end
context 'and associated project' do
before do
instance.project = project

@ -72,6 +72,16 @@ describe Repository::Subversion, type: :model do
expect(instance.class.available_types).to be_empty
end
end
context 'with string disabled types' do
let(:config) { { disabled_types: 'managed,unknowntype' } }
it 'is no longer manageable' do
expect(instance.class.available_types).to eq([:existing])
expect(instance.class.disabled_types).to eq([:managed, :unknowntype])
expect(instance.manageable?).to be false
end
end
end
describe 'managed Subversion' do

Loading…
Cancel
Save