Commit cf619ae4c7babe160bea84987d46cf0e31d3b2d8
Committed by
Antonio Terceiro
1 parent
867ad521
Exists in
master
and in
28 other branches
New user copies communities too from person_template
(ActionItem1626)
Showing
3 changed files
with
29 additions
and
1 deletions
Show diff stats
app/models/person.rb
| ... | ... | @@ -220,6 +220,15 @@ class Person < Profile |
| 220 | 220 | environment.person_template |
| 221 | 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 | 232 | def self.with_pending_tasks |
| 224 | 233 | Person.find(:all).select{ |person| !person.tasks.pending.empty? or person.has_organization_pending_tasks? } |
| 225 | 234 | end | ... | ... |
app/models/profile.rb
| ... | ... | @@ -295,6 +295,7 @@ class Profile < ActiveRecord::Base |
| 295 | 295 | def apply_template(template, options = {:copy_articles => true}) |
| 296 | 296 | copy_blocks_from(template) |
| 297 | 297 | copy_articles_from(template) if options[:copy_articles] |
| 298 | + self.apply_type_specific_template(template) | |
| 298 | 299 | |
| 299 | 300 | # copy interesting attributes |
| 300 | 301 | self.layout_template = template.layout_template |
| ... | ... | @@ -307,6 +308,9 @@ class Profile < ActiveRecord::Base |
| 307 | 308 | self.save_without_validation! |
| 308 | 309 | end |
| 309 | 310 | |
| 311 | + def apply_type_specific_template(template) | |
| 312 | + end | |
| 313 | + | |
| 310 | 314 | xss_terminate :only => [ :name, :nickname, :address, :contact_phone, :description ], :on => 'validation' |
| 311 | 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 | 953 | assert_equal 'some child article', child_art.name |
| 954 | 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 | 971 | should 'copy homepage from template' do |
| 957 | 972 | template = create_user('test_template').person |
| 958 | 973 | template.articles.destroy_all |
| ... | ... | @@ -1398,7 +1413,7 @@ class ProfileTest < Test::Unit::TestCase |
| 1398 | 1413 | end |
| 1399 | 1414 | |
| 1400 | 1415 | should 'copy header and footer after create a person' do |
| 1401 | - template = fast_create(Profile) | |
| 1416 | + template = create_user('test_template').person | |
| 1402 | 1417 | template.custom_footer = "footer customized" |
| 1403 | 1418 | template.custom_header = "header customized" |
| 1404 | 1419 | Environment.any_instance.stubs(:person_template).returns(template) | ... | ... |