##// END OF EJS Templates
Code cleanup in AuthSource controller and views....
Jean-Philippe Lang -
r10767:7775f86a69f1
parent child
Show More
@@ -20,6 +20,7 class AuthSourcesController < ApplicationController
20 20 menu_item :ldap_authentication
21 21
22 22 before_filter :require_admin
23 before_filter :find_auth_source, :only => [:edit, :update, :test_connection, :destroy]
23 24
24 25 def index
25 26 @auth_source_pages, @auth_sources = paginate AuthSource, :per_page => 10
@@ -28,6 +29,7 class AuthSourcesController < ApplicationController
28 29 def new
29 30 klass_name = params[:type] || 'AuthSourceLdap'
30 31 @auth_source = AuthSource.new_subclass_instance(klass_name, params[:auth_source])
32 render_404 unless @auth_source
31 33 end
32 34
33 35 def create
@@ -41,11 +43,9 class AuthSourcesController < ApplicationController
41 43 end
42 44
43 45 def edit
44 @auth_source = AuthSource.find(params[:id])
45 46 end
46 47
47 48 def update
48 @auth_source = AuthSource.find(params[:id])
49 49 if @auth_source.update_attributes(params[:auth_source])
50 50 flash[:notice] = l(:notice_successful_update)
51 51 redirect_to auth_sources_path
@@ -55,7 +55,6 class AuthSourcesController < ApplicationController
55 55 end
56 56
57 57 def test_connection
58 @auth_source = AuthSource.find(params[:id])
59 58 begin
60 59 @auth_source.test_connection
61 60 flash[:notice] = l(:notice_successful_connection)
@@ -66,11 +65,18 class AuthSourcesController < ApplicationController
66 65 end
67 66
68 67 def destroy
69 @auth_source = AuthSource.find(params[:id])
70 68 unless @auth_source.users.exists?
71 69 @auth_source.destroy
72 70 flash[:notice] = l(:notice_successful_delete)
73 71 end
74 72 redirect_to auth_sources_path
75 73 end
74
75 private
76
77 def find_auth_source
78 @auth_source = AuthSource.find(params[:id])
79 rescue ActiveRecord::RecordNotFound
80 render_404
81 end
76 82 end
@@ -1,13 +1,6
1 1 <%= error_messages_for 'auth_source' %>
2 2
3 <div class="box">
4 <!--[form:auth_source]-->
5 <p><label for="auth_source_name"><%=l(:field_name)%> <span class="required">*</span></label>
6 <%= text_field 'auth_source', 'name' %></p>
7
8 <p><label for="auth_source_onthefly_register"><%=l(:field_onthefly)%></label>
9 <%= check_box 'auth_source', 'onthefly_register' %></p>
3 <div class="box tabular">
4 <p><%= f.text_field :name, :required => true %></p>
5 <p><%= f.check_box :onthefly_register, :label => :field_onthefly %></p>
10 6 </div>
11
12 <!--[eoform:auth_source]-->
13
@@ -1,50 +1,24
1 1 <%= error_messages_for 'auth_source' %>
2 2
3 <div class="box">
4 <!--[form:auth_source]-->
5 <p><label for="auth_source_name"><%=l(:field_name)%> <span class="required">*</span></label>
6 <%= text_field 'auth_source', 'name' %></p>
7
8 <p><label for="auth_source_host"><%=l(:field_host)%> <span class="required">*</span></label>
9 <%= text_field 'auth_source', 'host' %></p>
10
11 <p><label for="auth_source_port"><%=l(:field_port)%> <span class="required">*</span></label>
12 <%= text_field 'auth_source', 'port', :size => 6 %> <%= check_box 'auth_source', 'tls' %> LDAPS</p>
13
14 <p><label for="auth_source_account"><%=l(:field_account)%></label>
15 <%= text_field 'auth_source', 'account' %></p>
16
17 <p><label for="auth_source_account_password"><%=l(:field_password)%></label>
18 <%= password_field 'auth_source', 'account_password', :name => 'ignore',
19 :value => ((@auth_source.new_record? || @auth_source.account_password.blank?) ? '' : ('x'*15)),
20 :onfocus => "this.value=''; this.name='auth_source[account_password]';",
21 :onchange => "this.name='auth_source[account_password]';" %></p>
22
23 <p><label for="auth_source_base_dn"><%=l(:field_base_dn)%> <span class="required">*</span></label>
24 <%= text_field 'auth_source', 'base_dn', :size => 60 %></p>
25
26 <p><label for="auth_source_custom_filter"><%=l(:field_auth_source_ldap_filter)%></label>
27 <%= text_field 'auth_source', 'filter', :size => 60 %></p>
28
29 <p><label for="auth_source_timeout"><%=l(:field_timeout)%></label>
30 <%= text_field 'auth_source', 'timeout', :size => 4 %></p>
31
32 <p><label for="auth_source_onthefly_register"><%=l(:field_onthefly)%></label>
33 <%= check_box 'auth_source', 'onthefly_register' %></p>
3 <div class="box tabular">
4 <p><%= f.text_field :name, :required => true %></p>
5 <p><%= f.text_field :host, :required => true %></p>
6 <p><%= f.text_field :port, :required => true, :size => 6 %> <%= f.check_box :tls, :no_label => true %> LDAPS</p>
7 <p><%= f.text_field :account %></p>
8 <p><%= f.password_field :account_password, :label => :field_password,
9 :name => 'dummy_password',
10 :value => ((@auth_source.new_record? || @auth_source.account_password.blank?) ? '' : ('x'*15)),
11 :onfocus => "this.value=''; this.name='auth_source[account_password]';",
12 :onchange => "this.name='auth_source[account_password]';" %></p>
13 <p><%= f.text_field :base_dn, :required => true, :size => 60 %></p>
14 <p><%= f.text_field :filter, :size => 60, :label => :field_auth_source_ldap_filter %></p>
15 <p><%= f.text_field :timeout, :size => 4 %></p>
16 <p><%= f.check_box :onthefly_register, :label => :field_onthefly %></p>
34 17 </div>
35 18
36 <fieldset class="box"><legend><%=l(:label_attribute_plural)%></legend>
37 <p><label for="auth_source_attr_login"><%=l(:field_login)%> <span class="required">*</span></label>
38 <%= text_field 'auth_source', 'attr_login', :size => 20 %></p>
39
40 <p><label for="auth_source_attr_firstname"><%=l(:field_firstname)%></label>
41 <%= text_field 'auth_source', 'attr_firstname', :size => 20 %></p>
42
43 <p><label for="auth_source_attr_lastname"><%=l(:field_lastname)%></label>
44 <%= text_field 'auth_source', 'attr_lastname', :size => 20 %></p>
45
46 <p><label for="auth_source_attr_mail"><%=l(:field_mail)%></label>
47 <%= text_field 'auth_source', 'attr_mail', :size => 20 %></p>
19 <fieldset class="box tabular"><legend><%=l(:label_attribute_plural)%></legend>
20 <p><%= f.text_field :attr_login, :required => true, :size => 20 %></p>
21 <p><%= f.text_field :attr_firstname, :size => 20 %></p>
22 <p><%= f.text_field :attr_lastname, :size => 20 %></p>
23 <p><%= f.text_field :attr_mail, :size => 20 %></p>
48 24 </fieldset>
49 <!--[eoform:auth_source]-->
50
@@ -1,6 +1,6
1 1 <h2><%=l(:label_auth_source)%> (<%= h(@auth_source.auth_method_name) %>)</h2>
2 2
3 <%= form_tag({:action => 'update', :id => @auth_source}, :method => :put, :class => "tabular") do %>
4 <%= render :partial => auth_source_partial_name(@auth_source) %>
3 <%= form_for @auth_source, :as => :auth_source, :url => auth_source_path(@auth_source), :html => {:id => 'auth_source_form'} do |f| %>
4 <%= render :partial => auth_source_partial_name(@auth_source), :locals => { :f => f } %>
5 5 <%= submit_tag l(:button_save) %>
6 6 <% end %>
@@ -20,7 +20,7
20 20 <td align="center"><%= h source.host %></td>
21 21 <td align="center"><%= h source.users.count %></td>
22 22 <td class="buttons">
23 <%= link_to l(:button_test), {:action => 'test_connection', :id => source}, :class => 'icon icon-test' %>
23 <%= link_to l(:button_test), try_connection_auth_source_path(source), :class => 'icon icon-test' %>
24 24 <%= delete_link auth_source_path(source) %>
25 25 </td>
26 26 </tr>
@@ -1,7 +1,7
1 1 <h2><%=l(:label_auth_source_new)%> (<%= h(@auth_source.auth_method_name) %>)</h2>
2 2
3 <%= form_tag({:action => 'create'}, :class => "tabular") do %>
3 <%= labelled_form_for @auth_source, :as => :auth_source, :url => auth_sources_path, :html => {:id => 'auth_source_form'} do |f| %>
4 4 <%= hidden_field_tag 'type', @auth_source.type %>
5 <%= render :partial => auth_source_partial_name(@auth_source) %>
5 <%= render :partial => auth_source_partial_name(@auth_source), :locals => { :f => f } %>
6 6 <%= submit_tag l(:button_create) %>
7 7 <% end %>
@@ -42,8 +42,15 class AuthSourcesControllerTest < ActionController::TestCase
42 42 assert_equal AuthSourceLdap, source.class
43 43 assert source.new_record?
44 44
45 assert_tag 'input', :attributes => {:name => 'type', :value => 'AuthSourceLdap'}
46 assert_tag 'input', :attributes => {:name => 'auth_source[host]'}
45 assert_select 'form#auth_source_form' do
46 assert_select 'input[name=type][value=AuthSourceLdap]'
47 assert_select 'input[name=?]', 'auth_source[host]'
48 end
49 end
50
51 def test_new_with_invalid_type_should_respond_with_404
52 get :new, :type => 'foo'
53 assert_response 404
47 54 end
48 55
49 56 def test_create
@@ -52,7 +59,7 class AuthSourcesControllerTest < ActionController::TestCase
52 59 assert_redirected_to '/auth_sources'
53 60 end
54 61
55 source = AuthSourceLdap.first(:order => 'id DESC')
62 source = AuthSourceLdap.order('id DESC').first
56 63 assert_equal 'Test', source.name
57 64 assert_equal '127.0.0.1', source.host
58 65 assert_equal 389, source.port
@@ -74,7 +81,23 class AuthSourcesControllerTest < ActionController::TestCase
74 81 assert_response :success
75 82 assert_template 'edit'
76 83
77 assert_tag 'input', :attributes => {:name => 'auth_source[host]'}
84 assert_select 'form#auth_source_form' do
85 assert_select 'input[name=?]', 'auth_source[host]'
86 end
87 end
88
89 def test_edit_should_not_contain_password
90 AuthSource.find(1).update_column :account_password, 'secret'
91
92 get :edit, :id => 1
93 assert_response :success
94 assert_select 'input[value=secret]', 0
95 assert_select 'input[name=dummy_password][value=?]', /x+/
96 end
97
98 def test_edit_invalid_should_respond_with_404
99 get :edit, :id => 99
100 assert_response 404
78 101 end
79 102
80 103 def test_update
@@ -96,6 +119,7 class AuthSourcesControllerTest < ActionController::TestCase
96 119 def test_destroy
97 120 assert_difference 'AuthSourceLdap.count', -1 do
98 121 delete :destroy, :id => 1
122 assert_redirected_to '/auth_sources'
99 123 end
100 124 end
101 125
@@ -104,6 +128,7 class AuthSourcesControllerTest < ActionController::TestCase
104 128
105 129 assert_no_difference 'AuthSourceLdap.count' do
106 130 delete :destroy, :id => 1
131 assert_redirected_to '/auth_sources'
107 132 end
108 133 end
109 134
General Comments 0
You need to be logged in to leave comments. Login now