[noosfero/noosfero][master] 3 commits: Fix ldap plugin hotspot behaviour

Rodrigo Souto gitlab at gitlab.com
Fri May 8 18:53:00 BRT 2015


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
141fa98c by Arthur Del Esposte at 2015-05-05T21:03:05Z
Fix ldap plugin hotspot behaviour

- - - - -
34f625c4 by Arthur Del Esposte at 2015-05-05T21:04:59Z
Add template reference when aplly template to profile

- - - - -
9304a753 by Rodrigo Souto at 2015-05-08T18:50:08Z
Merge branch 'ldap_fix'

- - - - -


3 changed files:

- app/models/profile.rb
- plugins/ldap/lib/ldap_plugin.rb
- test/unit/profile_test.rb


Changes:

=====================================
app/models/profile.rb
=====================================
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -404,6 +404,7 @@ class Profile < ActiveRecord::Base
   alias_method_chain :template, :default
 
   def apply_template(template, options = {:copy_articles => true})
+    self.template = template
     copy_blocks_from(template)
     copy_articles_from(template) if options[:copy_articles]
     self.apply_type_specific_template(template)


=====================================
plugins/ldap/lib/ldap_plugin.rb
=====================================
--- a/plugins/ldap/lib/ldap_plugin.rb
+++ b/plugins/ldap/lib/ldap_plugin.rb
@@ -18,7 +18,8 @@ class LdapPlugin < Noosfero::Plugin
     # - login received by ldap
     # - params from current context
     # returns = updated person_data hash
-    def ldap_plugin_set_profile_data(attrs, login, params)
+    def ldap_plugin_set_profile_data(attrs, params)
+      [attrs, params]
     end
 
     # -> Custom ldap plugin hotspot to update user object
@@ -55,19 +56,22 @@ class LdapPlugin < Noosfero::Plugin
 
       if attrs
         user.login = login
-        user.email = attrs[:mail]
+        user.email = get_email(attrs, login)
         user.name =  attrs[:fullname]
         user.password = password
         user.password_confirmation = password
-        person_data = plugins.dispatch(:ldap_plugin_set_profile_data, attrs, login, context.params)
-        user.person_data = person_data.blank? ? context.params[:profile_data] : person_data
+        user.person_data = plugins.pipeline(:ldap_plugin_set_profile_data, attrs, context.params).last[:profile_data]
         user.activated_at = Time.now.utc
         user.activation_code = nil
 
         ldap = LdapAuthentication.new(context.environment.ldap_plugin_attributes)
         begin
-          user = nil unless user.save!
-          plugins.dispatch(:ldap_plugin_update_user, user, attrs)
+          if user.save
+            user.activate
+            plugins.dispatch(:ldap_plugin_update_user, user, attrs)
+          else
+            user = nil
+          end
         rescue
           #User not saved
         end
@@ -90,6 +94,16 @@ class LdapPlugin < Noosfero::Plugin
     user
   end
 
+  def get_email(attrs, login)
+    return attrs[:mail] unless attrs[:mail].blank?
+
+    if attrs[:fullname]
+      return attrs[:fullname].to_slug + "@ldap.user"
+    else
+      return login.to_slug + "@ldap.user"
+    end
+  end
+
   def login_extra_contents
     proc do
       @person = Person.new(:environment => @environment)


=====================================
test/unit/profile_test.rb
=====================================
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -901,6 +901,8 @@ class ProfileTest < ActiveSupport::TestCase
 
   should 'copy set of articles from a template' do
     template = create_user('test_template').person
+    template.is_template = true
+    template.save
     template.articles.destroy_all
     a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article')
     a2 = fast_create(Article, :profile_id => template.id, :name => 'some child article', :parent_id => a1.id)
@@ -934,6 +936,8 @@ class ProfileTest < ActiveSupport::TestCase
 
   should 'copy homepage from template' do
     template = create_user('test_template').person
+    template.is_template = true
+    template.save
     template.articles.destroy_all
     a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article')
     template.home_page = a1
