Commit 82a9151e32a90a9c87ccb7eb083ab1381652f277

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 0f2dfa79

When creating an enterprise apply inactive template

   * Added feature 'enterprises_are_disabled_when_created'
   * After create, when applying template:
      * if enterprise is disabled, apply inactive_template
      * if enterprise is enabled, apply active_template

ActionItem1268
app/models/enterprise.rb
@@ -121,8 +121,19 @@ class Enterprise < Organization @@ -121,8 +121,19 @@ class Enterprise < Organization
121 blocks 121 blocks
122 end 122 end
123 123
  124 + before_create do |enterprise|
  125 + if enterprise.environment.enabled?('enterprises_are_disabled_when_created')
  126 + enterprise.enabled = false
  127 + end
  128 + true
  129 + end
  130 +
124 def template 131 def template
125 - environment.enterprise_template 132 + if enabled?
  133 + environment.enterprise_template
  134 + else
  135 + environment.inactive_enterprise_template
  136 + end
126 end 137 end
127 138
128 settings_items :enable_contact_us, :type => :boolean, :default => true 139 settings_items :enable_contact_us, :type => :boolean, :default => true
app/models/environment.rb
@@ -130,6 +130,7 @@ class Environment < ActiveRecord::Base @@ -130,6 +130,7 @@ class Environment < ActiveRecord::Base
130 'articles_dont_accept_comments_by_default' => _("Articles don't accept comments by default"), 130 'articles_dont_accept_comments_by_default' => _("Articles don't accept comments by default"),
131 'organizations_are_moderated_by_default' => _("Organizations have moderated publication by default"), 131 'organizations_are_moderated_by_default' => _("Organizations have moderated publication by default"),
132 'enable_organization_url_change' => _("Allow organizations to change their address"), 132 'enable_organization_url_change' => _("Allow organizations to change their address"),
  133 + 'enterprises_are_disabled_when_created' => _('Enterprises are disabled when created'),
133 } 134 }
134 end 135 end
135 136
lib/unifreire_terminology.rb
@@ -38,6 +38,7 @@ class UnifreireTerminology < Noosfero::Terminology::Custom @@ -38,6 +38,7 @@ class UnifreireTerminology < Noosfero::Terminology::Custom
38 'Enable Enterprise' => N_('Enable Institution'), 38 'Enable Enterprise' => N_('Enable Institution'),
39 'Enterprise Validation' => N_('Institution Validation'), 39 'Enterprise Validation' => N_('Institution Validation'),
40 'Enterprise Info and settings' => N_('Institution Info and settings'), 40 'Enterprise Info and settings' => N_('Institution Info and settings'),
  41 + 'Enterprises are disabled when created' => N_('Institutions are disabled when created'),
41 }) 42 })
42 end 43 end
43 44
lib/zen3_terminology.rb
@@ -82,6 +82,7 @@ class Zen3Terminology < Noosfero::Terminology::Custom @@ -82,6 +82,7 @@ class Zen3Terminology < Noosfero::Terminology::Custom
82 'Choose the communities you want to join and/or create your own.' => N_('Choose the groups you want to join and/or create your own.'), 82 'Choose the communities you want to join and/or create your own.' => N_('Choose the groups you want to join and/or create your own.'),
83 'New community' => N_('New group'), 83 'New community' => N_('New group'),
84 "Tags are important to new users, they'll be able to find your new community more easily." => N_("Tags are important to new users, they'll be able to find your new group more easily."), 84 "Tags are important to new users, they'll be able to find your new community more easily." => N_("Tags are important to new users, they'll be able to find your new group more easily."),
  85 + 'Enterprises are disabled when created' => N_('Organizations are disabled when created'),
85 }) 86 })
86 end 87 end
87 88
test/unit/enterprise_test.rb
@@ -177,14 +177,17 @@ class EnterpriseTest < Test::Unit::TestCase @@ -177,14 +177,17 @@ class EnterpriseTest < Test::Unit::TestCase
177 end 177 end
178 178
179 should 'not replace template if environment doesnt allow' do 179 should 'not replace template if environment doesnt allow' do
180 - template = Enterprise.create!(:name => 'template enteprise', :identifier => 'template_enterprise', :enabled => false)  
181 - template.boxes.destroy_all  
182 - template.boxes << Box.new  
183 - template.boxes[0].blocks << Block.new  
184 - template.save! 180 + inactive_template = Enterprise.create!(:name => 'inactive enteprise template', :identifier => 'inactive_enterprise_template')
  181 + inactive_template.boxes.destroy_all
  182 + inactive_template.boxes << Box.new
  183 + inactive_template.save!
  184 +
  185 + active_template = Enterprise.create!(:name => 'enteprise template', :identifier => 'enterprise_template')
  186 + assert_equal 3, active_template.boxes.size
185 187
186 e = Environment.default 188 e = Environment.default
187 - e.enterprise_template = template 189 + e.inactive_enterprise_template = inactive_template
  190 + e.enterprise_template = active_template
188 e.save! 191 e.save!
189 192
190 ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false) 193 ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
@@ -193,7 +196,6 @@ class EnterpriseTest &lt; Test::Unit::TestCase @@ -193,7 +196,6 @@ class EnterpriseTest &lt; Test::Unit::TestCase
193 ent.enable(p) 196 ent.enable(p)
194 ent.reload 197 ent.reload
195 assert_equal 1, ent.boxes.size 198 assert_equal 1, ent.boxes.size
196 - assert_equal 1, ent.boxes[0].blocks.size  
197 end 199 end
198 200
199 should 'create EnterpriseActivation task when creating with enabled = false' do 201 should 'create EnterpriseActivation task when creating with enabled = false' do
@@ -329,4 +331,42 @@ class EnterpriseTest &lt; Test::Unit::TestCase @@ -329,4 +331,42 @@ class EnterpriseTest &lt; Test::Unit::TestCase
329 assert_equal 'http://website.with.http', p.organization_website 331 assert_equal 'http://website.with.http', p.organization_website
330 end 332 end
331 333
  334 + should 'be created disabled if feature enterprises_are_disabled_when_created is enabled' do
  335 + e = Environment.default
  336 + e.enable('enterprises_are_disabled_when_created')
  337 + e.save!
  338 +
  339 + ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent')
  340 + assert_equal false, Enterprise['test_ent'].enabled?
  341 + end
  342 +
  343 + should 'have inactive_template when creating enterprise and feature is enabled' do
  344 + inactive_template = Enterprise.create!(:name => 'inactive enteprise template', :identifier => 'inactive_enterprise_template')
  345 + inactive_template.boxes.destroy_all
  346 + inactive_template.boxes << Box.new
  347 + inactive_template.save!
  348 +
  349 + e = Environment.default
  350 + e.enable('enterprises_are_disabled_when_created')
  351 + e.inactive_enterprise_template = inactive_template
  352 + e.save!
  353 +
  354 + ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent')
  355 + assert_equal 1, ent.boxes.size
  356 + end
  357 +
  358 + should 'have active_template when creating enterprise and feature is disabled' do
  359 + inactive_template = Enterprise.create!(:name => 'inactive enteprise template', :identifier => 'inactive_enterprise_template')
  360 + inactive_template.boxes.destroy_all
  361 + inactive_template.boxes << Box.new
  362 + inactive_template.save!
  363 +
  364 + e = Environment.default
  365 + e.disable('enterprises_are_disabled_when_created')
  366 + e.inactive_enterprise_template = inactive_template
  367 + e.save!
  368 +
  369 + ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent')
  370 + assert_equal 3, ent.boxes.size
  371 + end
332 end 372 end