Commit be877df5921af90930b0d1cf56b11617a14712c4
1 parent
44266031
Exists in
master
and in
22 other branches
Add a LDAP plugin's hotspots
- A Hotspot to change person_data before user creation - A Hotspot to update the created person by LDAP plugin
Showing
1 changed file
with
24 additions
and
3 deletions
Show diff stats
plugins/ldap/lib/ldap_plugin.rb
| 1 | require File.dirname(__FILE__) + '/ldap_authentication.rb' | 1 | require File.dirname(__FILE__) + '/ldap_authentication.rb' |
| 2 | 2 | ||
| 3 | class LdapPlugin < Noosfero::Plugin | 3 | class LdapPlugin < Noosfero::Plugin |
| 4 | + include Noosfero::Plugin::HotSpot | ||
| 4 | 5 | ||
| 5 | def self.plugin_name | 6 | def self.plugin_name |
| 6 | "LdapPlugin" | 7 | "LdapPlugin" |
| @@ -10,6 +11,25 @@ class LdapPlugin < Noosfero::Plugin | @@ -10,6 +11,25 @@ class LdapPlugin < Noosfero::Plugin | ||
| 10 | _("A plugin that add ldap support.") | 11 | _("A plugin that add ldap support.") |
| 11 | end | 12 | end |
| 12 | 13 | ||
| 14 | + module Hotspots | ||
| 15 | + # -> Custom ldap plugin hotspot to set profile data before user creation | ||
| 16 | + # receive the followings params: | ||
| 17 | + # - attrs with ldap received data | ||
| 18 | + # - login received by ldap | ||
| 19 | + # - params from current context | ||
| 20 | + # returns = updated person_data hash | ||
| 21 | + def ldap_plugin_set_profile_data(attrs, login, params) | ||
| 22 | + end | ||
| 23 | + | ||
| 24 | + # -> Custom ldap plugin hotspot to update user object | ||
| 25 | + # receive the followings params: | ||
| 26 | + # - user: user object | ||
| 27 | + # - attrs with ldap received data | ||
| 28 | + # returns = none | ||
| 29 | + def ldap_plugin_update_user(user, attrs) | ||
| 30 | + end | ||
| 31 | + end | ||
| 32 | + | ||
| 13 | def allow_user_registration | 33 | def allow_user_registration |
| 14 | false | 34 | false |
| 15 | end | 35 | end |
| @@ -39,13 +59,15 @@ class LdapPlugin < Noosfero::Plugin | @@ -39,13 +59,15 @@ class LdapPlugin < Noosfero::Plugin | ||
| 39 | user.name = attrs[:fullname] | 59 | user.name = attrs[:fullname] |
| 40 | user.password = password | 60 | user.password = password |
| 41 | user.password_confirmation = password | 61 | user.password_confirmation = password |
| 42 | - user.person_data = context.params[:profile_data] | 62 | + person_data = plugins.dispatch(:ldap_plugin_set_profile_data, attrs, login, context.params) |
| 63 | + user.person_data = person_data.nil? ? context.params[:profile_data] : person_data | ||
| 43 | user.activated_at = Time.now.utc | 64 | user.activated_at = Time.now.utc |
| 44 | user.activation_code = nil | 65 | user.activation_code = nil |
| 45 | 66 | ||
| 46 | ldap = LdapAuthentication.new(context.environment.ldap_plugin_attributes) | 67 | ldap = LdapAuthentication.new(context.environment.ldap_plugin_attributes) |
| 47 | begin | 68 | begin |
| 48 | - user = nil unless user.save | 69 | + user = nil unless user.save! |
| 70 | + plugins.dispatch(:ldap_plugin_update_user, user, attrs) | ||
| 49 | rescue | 71 | rescue |
| 50 | #User not saved | 72 | #User not saved |
| 51 | end | 73 | end |
| @@ -54,7 +76,6 @@ class LdapPlugin < Noosfero::Plugin | @@ -54,7 +76,6 @@ class LdapPlugin < Noosfero::Plugin | ||
| 54 | end | 76 | end |
| 55 | 77 | ||
| 56 | else | 78 | else |
| 57 | - | ||
| 58 | return nil if !user.activated? | 79 | return nil if !user.activated? |
| 59 | 80 | ||
| 60 | begin | 81 | begin |