diff --git a/app/models/person.rb b/app/models/person.rb index b6b487d..ec0571a 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -220,6 +220,15 @@ class Person < Profile environment.person_template end + def apply_type_specific_template(template) + copy_communities_from(template) + end + + def copy_communities_from(template) + template.communities.each {|community| community.add_member(self)} + end + + def self.with_pending_tasks Person.find(:all).select{ |person| !person.tasks.pending.empty? or person.has_organization_pending_tasks? } end diff --git a/app/models/profile.rb b/app/models/profile.rb index 089ff50..6cbfc7f 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -295,6 +295,7 @@ class Profile < ActiveRecord::Base def apply_template(template, options = {:copy_articles => true}) copy_blocks_from(template) copy_articles_from(template) if options[:copy_articles] + self.apply_type_specific_template(template) # copy interesting attributes self.layout_template = template.layout_template @@ -307,6 +308,9 @@ class Profile < ActiveRecord::Base self.save_without_validation! end + def apply_type_specific_template(template) + end + xss_terminate :only => [ :name, :nickname, :address, :contact_phone, :description ], :on => 'validation' xss_terminate :only => [ :custom_footer, :custom_header ], :with => 'white_list', :on => 'validation' diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 5ec2e9f..021f895 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -953,6 +953,21 @@ class ProfileTest < Test::Unit::TestCase assert_equal 'some child article', child_art.name end + should 'copy communities from person template' do + template = create_user('test_template').person + Environment.any_instance.stubs(:person_template).returns(template) + + c1 = fast_create(Community) + c2 = fast_create(Community) + c1.add_member(template) + c2.add_member(template) + + p = create_user_full('new_user').person + + assert_includes p.communities, c1 + assert_includes p.communities, c2 + end + should 'copy homepage from template' do template = create_user('test_template').person template.articles.destroy_all @@ -1398,7 +1413,7 @@ class ProfileTest < Test::Unit::TestCase end should 'copy header and footer after create a person' do - template = fast_create(Profile) + template = create_user('test_template').person template.custom_footer = "footer customized" template.custom_header = "header customized" Environment.any_instance.stubs(:person_template).returns(template) -- libgit2 0.21.2