##// END OF EJS Templates
Refactor AuthSourcesController to support non-LDAP sources. #1131...
Eric Davis -
r3630:715c9d16ef2c
parent child
Show More
@@ -0,0 +1,25
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 class LdapAuthSourcesController < AuthSourcesController
19
20 protected
21
22 def auth_source_class
23 AuthSourceLdap
24 end
25 end
@@ -0,0 +1,13
1 <%= error_messages_for 'auth_source' %>
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>
10 </div>
11
12 <!--[eoform:auth_source]-->
13
@@ -0,0 +1,83
1 require 'test_helper'
2
3 class AuthSourcesControllerTest < ActionController::TestCase
4 fixtures :all
5
6 def setup
7 @request.session[:user_id] = 1
8 end
9
10 context "get :index" do
11 setup do
12 get :index
13 end
14
15 should_assign_to :auth_sources
16 should_assign_to :auth_source_pages
17 should_respond_with :success
18 should_render_template :index
19 end
20
21 context "get :new" do
22 setup do
23 get :new
24 end
25
26 should_assign_to :auth_source
27 should_respond_with :success
28 should_render_template :new
29
30 should "initilize a new AuthSource" do
31 assert_equal AuthSource, assigns(:auth_source).class
32 assert assigns(:auth_source).new_record?
33 end
34 end
35
36 context "post :create" do
37 setup do
38 post :create, :auth_source => {:name => 'Test'}
39 end
40
41 should_respond_with :redirect
42 should_redirect_to("index") {{:action => 'index'}}
43 should_set_the_flash_to /success/i
44 end
45
46 context "get :edit" do
47 setup do
48 @auth_source = AuthSource.generate!(:name => 'TestEdit')
49 get :edit, :id => @auth_source.id
50 end
51
52 should_assign_to(:auth_source) {@auth_source}
53 should_respond_with :success
54 should_render_template :edit
55 end
56
57 context "post :update" do
58 setup do
59 @auth_source = AuthSource.generate!(:name => 'TestEdit')
60 post :update, :id => @auth_source.id, :auth_source => {:name => 'TestUpdate'}
61 end
62
63 should_respond_with :redirect
64 should_redirect_to("index") {{:action => 'index'}}
65 should_set_the_flash_to /update/i
66 end
67
68 context "post :destroy" do
69 context "without users" do
70 setup do
71 @auth_source = AuthSource.generate!(:name => 'TestEdit')
72 post :destroy, :id => @auth_source.id
73 end
74
75 should_respond_with :redirect
76 should_redirect_to("index") {{:action => 'index'}}
77 should_set_the_flash_to /deletion/i
78
79 end
80
81 should "be tested with users"
82 end
83 end
@@ -0,0 +1,24
1 require 'test_helper'
2
3 class LdapAuthSourcesControllerTest < ActionController::TestCase
4 fixtures :all
5
6 def setup
7 @request.session[:user_id] = 1
8 end
9
10 context "get :new" do
11 setup do
12 get :new
13 end
14
15 should_assign_to :auth_source
16 should_respond_with :success
17 should_render_template :new
18
19 should "initilize a new AuthSource" do
20 assert_equal AuthSourceLdap, assigns(:auth_source).class
21 assert assigns(:auth_source).new_record?
22 end
23 end
24 end
@@ -1,79 +1,87
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class AuthSourcesController < ApplicationController
18 class AuthSourcesController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20
20
21 before_filter :require_admin
21 before_filter :require_admin
22
22
23 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
23 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
24 verify :method => :post, :only => [ :destroy, :create, :update ],
24 verify :method => :post, :only => [ :destroy, :create, :update ],
25 :redirect_to => { :action => :list }
25 :redirect_to => { :template => :index }
26
26
27 def index
27 def index
28 @auth_source_pages, @auth_sources = paginate :auth_sources, :per_page => 10
28 @auth_source_pages, @auth_sources = paginate auth_source_class.name.tableize, :per_page => 10
29 render :action => "index", :layout => false if request.xhr?
29 render "auth_sources/index"
30 end
30 end
31
31
32 def new
32 def new
33 @auth_source = AuthSourceLdap.new
33 @auth_source = auth_source_class.new
34 render 'auth_sources/new'
34 end
35 end
35
36
36 def create
37 def create
37 @auth_source = AuthSourceLdap.new(params[:auth_source])
38 @auth_source = auth_source_class.new(params[:auth_source])
38 if @auth_source.save
39 if @auth_source.save
39 flash[:notice] = l(:notice_successful_create)
40 flash[:notice] = l(:notice_successful_create)
40 redirect_to :action => 'index'
41 redirect_to :action => 'index'
41 else
42 else
42 render :action => 'new'
43 render 'auth_sources/new'
43 end
44 end
44 end
45 end
45
46
46 def edit
47 def edit
47 @auth_source = AuthSource.find(params[:id])
48 @auth_source = AuthSource.find(params[:id])
49 render 'auth_sources/edit'
48 end
50 end
49
51
50 def update
52 def update
51 @auth_source = AuthSource.find(params[:id])
53 @auth_source = AuthSource.find(params[:id])
52 if @auth_source.update_attributes(params[:auth_source])
54 if @auth_source.update_attributes(params[:auth_source])
53 flash[:notice] = l(:notice_successful_update)
55 flash[:notice] = l(:notice_successful_update)
54 redirect_to :action => 'index'
56 redirect_to :action => 'index'
55 else
57 else
56 render :action => 'edit'
58 render 'auth_sources/edit'
57 end
59 end
58 end
60 end
59
61
60 def test_connection
62 def test_connection
61 @auth_method = AuthSource.find(params[:id])
63 @auth_method = AuthSource.find(params[:id])
62 begin
64 begin
63 @auth_method.test_connection
65 @auth_method.test_connection
64 flash[:notice] = l(:notice_successful_connection)
66 flash[:notice] = l(:notice_successful_connection)
65 rescue => text
67 rescue => text
66 flash[:error] = l(:error_unable_to_connect, text.message)
68 flash[:error] = l(:error_unable_to_connect, text.message)
67 end
69 end
68 redirect_to :action => 'index'
70 redirect_to :action => 'index'
69 end
71 end
70
72
71 def destroy
73 def destroy
72 @auth_source = AuthSource.find(params[:id])
74 @auth_source = AuthSource.find(params[:id])
73 unless @auth_source.users.find(:first)
75 unless @auth_source.users.find(:first)
74 @auth_source.destroy
76 @auth_source.destroy
75 flash[:notice] = l(:notice_successful_delete)
77 flash[:notice] = l(:notice_successful_delete)
76 end
78 end
77 redirect_to :action => 'index'
79 redirect_to :action => 'index'
78 end
80 end
81
82 protected
83
84 def auth_source_class
85 AuthSource
86 end
79 end
87 end
@@ -1,19 +1,20
1 <div id="admin-menu">
1 <div id="admin-menu">
2 <ul>
2 <ul>
3 <li><%= link_to l(:label_project_plural), {:controller => 'admin', :action => 'projects'}, :class => 'projects' %></li>
3 <li><%= link_to l(:label_project_plural), {:controller => 'admin', :action => 'projects'}, :class => 'projects' %></li>
4 <li><%= link_to l(:label_user_plural), {:controller => 'users'}, :class => 'users' %></li>
4 <li><%= link_to l(:label_user_plural), {:controller => 'users'}, :class => 'users' %></li>
5 <li><%= link_to l(:label_group_plural), {:controller => 'groups'}, :class => 'groups' %></li>
5 <li><%= link_to l(:label_group_plural), {:controller => 'groups'}, :class => 'groups' %></li>
6 <li><%= link_to l(:label_ldap_authentication), :controller => 'ldap_auth_sources', :action => 'index' %></li>
6 <li><%= link_to l(:label_role_and_permissions), {:controller => 'roles'}, :class => 'roles' %></li>
7 <li><%= link_to l(:label_role_and_permissions), {:controller => 'roles'}, :class => 'roles' %></li>
7 <li><%= link_to l(:label_tracker_plural), {:controller => 'trackers'}, :class => 'trackers' %></li>
8 <li><%= link_to l(:label_tracker_plural), {:controller => 'trackers'}, :class => 'trackers' %></li>
8 <li><%= link_to l(:label_issue_status_plural), {:controller => 'issue_statuses'}, :class => 'issue_statuses' %></li>
9 <li><%= link_to l(:label_issue_status_plural), {:controller => 'issue_statuses'}, :class => 'issue_statuses' %></li>
9 <li><%= link_to l(:label_workflow), {:controller => 'workflows', :action => 'edit'}, :class => 'workflows' %></li>
10 <li><%= link_to l(:label_workflow), {:controller => 'workflows', :action => 'edit'}, :class => 'workflows' %></li>
10 <li><%= link_to l(:label_custom_field_plural), {:controller => 'custom_fields'}, :class => 'custom_fields' %></li>
11 <li><%= link_to l(:label_custom_field_plural), {:controller => 'custom_fields'}, :class => 'custom_fields' %></li>
11 <li><%= link_to l(:label_enumerations), {:controller => 'enumerations'}, :class => 'enumerations' %></li>
12 <li><%= link_to l(:label_enumerations), {:controller => 'enumerations'}, :class => 'enumerations' %></li>
12 <li><%= link_to l(:label_settings), {:controller => 'settings'}, :class => 'settings' %></li>
13 <li><%= link_to l(:label_settings), {:controller => 'settings'}, :class => 'settings' %></li>
13 <% menu_items_for(:admin_menu) do |item| -%>
14 <% menu_items_for(:admin_menu) do |item| -%>
14 <li><%= link_to h(item.caption), item.url, item.html_options %></li>
15 <li><%= link_to h(item.caption), item.url, item.html_options %></li>
15 <% end -%>
16 <% end -%>
16 <li><%= link_to l(:label_plugins), {:controller => 'admin', :action => 'plugins'}, :class => 'plugins' %></li>
17 <li><%= link_to l(:label_plugins), {:controller => 'admin', :action => 'plugins'}, :class => 'plugins' %></li>
17 <li><%= link_to l(:label_information_plural), {:controller => 'admin', :action => 'info'}, :class => 'info' %></li>
18 <li><%= link_to l(:label_information_plural), {:controller => 'admin', :action => 'info'}, :class => 'info' %></li>
18 </ul>
19 </ul>
19 </div>
20 </div>
1 NO CONTENT: file renamed from app/views/auth_sources/_form.rhtml to app/views/ldap_auth_sources/_form.rhtml
NO CONTENT: file renamed from app/views/auth_sources/_form.rhtml to app/views/ldap_auth_sources/_form.rhtml
@@ -1,27 +1,27
1 <% form_tag({:action => 'edit', :tab => 'authentication'}) do %>
1 <% form_tag({:action => 'edit', :tab => 'authentication'}) do %>
2
2
3 <div class="box tabular settings">
3 <div class="box tabular settings">
4 <p><%= setting_check_box :login_required %></p>
4 <p><%= setting_check_box :login_required %></p>
5
5
6 <p><%= setting_select :autologin, [1, 7, 30, 365].collect{|days| [l('datetime.distance_in_words.x_days', :count => days), days.to_s]}, :blank => :label_disabled %></p>
6 <p><%= setting_select :autologin, [1, 7, 30, 365].collect{|days| [l('datetime.distance_in_words.x_days', :count => days), days.to_s]}, :blank => :label_disabled %></p>
7
7
8 <p><%= setting_select :self_registration, [[l(:label_disabled), "0"],
8 <p><%= setting_select :self_registration, [[l(:label_disabled), "0"],
9 [l(:label_registration_activation_by_email), "1"],
9 [l(:label_registration_activation_by_email), "1"],
10 [l(:label_registration_manual_activation), "2"],
10 [l(:label_registration_manual_activation), "2"],
11 [l(:label_registration_automatic_activation), "3"]] %></p>
11 [l(:label_registration_automatic_activation), "3"]] %></p>
12
12
13 <p><%= setting_text_field :password_min_length, :size => 6 %></p>
13 <p><%= setting_text_field :password_min_length, :size => 6 %></p>
14
14
15 <p><%= setting_check_box :lost_password, :label => :label_password_lost %></p>
15 <p><%= setting_check_box :lost_password, :label => :label_password_lost %></p>
16
16
17 <p><%= setting_check_box :openid, :disabled => !Object.const_defined?(:OpenID) %></p>
17 <p><%= setting_check_box :openid, :disabled => !Object.const_defined?(:OpenID) %></p>
18
18
19 <p><%= setting_check_box :rest_api_enabled %></p>
19 <p><%= setting_check_box :rest_api_enabled %></p>
20 </div>
20 </div>
21
21
22 <div style="float:right;">
22 <div style="float:right;">
23 <%= link_to l(:label_ldap_authentication), :controller => 'auth_sources', :action => 'index' %>
23 <%= link_to l(:label_ldap_authentication), :controller => 'ldap_auth_sources', :action => 'index' %>
24 </div>
24 </div>
25
25
26 <%= submit_tag l(:button_save) %>
26 <%= submit_tag l(:button_save) %>
27 <% end %>
27 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now