Commit 9304a753d91eea8b2adfe45076b462ef15669c98

Authored by Rodrigo Souto
2 parents 87905aaa 34f625c4

Merge branch 'ldap_fix'

app/models/profile.rb
@@ -404,6 +404,7 @@ class Profile < ActiveRecord::Base @@ -404,6 +404,7 @@ class Profile < ActiveRecord::Base
404 alias_method_chain :template, :default 404 alias_method_chain :template, :default
405 405
406 def apply_template(template, options = {:copy_articles => true}) 406 def apply_template(template, options = {:copy_articles => true})
  407 + self.template = template
407 copy_blocks_from(template) 408 copy_blocks_from(template)
408 copy_articles_from(template) if options[:copy_articles] 409 copy_articles_from(template) if options[:copy_articles]
409 self.apply_type_specific_template(template) 410 self.apply_type_specific_template(template)
plugins/ldap/lib/ldap_plugin.rb
@@ -18,7 +18,8 @@ class LdapPlugin < Noosfero::Plugin @@ -18,7 +18,8 @@ class LdapPlugin < Noosfero::Plugin
18 # - login received by ldap 18 # - login received by ldap
19 # - params from current context 19 # - params from current context
20 # returns = updated person_data hash 20 # returns = updated person_data hash
21 - def ldap_plugin_set_profile_data(attrs, login, params) 21 + def ldap_plugin_set_profile_data(attrs, params)
  22 + [attrs, params]
22 end 23 end
23 24
24 # -> Custom ldap plugin hotspot to update user object 25 # -> Custom ldap plugin hotspot to update user object
@@ -55,19 +56,22 @@ class LdapPlugin < Noosfero::Plugin @@ -55,19 +56,22 @@ class LdapPlugin < Noosfero::Plugin
55 56
56 if attrs 57 if attrs
57 user.login = login 58 user.login = login
58 - user.email = attrs[:mail] 59 + user.email = get_email(attrs, login)
59 user.name = attrs[:fullname] 60 user.name = attrs[:fullname]
60 user.password = password 61 user.password = password
61 user.password_confirmation = password 62 user.password_confirmation = password
62 - person_data = plugins.dispatch(:ldap_plugin_set_profile_data, attrs, login, context.params)  
63 - user.person_data = person_data.blank? ? context.params[:profile_data] : person_data 63 + user.person_data = plugins.pipeline(:ldap_plugin_set_profile_data, attrs, context.params).last[:profile_data]
64 user.activated_at = Time.now.utc 64 user.activated_at = Time.now.utc
65 user.activation_code = nil 65 user.activation_code = nil
66 66
67 ldap = LdapAuthentication.new(context.environment.ldap_plugin_attributes) 67 ldap = LdapAuthentication.new(context.environment.ldap_plugin_attributes)
68 begin 68 begin
69 - user = nil unless user.save!  
70 - plugins.dispatch(:ldap_plugin_update_user, user, attrs) 69 + if user.save
  70 + user.activate
  71 + plugins.dispatch(:ldap_plugin_update_user, user, attrs)
  72 + else
  73 + user = nil
  74 + end
71 rescue 75 rescue
72 #User not saved 76 #User not saved
73 end 77 end
@@ -90,6 +94,16 @@ class LdapPlugin < Noosfero::Plugin @@ -90,6 +94,16 @@ class LdapPlugin < Noosfero::Plugin
90 user 94 user
91 end 95 end
92 96
  97 + def get_email(attrs, login)
  98 + return attrs[:mail] unless attrs[:mail].blank?
  99 +
  100 + if attrs[:fullname]
  101 + return attrs[:fullname].to_slug + "@ldap.user"
  102 + else
  103 + return login.to_slug + "@ldap.user"
  104 + end
  105 + end
  106 +
93 def login_extra_contents 107 def login_extra_contents
94 proc do 108 proc do
95 @person = Person.new(:environment => @environment) 109 @person = Person.new(:environment => @environment)
test/unit/profile_test.rb
@@ -901,6 +901,8 @@ class ProfileTest < ActiveSupport::TestCase @@ -901,6 +901,8 @@ class ProfileTest < ActiveSupport::TestCase
901 901
902 should 'copy set of articles from a template' do 902 should 'copy set of articles from a template' do
903 template = create_user('test_template').person 903 template = create_user('test_template').person
  904 + template.is_template = true
  905 + template.save
904 template.articles.destroy_all 906 template.articles.destroy_all
905 a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') 907 a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article')
906 a2 = fast_create(Article, :profile_id => template.id, :name => 'some child article', :parent_id => a1.id) 908 a2 = fast_create(Article, :profile_id => template.id, :name => 'some child article', :parent_id => a1.id)
@@ -934,6 +936,8 @@ class ProfileTest < ActiveSupport::TestCase @@ -934,6 +936,8 @@ class ProfileTest < ActiveSupport::TestCase
934 936
935 should 'copy homepage from template' do 937 should 'copy homepage from template' do
936 template = create_user('test_template').person 938 template = create_user('test_template').person
  939 + template.is_template = true
  940 + template.save
937 template.articles.destroy_all 941 template.articles.destroy_all
938 a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') 942 a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article')
939 template.home_page = a1 943 template.home_page = a1
@@ -949,6 +953,8 @@ class ProfileTest < ActiveSupport::TestCase @@ -949,6 +953,8 @@ class ProfileTest < ActiveSupport::TestCase
949 953
950 should 'not advertise the articles copied from templates' do 954 should 'not advertise the articles copied from templates' do
951 template = create_user('test_template').person 955 template = create_user('test_template').person
  956 + template.is_template = true
  957 + template.save
