diff --git a/app/models/environment.rb b/app/models/environment.rb
index de44118..0f6e45c 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -86,6 +86,38 @@ class Environment < ActiveRecord::Base
def has_terms_of_use?
! self.settings['terms_of_use'].nil?
end
+
+ # returns the approval method used for this environment. Possible values are:
+ #
+ # Defaults to :admim.
+ def organization_approval_method
+ self.settings['organization_approval_method'] || :admin
+ end
+
+ # Sets the organization_approval_method. Only accepts the following values:
+ #
+ # * :admin: organization registration must be approved by the
+ # environment administrator.
+ # * :region: organization registering must be approved by some other
+ # organization asssigned as validator to the Region the new organization
+ # belongs to.
+ #
+ # Trying to set organization_approval_method to any other value will raise an
+ # ArgumentError.
+ #
+ # The value passed as argument is converted to a Symbol before being actually
+ # set to this setting.
+ def organization_approval_method=(value)
+ actual_value = value.to_sym
+
+ accepted_values = %w[
+ admin
+ region
+ ].map(&:to_sym)
+ raise ArgumentError unless accepted_values.include?(actual_value)
+
+ self.settings['organization_approval_method'] = actual_value
+ end
# #################################################
# Validations
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index 8516c66..837e6c3 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -145,4 +145,28 @@ class EnvironmentTest < Test::Unit::TestCase
assert_equal 'localhost.localdomain', env.default_hostname
end
+ should 'provide an approval_method setting' do
+ env = Environment.new
+
+ # default value
+ assert_equal :admin, env.organization_approval_method
+
+ # valid values
+ assert_nothing_raised do
+ valid = %w[
+ admin
+ region
+ ].each do |item|
+ env.organization_approval_method = item
+ env.organization_approval_method = item.to_sym
+ end
+ end
+
+ # do not allow other values
+ assert_raise ArgumentError do
+ env.organization_approval_method = :lalala
+ end
+
+ end
+
end
--
libgit2 0.21.2