@@ -949,6 +953,8 @@ class ProfileTest < ActiveSupport::TestCase
 
   should 'not advertise the articles copied from templates' do
     template = create_user('test_template').person
+    template.is_template = true
+    template.save
     template.articles.destroy_all
     a = fast_create(Article, :profile_id => template.id, :name => 'some xyz article')
 
@@ -962,7 +968,7 @@ class ProfileTest < ActiveSupport::TestCase
   end
 
   should 'copy set of boxes from profile template' do
-    template = fast_create(Profile)
+    template = fast_create(Profile, :is_template => true)
     template.boxes.destroy_all
     template.boxes << Box.new
     template.boxes[0].blocks << Block.new
@@ -977,7 +983,7 @@ class ProfileTest < ActiveSupport::TestCase
   end
 
   should 'copy layout template when applying template' do
-    template = fast_create(Profile)
+    template = fast_create(Profile, :is_template => true)
     template.layout_template = 'leftbar'
     template.save!
 
@@ -989,7 +995,7 @@ class ProfileTest < ActiveSupport::TestCase
   end
 
   should 'copy blocks when applying template' do
-    template = fast_create(Profile)
+    template = fast_create(Profile, :is_template => true)
     template.boxes.destroy_all
     template.boxes << Box.new
     template.boxes[0].blocks << Block.new
@@ -1004,7 +1010,7 @@ class ProfileTest < ActiveSupport::TestCase
   end
 
   should 'copy articles when applying template' do
-    template = fast_create(Profile)
+    template = fast_create(Profile, :is_template => true)
     template.articles.create(:name => 'template article')
     template.save!
 
@@ -1016,7 +1022,7 @@ class ProfileTest < ActiveSupport::TestCase
   end
 
   should 'rename existing articles when applying template' do
-    template = fast_create(Profile)
+    template = fast_create(Profile, :is_template => true)
     template.boxes.destroy_all
     template.boxes << Box.new
     template.boxes[0].blocks << Block.new
@@ -1033,7 +1039,7 @@ class ProfileTest < ActiveSupport::TestCase
   end
 
   should 'copy header when applying template' do
-    template = fast_create(Profile)
+    template = fast_create(Profile, :is_template => true)
     template[:custom_header] = '{name}'
     template.save!
 
@@ -1047,7 +1053,7 @@ class ProfileTest < ActiveSupport::TestCase
   end
 
   should 'copy footer when applying template' do
-    template = create(Profile, :address => 'Template address', :custom_footer => '{address}')
+    template = create(Profile, :address => 'Template address', :custom_footer => '{address}', :is_template => true)
 
     p = create(Profile, :address => 'Profile address')
     p.apply_template(template)
@@ -1058,7 +1064,7 @@ class ProfileTest < ActiveSupport::TestCase
   end
 
   should 'ignore failing validation when applying template' do
-    template = create(Profile, :layout_template => 'leftbar', :custom_footer => 'my custom footer', :custom_header => 'my custom header')
+    template = create(Profile, :layout_template => 'leftbar', :custom_footer => 'my custom footer', :custom_header => 'my custom header', :is_template => true)
 
     p = create(Profile)
     def p.validate
@@ -1074,7 +1080,7 @@ class ProfileTest < ActiveSupport::TestCase
   end
 
   should 'copy homepage when applying template' do
-    template = fast_create(Profile)
+    template = fast_create(Profile, :is_template => true)
     a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article')
     template.home_page = a1
     template.save!
@@ -1161,7 +1167,7 @@ class ProfileTest < ActiveSupport::TestCase
   end
 
   should 'copy public/private setting from template' do
-    template = fast_create(Profile, :public_profile => false)
+    template = fast_create(Profile, :public_profile => false, :is_template => true)
     p = fast_create(Profile)
     p.apply_template(template)
     assert_equal false, p.public_profile



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/87905aaaa4b2da1c24cb0e98964c5f2f348f5ca5...9304a753d91eea8b2adfe45076b462ef15669c98
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150508/2e3c1db3/attachment.html>


More information about the Noosfero-dev mailing list