##// END OF EJS Templates
Merged LdapAuthSourceController into AuthSourceController....
Jean-Philippe Lang -
r9112:bd47af098fef
parent child
Show More
@@ -17,32 +17,31
17
17
18 class AuthSourcesController < ApplicationController
18 class AuthSourcesController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 menu_item :ldap_authentication
20
21
21 before_filter :require_admin
22 before_filter :require_admin
22
23
23 def index
24 def index
24 @auth_source_pages, @auth_sources = paginate auth_source_class.name.tableize, :per_page => 10
25 @auth_source_pages, @auth_sources = paginate AuthSource, :per_page => 10
25 render "auth_sources/index"
26 end
26 end
27
27
28 def new
28 def new
29 @auth_source = auth_source_class.new
29 klass_name = params[:type] || 'AuthSourceLdap'
30 render 'auth_sources/new'
30 @auth_source = AuthSource.new_subclass_instance(klass_name, params[:auth_source])
31 end
31 end
32
32
33 def create
33 def create
34 @auth_source = auth_source_class.new(params[:auth_source])
34 @auth_source = AuthSource.new_subclass_instance(params[:type], params[:auth_source])
35 if @auth_source.save
35 if @auth_source.save
36 flash[:notice] = l(:notice_successful_create)
36 flash[:notice] = l(:notice_successful_create)
37 redirect_to :action => 'index'
37 redirect_to :action => 'index'
38 else
38 else
39 render 'auth_sources/new'
39 render :action => 'new'
40 end
40 end
41 end
41 end
42
42
43 def edit
43 def edit
44 @auth_source = AuthSource.find(params[:id])
44 @auth_source = AuthSource.find(params[:id])
45 render 'auth_sources/edit'
46 end
45 end
47
46
48 def update
47 def update
@@ -51,14 +50,14 class AuthSourcesController < ApplicationController
51 flash[:notice] = l(:notice_successful_update)
50 flash[:notice] = l(:notice_successful_update)
52 redirect_to :action => 'index'
51 redirect_to :action => 'index'
53 else
52 else
54 render 'auth_sources/edit'
53 render :action => 'edit'
55 end
54 end
56 end
55 end
57
56
58 def test_connection
57 def test_connection
59 @auth_method = AuthSource.find(params[:id])
58 @auth_source = AuthSource.find(params[:id])
60 begin
59 begin
61 @auth_method.test_connection
60 @auth_source.test_connection
62 flash[:notice] = l(:notice_successful_connection)
61 flash[:notice] = l(:notice_successful_connection)
63 rescue Exception => e
62 rescue Exception => e
64 flash[:error] = l(:error_unable_to_connect, e.message)
63 flash[:error] = l(:error_unable_to_connect, e.message)
@@ -74,10 +73,4 class AuthSourcesController < ApplicationController
74 end
73 end
75 redirect_to :action => 'index'
74 redirect_to :action => 'index'
76 end
75 end
77
78 protected
79
80 def auth_source_class
81 AuthSource
82 end
83 end
76 end
@@ -18,4 +18,7
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 module AuthSourcesHelper
20 module AuthSourcesHelper
21 def auth_source_partial_name(auth_source)
22 "form_#{auth_source.class.name.underscore}"
23 end
21 end
24 end
@@ -20,6 +20,7
20 class AuthSourceException < Exception; end
20 class AuthSourceException < Exception; end
21
21
22 class AuthSource < ActiveRecord::Base
22 class AuthSource < ActiveRecord::Base
23 include Redmine::SubclassFactory
23 include Redmine::Ciphering
24 include Redmine::Ciphering
24
25
25 has_many :users
26 has_many :users
1 NO CONTENT: file renamed from app/views/ldap_auth_sources/_form.html.erb to app/views/auth_sources/_form_auth_source_ldap.html.erb
NO CONTENT: file renamed from app/views/ldap_auth_sources/_form.html.erb to app/views/auth_sources/_form_auth_source_ldap.html.erb
@@ -1,7 +1,6
1 <h2><%=l(:label_auth_source)%> (<%= h(@auth_source.auth_method_name) %>)</h2>
1 <h2><%=l(:label_auth_source)%> (<%= h(@auth_source.auth_method_name) %>)</h2>
2
2
3 <% form_tag({:action => 'update', :id => @auth_source}, :class => "tabular") do %>
3 <% form_tag({:action => 'update', :id => @auth_source}, :class => "tabular") do %>
4 <%= render :partial => 'form' %>
4 <%= render :partial => auth_source_partial_name(@auth_source) %>
5 <%= submit_tag l(:button_save) %>
5 <%= submit_tag l(:button_save) %>
6 <% end %>
6 <% end %>
7
@@ -1,6 +1,7
1 <h2><%=l(:label_auth_source_new)%> (<%= h(@auth_source.auth_method_name) %>)</h2>
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 <% form_tag({:action => 'create'}, :class => "tabular") do %>
4 <%= render :partial => 'form' %>
4 <%= hidden_field_tag 'type', @auth_source.type %>
5 <%= render :partial => auth_source_partial_name(@auth_source) %>
5 <%= submit_tag l(:button_create) %>
6 <%= submit_tag l(:button_create) %>
6 <% end %>
7 <% end %>
@@ -370,21 +370,6 ActionController::Routing::Routes.draw do |map|
370 map.connect 'auth_sources/update/:id', :controller => 'auth_sources',
370 map.connect 'auth_sources/update/:id', :controller => 'auth_sources',
371 :action => 'update', :id => /\d+/, :conditions => {:method => :post}
371 :action => 'update', :id => /\d+/, :conditions => {:method => :post}
372
372
373 map.connect 'ldap_auth_sources', :controller => 'ldap_auth_sources',
374 :action => 'index', :conditions => {:method => :get}
375 map.connect 'ldap_auth_sources/new', :controller => 'ldap_auth_sources',
376 :action => 'new', :conditions => {:method => :get}
377 map.connect 'ldap_auth_sources/create', :controller => 'ldap_auth_sources',
378 :action => 'create', :conditions => {:method => :post}
379 map.connect 'ldap_auth_sources/destroy/:id', :controller => 'ldap_auth_sources',
380 :action => 'destroy', :id => /\d+/, :conditions => {:method => :post}
381 map.connect 'ldap_auth_sources/test_connection/:id', :controller => 'ldap_auth_sources',
382 :action => 'test_connection', :conditions => {:method => :get}
383 map.connect 'ldap_auth_sources/edit/:id', :controller => 'ldap_auth_sources',
384 :action => 'edit', :id => /\d+/, :conditions => {:method => :get}
385 map.connect 'ldap_auth_sources/update/:id', :controller => 'ldap_auth_sources',
386 :action => 'update', :id => /\d+/, :conditions => {:method => :post}
387
388 map.connect 'workflows', :controller => 'workflows',
373 map.connect 'workflows', :controller => 'workflows',
389 :action => 'index', :conditions => {:method => :get}
374 :action => 'index', :conditions => {:method => :get}
390 map.connect 'workflows/edit', :controller => 'workflows',
375 map.connect 'workflows/edit', :controller => 'workflows',
@@ -182,7 +182,7 Redmine::MenuManager.map :admin_menu do |menu|
182 :html => {:class => 'custom_fields'}
182 :html => {:class => 'custom_fields'}
183 menu.push :enumerations, {:controller => 'enumerations'}
183 menu.push :enumerations, {:controller => 'enumerations'}
184 menu.push :settings, {:controller => 'settings'}
184 menu.push :settings, {:controller => 'settings'}
185 menu.push :ldap_authentication, {:controller => 'ldap_auth_sources', :action => 'index'},
185 menu.push :ldap_authentication, {:controller => 'auth_sources', :action => 'index'},
186 :html => {:class => 'server_authentication'}
186 :html => {:class => 'server_authentication'}
187 menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true
187 menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true
188 menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true
188 menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true
@@ -18,7 +18,7
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class AuthSourcesControllerTest < ActionController::TestCase
20 class AuthSourcesControllerTest < ActionController::TestCase
21 fixtures :users
21 fixtures :users, :auth_sources
22
22
23 def setup
23 def setup
24 @request.session[:user_id] = 1
24 @request.session[:user_id] = 1
@@ -37,54 +37,91 class AuthSourcesControllerTest < ActionController::TestCase
37
37
38 assert_response :success
38 assert_response :success
39 assert_template 'new'
39 assert_template 'new'
40 assert_kind_of AuthSource, assigns(:auth_source)
40
41 assert assigns(:auth_source).new_record?
41 source = assigns(:auth_source)
42 assert_equal AuthSourceLdap, source.class
43 assert source.new_record?
44
45 assert_tag 'input', :attributes => {:name => 'type', :value => 'AuthSourceLdap'}
46 assert_tag 'input', :attributes => {:name => 'auth_source[host]'}
42 end
47 end
43
48
44 def test_create
49 def test_create
45 assert_difference 'AuthSource.count' do
50 assert_difference 'AuthSourceLdap.count' do
46 post :create, :auth_source => {:name => 'Test'}
51 post :create, :type => 'AuthSourceLdap', :auth_source => {:name => 'Test', :host => '127.0.0.1', :port => '389', :attr_login => 'cn'}
52 assert_redirected_to '/auth_sources'
47 end
53 end
48
54
49 assert_redirected_to '/auth_sources'
55 source = AuthSourceLdap.first(:order => 'id DESC')
50 auth_source = AuthSource.first(:order => 'id DESC')
56 assert_equal 'Test', source.name
51 assert_equal 'Test', auth_source.name
57 assert_equal '127.0.0.1', source.host
58 assert_equal 389, source.port
59 assert_equal 'cn', source.attr_login
60 end
61
62 def test_create_with_failure
63 assert_no_difference 'AuthSourceLdap.count' do
64 post :create, :type => 'AuthSourceLdap', :auth_source => {:name => 'Test', :host => '', :port => '389', :attr_login => 'cn'}
65 assert_response :success
66 assert_template 'new'
67 end
68 assert_error_tag :content => /host can't be blank/i
52 end
69 end
53
70
54 def test_edit
71 def test_edit
55 auth_source = AuthSource.create!(:name => 'TestEdit')
72 get :edit, :id => 1
56 get :edit, :id => auth_source.id
57
73
58 assert_response :success
74 assert_response :success
59 assert_template 'edit'
75 assert_template 'edit'
60 assert_equal auth_source, assigns(:auth_source)
76
77 assert_tag 'input', :attributes => {:name => 'auth_source[host]'}
61 end
78 end
62
79
63 def test_update
80 def test_update
64 auth_source = AuthSource.create!(:name => 'TestEdit')
81 post :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '192.168.0.10', :port => '389', :attr_login => 'uid'}
65 post :update, :id => auth_source.id, :auth_source => {:name => 'TestUpdate'}
66
67 assert_redirected_to '/auth_sources'
82 assert_redirected_to '/auth_sources'
68 assert_equal 'TestUpdate', auth_source.reload.name
83
84 source = AuthSourceLdap.find(1)
85 assert_equal 'Renamed', source.name
86 assert_equal '192.168.0.10', source.host
87 end
88
89 def test_update_with_failure
90 post :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '', :port => '389', :attr_login => 'uid'}
91 assert_response :success
92 assert_template 'edit'
93 assert_error_tag :content => /host can't be blank/i
94 end
95
96 def test_destroy
97 assert_difference 'AuthSourceLdap.count', -1 do
98 post :destroy, :id => 1
99 end
69 end
100 end
70
101
71 def test_destroy_without_users
102 def test_destroy_auth_source_in_use
72 auth_source = AuthSource.create!(:name => 'TestEdit')
103 User.find(2).update_attribute :auth_source_id, 1
73 assert_difference 'AuthSource.count', -1 do
104
74 post :destroy, :id => auth_source.id
105 assert_no_difference 'AuthSourceLdap.count' do
106 post :destroy, :id => 1
75 end
107 end
108 end
76
109
110 def test_test_connection
111 AuthSourceLdap.any_instance.stubs(:test_connection).returns(true)
112
113 get :test_connection, :id => 1
77 assert_redirected_to '/auth_sources'
114 assert_redirected_to '/auth_sources'
115 assert_not_nil flash[:notice]
116 assert_match /successful/i, flash[:notice]
78 end
117 end
79
118
80 def test_destroy_with_users
119 def test_test_connection_with_failure
81 auth_source = AuthSource.create!(:name => 'TestEdit')
120 AuthSourceLdap.any_instance.stubs(:test_connection).raises(Exception.new("Something went wrong"))
82 User.find(2).update_attribute :auth_source, auth_source
83 assert_no_difference 'AuthSource.count' do
84 post :destroy, :id => auth_source.id
85 end
86
121
122 get :test_connection, :id => 1
87 assert_redirected_to '/auth_sources'
123 assert_redirected_to '/auth_sources'
88 assert AuthSource.find(auth_source.id)
124 assert_not_nil flash[:error]
125 assert_include '(Something went wrong)', flash[:error]
89 end
126 end
90 end
127 end
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now