952 template.articles.destroy_all 958 template.articles.destroy_all
953 a = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') 959 a = fast_create(Article, :profile_id => template.id, :name => 'some xyz article')
954 960
@@ -962,7 +968,7 @@ class ProfileTest < ActiveSupport::TestCase @@ -962,7 +968,7 @@ class ProfileTest < ActiveSupport::TestCase
962 end 968 end
963 969
964 should 'copy set of boxes from profile template' do 970 should 'copy set of boxes from profile template' do
965 - template = fast_create(Profile) 971 + template = fast_create(Profile, :is_template => true)
966 template.boxes.destroy_all 972 template.boxes.destroy_all
967 template.boxes << Box.new 973 template.boxes << Box.new
968 template.boxes[0].blocks << Block.new 974 template.boxes[0].blocks << Block.new
@@ -977,7 +983,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -977,7 +983,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
977 end 983 end
978 984
979 should 'copy layout template when applying template' do 985 should 'copy layout template when applying template' do
980 - template = fast_create(Profile) 986 + template = fast_create(Profile, :is_template => true)
981 template.layout_template = 'leftbar' 987 template.layout_template = 'leftbar'
982 template.save! 988 template.save!
983 989
@@ -989,7 +995,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -989,7 +995,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
989 end 995 end
990 996
991 should 'copy blocks when applying template' do 997 should 'copy blocks when applying template' do
992 - template = fast_create(Profile) 998 + template = fast_create(Profile, :is_template => true)
993 template.boxes.destroy_all 999 template.boxes.destroy_all
994 template.boxes << Box.new 1000 template.boxes << Box.new
995 template.boxes[0].blocks << Block.new 1001 template.boxes[0].blocks << Block.new
@@ -1004,7 +1010,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1004,7 +1010,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1004 end 1010 end
1005 1011
1006 should 'copy articles when applying template' do 1012 should 'copy articles when applying template' do
1007 - template = fast_create(Profile) 1013 + template = fast_create(Profile, :is_template => true)
1008 template.articles.create(:name => 'template article') 1014 template.articles.create(:name => 'template article')
1009 template.save! 1015 template.save!
1010 1016
@@ -1016,7 +1022,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1016,7 +1022,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1016 end 1022 end
1017 1023
1018 should 'rename existing articles when applying template' do 1024 should 'rename existing articles when applying template' do
1019 - template = fast_create(Profile) 1025 + template = fast_create(Profile, :is_template => true)
1020 template.boxes.destroy_all 1026 template.boxes.destroy_all
1021 template.boxes << Box.new 1027 template.boxes << Box.new
1022 template.boxes[0].blocks << Block.new 1028 template.boxes[0].blocks << Block.new
@@ -1033,7 +1039,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1033,7 +1039,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1033 end 1039 end
1034 1040
1035 should 'copy header when applying template' do 1041 should 'copy header when applying template' do
1036 - template = fast_create(Profile) 1042 + template = fast_create(Profile, :is_template => true)
1037 template[:custom_header] = '{name}' 1043 template[:custom_header] = '{name}'
1038 template.save! 1044 template.save!
1039 1045
@@ -1047,7 +1053,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1047,7 +1053,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1047 end 1053 end
1048 1054
1049 should 'copy footer when applying template' do 1055 should 'copy footer when applying template' do
1050 - template = create(Profile, :address => 'Template address', :custom_footer => '{address}') 1056 + template = create(Profile, :address => 'Template address', :custom_footer => '{address}', :is_template => true)
1051 1057
1052 p = create(Profile, :address => 'Profile address') 1058 p = create(Profile, :address => 'Profile address')
1053 p.apply_template(template) 1059 p.apply_template(template)
@@ -1058,7 +1064,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1058,7 +1064,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1058 end 1064 end
1059 1065
1060 should 'ignore failing validation when applying template' do 1066 should 'ignore failing validation when applying template' do
1061 - template = create(Profile, :layout_template => 'leftbar', :custom_footer => 'my custom footer', :custom_header => 'my custom header') 1067 + template = create(Profile, :layout_template => 'leftbar', :custom_footer => 'my custom footer', :custom_header => 'my custom header', :is_template => true)
1062 1068
1063 p = create(Profile) 1069 p = create(Profile)
1064 def p.validate 1070 def p.validate
@@ -1074,7 +1080,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1074,7 +1080,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1074 end 1080 end
1075 1081
1076 should 'copy homepage when applying template' do 1082 should 'copy homepage when applying template' do
1077 - template = fast_create(Profile) 1083 + template = fast_create(Profile, :is_template => true)
1078 a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') 1084 a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article')
1079 template.home_page = a1 1085 template.home_page = a1
1080 template.save! 1086 template.save!
@@ -1161,7 +1167,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1161,7 +1167,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1161 end 1167 end
1162 1168
1163 should 'copy public/private setting from template' do 1169 should 'copy public/private setting from template' do
1164 - template = fast_create(Profile, :public_profile => false) 1170 + template = fast_create(Profile, :public_profile => false, :is_template => true)
1165 p = fast_create(Profile) 1171 p = fast_create(Profile)
1166 p.apply_template(template) 1172 p.apply_template(template)
1167 assert_equal false, p.public_profile 1173 assert_equal false, p.public_profile