Commit bf1dc29257ec7652392ec9678aa32bd04c8e5756

Authored by Aurélio A. Heckert
Committed by Daniela Feitosa
1 parent 91261f4b

Makes LDAP password_recovery configurable

plugins/ldap/lib/ext/environment.rb
@@ -6,7 +6,7 @@ class Environment @@ -6,7 +6,7 @@ class Environment
6 6
7 validates_presence_of :ldap_plugin_host, :if => lambda {|env| !env.ldap_plugin.blank? } 7 validates_presence_of :ldap_plugin_host, :if => lambda {|env| !env.ldap_plugin.blank? }
8 8
9 - attr_accessible :ldap_plugin_host, :ldap_plugin_port, :ldap_plugin_tls, :ldap_plugin_onthefly_register, :ldap_plugin_account, :ldap_plugin_account_password, :ldap_plugin_filter, :ldap_plugin_base_dn, :ldap_plugin_attr_mail, :ldap_plugin_attr_login, :ldap_plugin_attr_fullname 9 + attr_accessible :ldap_plugin_host, :ldap_plugin_port, :ldap_plugin_tls, :ldap_plugin_onthefly_register, :ldap_plugin_account, :ldap_plugin_account_password, :ldap_plugin_filter, :ldap_plugin_base_dn, :ldap_plugin_attr_mail, :ldap_plugin_attr_login, :ldap_plugin_attr_fullname, :ldap_plugin_allow_password_recovery
10 10
11 def ldap_plugin_attributes 11 def ldap_plugin_attributes
12 self.ldap_plugin || {} 12 self.ldap_plugin || {}
@@ -113,4 +113,13 @@ class Environment @@ -113,4 +113,13 @@ class Environment
113 self.ldap_plugin['tls'] = (value.to_s == '1') ? true : false 113 self.ldap_plugin['tls'] = (value.to_s == '1') ? true : false
114 end 114 end
115 115
  116 + def ldap_plugin_allow_password_recovery
  117 + self.ldap_plugin['allow_password_recovery'] ||= false
  118 + end
  119 +
  120 + def ldap_plugin_allow_password_recovery= value
  121 + self.ldap_plugin = {} if self.ldap_plugin.blank?
  122 + self.ldap_plugin['allow_password_recovery'] = (value.to_i == 1)
  123 + end
  124 +
116 end 125 end
plugins/ldap/lib/ldap_plugin.rb
@@ -36,7 +36,7 @@ class LdapPlugin < Noosfero::Plugin @@ -36,7 +36,7 @@ class LdapPlugin < Noosfero::Plugin
36 end 36 end
37 37
38 def allow_password_recovery 38 def allow_password_recovery
39 - false 39 + context.environment.ldap_plugin['allow_password_recovery']
40 end 40 end
41 41
42 def alternative_authentication 42 def alternative_authentication
plugins/ldap/test/unit/ldap_plugin_test.rb
@@ -9,6 +9,8 @@ class LdapPluginTest < ActiveSupport::TestCase @@ -9,6 +9,8 @@ class LdapPluginTest < ActiveSupport::TestCase
9 9
10 should "not allow password recovery" do 10 should "not allow password recovery" do
11 plugin = LdapPlugin.new 11 plugin = LdapPlugin.new
  12 + plugin.context = mock
  13 + plugin.context.expects(:environment).returns(Environment.default)
12 refute plugin.allow_password_recovery 14 refute plugin.allow_password_recovery
13 end 15 end
14 16
plugins/ldap/views/ldap_plugin_admin/index.html.erb
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 4
5 <table> 5 <table>
6 <tr> 6 <tr>
7 - <th><%= c_('Configuration') %></th> 7 + <th><%= _('LDAP Configuration') %></th>
8 <th><%= _('Value') %></th> 8 <th><%= _('Value') %></th>
9 </tr> 9 </tr>
10 <tr> 10 <tr>
@@ -43,7 +43,8 @@ @@ -43,7 +43,8 @@
43 43
44 <table> 44 <table>
45 <tr> 45 <tr>
46 - <th colspan='2'> <%= _('Attributes') %> </th> 46 + <th><%= _('Attributes') %></th>
  47 + <th><%= _('LDAP Field') %></th>
47 </tr> 48 </tr>
48 <tr> 49 <tr>
49 <td><%= c_('Login') %></td> 50 <td><%= c_('Login') %></td>
@@ -59,6 +60,18 @@ @@ -59,6 +60,18 @@
59 </tr> 60 </tr>
60 </table> 61 </table>
61 62
  63 +<table>
  64 + <tr>
  65 + <th><%= _('Behaviour Configuration') %></th>
  66 + </tr>
  67 + <tr>
  68 + <td><label>
  69 + <%= check_box :environment, :ldap_plugin_allow_password_recovery, {}, '1', '0' %>
  70 + <%= _('Allow password recovery') %>
  71 + </label></td>
  72 + </tr>
  73 +</table>
  74 +
62 <div> 75 <div>
63 <% button_bar do %> 76 <% button_bar do %>
64 <%= submit_button('save', c_('Save changes')) %> 77 <%= submit_button('save', c_('Save changes')) %>