Commit 9304a753d91eea8b2adfe45076b462ef15669c98
Exists in
master
and in
26 other branches
Merge branch 'ldap_fix'
Showing
3 changed files
with
37 additions
and
16 deletions
Show diff stats
app/models/profile.rb
... | ... | @@ -404,6 +404,7 @@ class Profile < ActiveRecord::Base |
404 | 404 | alias_method_chain :template, :default |
405 | 405 | |
406 | 406 | def apply_template(template, options = {:copy_articles => true}) |
407 | + self.template = template | |
407 | 408 | copy_blocks_from(template) |
408 | 409 | copy_articles_from(template) if options[:copy_articles] |
409 | 410 | self.apply_type_specific_template(template) | ... | ... |
plugins/ldap/lib/ldap_plugin.rb
... | ... | @@ -18,7 +18,8 @@ class LdapPlugin < Noosfero::Plugin |
18 | 18 | # - login received by ldap |
19 | 19 | # - params from current context |
20 | 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 | 23 | end |
23 | 24 | |
24 | 25 | # -> Custom ldap plugin hotspot to update user object |
... | ... | @@ -55,19 +56,22 @@ class LdapPlugin < Noosfero::Plugin |
55 | 56 | |
56 | 57 | if attrs |
57 | 58 | user.login = login |
58 | - user.email = attrs[:mail] | |
59 | + user.email = get_email(attrs, login) | |
59 | 60 | user.name = attrs[:fullname] |
60 | 61 | user.password = password |
61 | 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 | 64 | user.activated_at = Time.now.utc |
65 | 65 | user.activation_code = nil |
66 | 66 | |
67 | 67 | ldap = LdapAuthentication.new(context.environment.ldap_plugin_attributes) |
68 | 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 | 75 | rescue |
72 | 76 | #User not saved |
73 | 77 | end |
... | ... | @@ -90,6 +94,16 @@ class LdapPlugin < Noosfero::Plugin |
90 | 94 | user |
91 | 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 | 107 | def login_extra_contents |
94 | 108 | proc do |
95 | 109 | @person = Person.new(:environment => @environment) | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -901,6 +901,8 @@ class ProfileTest < ActiveSupport::TestCase |
901 | 901 | |
902 | 902 | should 'copy set of articles from a template' do |
903 | 903 | template = create_user('test_template').person |
904 | + template.is_template = true | |
905 | + template.save | |
904 | 906 | template.articles.destroy_all |
905 | 907 | a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') |
906 | 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 | 936 | |
935 | 937 | should 'copy homepage from template' do |
936 | 938 | template = create_user('test_template').person |
939 | + template.is_template = true | |
940 | + template.save | |
937 | 941 | template.articles.destroy_all |
938 | 942 | a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') |
939 | 943 | template.home_page = a1 |
... | ... | @@ -949,6 +953,8 @@ class ProfileTest < ActiveSupport::TestCase |
949 | 953 | |
950 | 954 | should 'not advertise the articles copied from templates' do |
951 | 955 | template = create_user('test_template').person |
956 | + template.is_template = true | |
957 | + template.save | |
952 | 958 | template.articles.destroy_all |
953 | 959 | a = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') |
954 | 960 | |
... | ... | @@ -962,7 +968,7 @@ class ProfileTest < ActiveSupport::TestCase |
962 | 968 | end |
963 | 969 | |
964 | 970 | should 'copy set of boxes from profile template' do |
965 | - template = fast_create(Profile) | |
971 | + template = fast_create(Profile, :is_template => true) | |
966 | 972 | template.boxes.destroy_all |
967 | 973 | template.boxes << Box.new |
968 | 974 | template.boxes[0].blocks << Block.new |
... | ... | @@ -977,7 +983,7 @@ class ProfileTest < ActiveSupport::TestCase |
977 | 983 | end |
978 | 984 | |
979 | 985 | should 'copy layout template when applying template' do |
980 | - template = fast_create(Profile) | |
986 | + template = fast_create(Profile, :is_template => true) | |
981 | 987 | template.layout_template = 'leftbar' |
982 | 988 | template.save! |
983 | 989 | |
... | ... | @@ -989,7 +995,7 @@ class ProfileTest < ActiveSupport::TestCase |
989 | 995 | end |
990 | 996 | |
991 | 997 | should 'copy blocks when applying template' do |
992 | - template = fast_create(Profile) | |
998 | + template = fast_create(Profile, :is_template => true) | |
993 | 999 | template.boxes.destroy_all |
994 | 1000 | template.boxes << Box.new |
995 | 1001 | template.boxes[0].blocks << Block.new |
... | ... | @@ -1004,7 +1010,7 @@ class ProfileTest < ActiveSupport::TestCase |
1004 | 1010 | end |
1005 | 1011 | |
1006 | 1012 | should 'copy articles when applying template' do |
1007 | - template = fast_create(Profile) | |
1013 | + template = fast_create(Profile, :is_template => true) | |
1008 | 1014 | template.articles.create(:name => 'template article') |
1009 | 1015 | template.save! |
1010 | 1016 | |
... | ... | @@ -1016,7 +1022,7 @@ class ProfileTest < ActiveSupport::TestCase |
1016 | 1022 | end |
1017 | 1023 | |
1018 | 1024 | should 'rename existing articles when applying template' do |
1019 | - template = fast_create(Profile) | |
1025 | + template = fast_create(Profile, :is_template => true) | |
1020 | 1026 | template.boxes.destroy_all |
1021 | 1027 | template.boxes << Box.new |
1022 | 1028 | template.boxes[0].blocks << Block.new |
... | ... | @@ -1033,7 +1039,7 @@ class ProfileTest < ActiveSupport::TestCase |
1033 | 1039 | end |
1034 | 1040 | |
1035 | 1041 | should 'copy header when applying template' do |
1036 | - template = fast_create(Profile) | |
1042 | + template = fast_create(Profile, :is_template => true) | |
1037 | 1043 | template[:custom_header] = '{name}' |
1038 | 1044 | template.save! |
1039 | 1045 | |
... | ... | @@ -1047,7 +1053,7 @@ class ProfileTest < ActiveSupport::TestCase |
1047 | 1053 | end |
1048 | 1054 | |
1049 | 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 | 1058 | p = create(Profile, :address => 'Profile address') |
1053 | 1059 | p.apply_template(template) |
... | ... | @@ -1058,7 +1064,7 @@ class ProfileTest < ActiveSupport::TestCase |
1058 | 1064 | end |
1059 | 1065 | |
1060 | 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 | 1069 | p = create(Profile) |
1064 | 1070 | def p.validate |
... | ... | @@ -1074,7 +1080,7 @@ class ProfileTest < ActiveSupport::TestCase |
1074 | 1080 | end |
1075 | 1081 | |
1076 | 1082 | should 'copy homepage when applying template' do |
1077 | - template = fast_create(Profile) | |
1083 | + template = fast_create(Profile, :is_template => true) | |
1078 | 1084 | a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') |
1079 | 1085 | template.home_page = a1 |
1080 | 1086 | template.save! |
... | ... | @@ -1161,7 +1167,7 @@ class ProfileTest < ActiveSupport::TestCase |
1161 | 1167 | end |
1162 | 1168 | |
1163 | 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 | 1171 | p = fast_create(Profile) |
1166 | 1172 | p.apply_template(template) |
1167 | 1173 | assert_equal false, p.public_profile | ... | ... |