From 82a9151e32a90a9c87ccb7eb083ab1381652f277 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Thu, 5 Nov 2009 14:25:14 -0300 Subject: [PATCH] When creating an enterprise apply inactive template --- app/models/enterprise.rb | 13 ++++++++++++- app/models/environment.rb | 1 + lib/unifreire_terminology.rb | 1 + lib/zen3_terminology.rb | 1 + test/unit/enterprise_test.rb | 54 +++++++++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 62 insertions(+), 8 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 037d6c3..f1edd9e 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -121,8 +121,19 @@ class Enterprise < Organization blocks end + before_create do |enterprise| + if enterprise.environment.enabled?('enterprises_are_disabled_when_created') + enterprise.enabled = false + end + true + end + def template - environment.enterprise_template + if enabled? + environment.enterprise_template + else + environment.inactive_enterprise_template + end end settings_items :enable_contact_us, :type => :boolean, :default => true diff --git a/app/models/environment.rb b/app/models/environment.rb index af77512..5a63151 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -130,6 +130,7 @@ class Environment < ActiveRecord::Base 'articles_dont_accept_comments_by_default' => _("Articles don't accept comments by default"), 'organizations_are_moderated_by_default' => _("Organizations have moderated publication by default"), 'enable_organization_url_change' => _("Allow organizations to change their address"), + 'enterprises_are_disabled_when_created' => _('Enterprises are disabled when created'), } end diff --git a/lib/unifreire_terminology.rb b/lib/unifreire_terminology.rb index b89f0a4..42b3b49 100644 --- a/lib/unifreire_terminology.rb +++ b/lib/unifreire_terminology.rb @@ -38,6 +38,7 @@ class UnifreireTerminology < Noosfero::Terminology::Custom 'Enable Enterprise' => N_('Enable Institution'), 'Enterprise Validation' => N_('Institution Validation'), 'Enterprise Info and settings' => N_('Institution Info and settings'), + 'Enterprises are disabled when created' => N_('Institutions are disabled when created'), }) end diff --git a/lib/zen3_terminology.rb b/lib/zen3_terminology.rb index a8a3475..2fb8377 100644 --- a/lib/zen3_terminology.rb +++ b/lib/zen3_terminology.rb @@ -82,6 +82,7 @@ class Zen3Terminology < Noosfero::Terminology::Custom '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.'), 'New community' => N_('New group'), "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."), + 'Enterprises are disabled when created' => N_('Organizations are disabled when created'), }) end diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index ece1b5b..9c8eb53 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -177,14 +177,17 @@ class EnterpriseTest < Test::Unit::TestCase end should 'not replace template if environment doesnt allow' do - template = Enterprise.create!(:name => 'template enteprise', :identifier => 'template_enterprise', :enabled => false) - template.boxes.destroy_all - template.boxes << Box.new - template.boxes[0].blocks << Block.new - template.save! + inactive_template = Enterprise.create!(:name => 'inactive enteprise template', :identifier => 'inactive_enterprise_template') + inactive_template.boxes.destroy_all + inactive_template.boxes << Box.new + inactive_template.save! + + active_template = Enterprise.create!(:name => 'enteprise template', :identifier => 'enterprise_template') + assert_equal 3, active_template.boxes.size e = Environment.default - e.enterprise_template = template + e.inactive_enterprise_template = inactive_template + e.enterprise_template = active_template e.save! ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false) @@ -193,7 +196,6 @@ class EnterpriseTest < Test::Unit::TestCase ent.enable(p) ent.reload assert_equal 1, ent.boxes.size - assert_equal 1, ent.boxes[0].blocks.size end should 'create EnterpriseActivation task when creating with enabled = false' do @@ -329,4 +331,42 @@ class EnterpriseTest < Test::Unit::TestCase assert_equal 'http://website.with.http', p.organization_website end + should 'be created disabled if feature enterprises_are_disabled_when_created is enabled' do + e = Environment.default + e.enable('enterprises_are_disabled_when_created') + e.save! + + ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') + assert_equal false, Enterprise['test_ent'].enabled? + end + + should 'have inactive_template when creating enterprise and feature is enabled' do + inactive_template = Enterprise.create!(:name => 'inactive enteprise template', :identifier => 'inactive_enterprise_template') + inactive_template.boxes.destroy_all + inactive_template.boxes << Box.new + inactive_template.save! + + e = Environment.default + e.enable('enterprises_are_disabled_when_created') + e.inactive_enterprise_template = inactive_template + e.save! + + ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') + assert_equal 1, ent.boxes.size + end + + should 'have active_template when creating enterprise and feature is disabled' do + inactive_template = Enterprise.create!(:name => 'inactive enteprise template', :identifier => 'inactive_enterprise_template') + inactive_template.boxes.destroy_all + inactive_template.boxes << Box.new + inactive_template.save! + + e = Environment.default + e.disable('enterprises_are_disabled_when_created') + e.inactive_enterprise_template = inactive_template + e.save! + + ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') + assert_equal 3, ent.boxes.size + end end -- libgit2 0.21.2