Commit a54592c43855cf983d85c1720c5853151889f031
1 parent
0f3f61b4
Exists in
staging
and in
42 other branches
ActionItem103: implementing organization_approval_method setting
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@653 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
56 additions
and
0 deletions
Show diff stats
app/models/environment.rb
| ... | ... | @@ -86,6 +86,38 @@ class Environment < ActiveRecord::Base |
| 86 | 86 | def has_terms_of_use? |
| 87 | 87 | ! self.settings['terms_of_use'].nil? |
| 88 | 88 | end |
| 89 | + | |
| 90 | + # returns the approval method used for this environment. Possible values are: | |
| 91 | + # | |
| 92 | + # Defaults to <tt>:admim</tt>. | |
| 93 | + def organization_approval_method | |
| 94 | + self.settings['organization_approval_method'] || :admin | |
| 95 | + end | |
| 96 | + | |
| 97 | + # Sets the organization_approval_method. Only accepts the following values: | |
| 98 | + # | |
| 99 | + # * <tt>:admin</tt>: organization registration must be approved by the | |
| 100 | + # environment administrator. | |
| 101 | + # * <tt>:region</tt>: organization registering must be approved by some other | |
| 102 | + # organization asssigned as validator to the Region the new organization | |
| 103 | + # belongs to. | |
| 104 | + # | |
| 105 | + # Trying to set organization_approval_method to any other value will raise an | |
| 106 | + # ArgumentError. | |
| 107 | + # | |
| 108 | + # The value passed as argument is converted to a Symbol before being actually | |
| 109 | + # set to this setting. | |
| 110 | + def organization_approval_method=(value) | |
| 111 | + actual_value = value.to_sym | |
| 112 | + | |
| 113 | + accepted_values = %w[ | |
| 114 | + admin | |
| 115 | + region | |
| 116 | + ].map(&:to_sym) | |
| 117 | + raise ArgumentError unless accepted_values.include?(actual_value) | |
| 118 | + | |
| 119 | + self.settings['organization_approval_method'] = actual_value | |
| 120 | + end | |
| 89 | 121 | |
| 90 | 122 | # ################################################# |
| 91 | 123 | # Validations | ... | ... |
test/unit/environment_test.rb
| ... | ... | @@ -145,4 +145,28 @@ class EnvironmentTest < Test::Unit::TestCase |
| 145 | 145 | assert_equal 'localhost.localdomain', env.default_hostname |
| 146 | 146 | end |
| 147 | 147 | |
| 148 | + should 'provide an approval_method setting' do | |
| 149 | + env = Environment.new | |
| 150 | + | |
| 151 | + # default value | |
| 152 | + assert_equal :admin, env.organization_approval_method | |
| 153 | + | |
| 154 | + # valid values | |
| 155 | + assert_nothing_raised do | |
| 156 | + valid = %w[ | |
| 157 | + admin | |
| 158 | + region | |
| 159 | + ].each do |item| | |
| 160 | + env.organization_approval_method = item | |
| 161 | + env.organization_approval_method = item.to_sym | |
| 162 | + end | |
| 163 | + end | |
| 164 | + | |
| 165 | + # do not allow other values | |
| 166 | + assert_raise ArgumentError do | |
| 167 | + env.organization_approval_method = :lalala | |
| 168 | + end | |
| 169 | + | |
| 170 | + end | |
| 171 | + | |
| 148 | 172 | end | ... | ... |