Commit b8e0bdb297ed86059abae6fc853ae51810e6f536

Authored by Antonio Terceiro
2 parents 84dae213 82a9151e

Merge branch 'stable'

Conflicts:

	app/models/environment.rb
app/controllers/public/content_viewer_controller.rb
@@ -97,6 +97,7 @@ class ContentViewerController < ApplicationController @@ -97,6 +97,7 @@ class ContentViewerController < ApplicationController
97 @comment.author = user if logged_in? 97 @comment.author = user if logged_in?
98 @comment.article = @page 98 @comment.article = @page
99 if @comment.save 99 if @comment.save
  100 + @page.touch
100 @comment = nil # clear the comment form 101 @comment = nil # clear the comment form
101 else 102 else
102 @form_div = 'opened' 103 @form_div = 'opened'
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
@@ -131,6 +131,7 @@ class Environment < ActiveRecord::Base @@ -131,6 +131,7 @@ class Environment < ActiveRecord::Base
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 URL"), 132 'enable_organization_url_change' => _("Allow organizations to change their URL"),
133 'admin_must_approve_new_communities' => _("Admin must approve creation of communities"), 133 'admin_must_approve_new_communities' => _("Admin must approve creation of communities"),
  134 + 'enterprises_are_disabled_when_created' => _('Enterprises are disabled when created'),
134 } 135 }
135 end 136 end
136 137
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/functional/content_viewer_controller_test.rb
@@ -873,4 +873,14 @@ class ContentViewerControllerTest < Test::Unit::TestCase @@ -873,4 +873,14 @@ class ContentViewerControllerTest < Test::Unit::TestCase
873 assert_tag :tag => 'a', :content => 'New article' 873 assert_tag :tag => 'a', :content => 'New article'
874 end 874 end
875 875
  876 + should 'touch article after adding a comment' do
  877 + yesterday = Time.now.yesterday
  878 + Article.record_timestamps = false
  879 + page = profile.articles.create(:name => 'myarticle', :body => 'the body of the text', :created_at => yesterday, :updated_at => yesterday)
  880 + Article.record_timestamps = true
  881 +
  882 + login_as('ze')
  883 + post :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :title => 'crap!', :body => 'I think that this article is crap' }
  884 + assert_not_equal yesterday, assigns(:page).updated_at
  885 + end
876 end 886 end
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