Commit cf619ae4c7babe160bea84987d46cf0e31d3b2d8

Authored by Rodrigo Souto
Committed by Antonio Terceiro
1 parent 867ad521

New user copies communities too from person_template

(ActionItem1626)
app/models/person.rb
@@ -220,6 +220,15 @@ class Person < Profile @@ -220,6 +220,15 @@ class Person < Profile
220 environment.person_template 220 environment.person_template
221 end 221 end
222 222
  223 + def apply_type_specific_template(template)
  224 + copy_communities_from(template)
  225 + end
  226 +
  227 + def copy_communities_from(template)
  228 + template.communities.each {|community| community.add_member(self)}
  229 + end
  230 +
  231 +
223 def self.with_pending_tasks 232 def self.with_pending_tasks
224 Person.find(:all).select{ |person| !person.tasks.pending.empty? or person.has_organization_pending_tasks? } 233 Person.find(:all).select{ |person| !person.tasks.pending.empty? or person.has_organization_pending_tasks? }
225 end 234 end
app/models/profile.rb
@@ -295,6 +295,7 @@ class Profile < ActiveRecord::Base @@ -295,6 +295,7 @@ class Profile < ActiveRecord::Base
295 def apply_template(template, options = {:copy_articles => true}) 295 def apply_template(template, options = {:copy_articles => true})
296 copy_blocks_from(template) 296 copy_blocks_from(template)
297 copy_articles_from(template) if options[:copy_articles] 297 copy_articles_from(template) if options[:copy_articles]
  298 + self.apply_type_specific_template(template)
298 299
299 # copy interesting attributes 300 # copy interesting attributes
300 self.layout_template = template.layout_template 301 self.layout_template = template.layout_template
@@ -307,6 +308,9 @@ class Profile < ActiveRecord::Base @@ -307,6 +308,9 @@ class Profile < ActiveRecord::Base
307 self.save_without_validation! 308 self.save_without_validation!
308 end 309 end
309 310
  311 + def apply_type_specific_template(template)
  312 + end
  313 +
310 xss_terminate :only => [ :name, :nickname, :address, :contact_phone, :description ], :on => 'validation' 314 xss_terminate :only => [ :name, :nickname, :address, :contact_phone, :description ], :on => 'validation'
311 xss_terminate :only => [ :custom_footer, :custom_header ], :with => 'white_list', :on => 'validation' 315 xss_terminate :only => [ :custom_footer, :custom_header ], :with => 'white_list', :on => 'validation'
312 316
test/unit/profile_test.rb
@@ -953,6 +953,21 @@ class ProfileTest < Test::Unit::TestCase @@ -953,6 +953,21 @@ class ProfileTest < Test::Unit::TestCase
953 assert_equal 'some child article', child_art.name 953 assert_equal 'some child article', child_art.name
954 end 954 end
955 955
  956 + should 'copy communities from person template' do
  957 + template = create_user('test_template').person
  958 + Environment.any_instance.stubs(:person_template).returns(template)
  959 +
  960 + c1 = fast_create(Community)
  961 + c2 = fast_create(Community)
  962 + c1.add_member(template)
  963 + c2.add_member(template)
  964 +
  965 + p = create_user_full('new_user').person
  966 +
  967 + assert_includes p.communities, c1
  968 + assert_includes p.communities, c2
  969 + end
  970 +
956 should 'copy homepage from template' do 971 should 'copy homepage from template' do
957 template = create_user('test_template').person 972 template = create_user('test_template').person
958 template.articles.destroy_all 973 template.articles.destroy_all
@@ -1398,7 +1413,7 @@ class ProfileTest < Test::Unit::TestCase @@ -1398,7 +1413,7 @@ class ProfileTest < Test::Unit::TestCase
1398 end 1413 end
1399 1414
1400 should 'copy header and footer after create a person' do 1415 should 'copy header and footer after create a person' do
1401 - template = fast_create(Profile) 1416 + template = create_user('test_template').person
1402 template.custom_footer = "footer customized" 1417 template.custom_footer = "footer customized"
1403 template.custom_header = "header customized" 1418 template.custom_header = "header customized"
1404 Environment.any_instance.stubs(:person_template).returns(template) 1419 Environment.any_instance.stubs(:person_template).returns(template)