Mercurial > hg > soundsoftware-site
comparison app/controllers/auth_sources_controller.rb @ 1338:25603efa57b5
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 20 Jun 2013 13:14:14 +0100 |
parents | 433d4f72a19b |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
1209:1b1138f6f55e | 1338:25603efa57b5 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 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. |
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 menu_item :ldap_authentication | |
20 | 21 |
21 before_filter :require_admin | 22 before_filter :require_admin |
22 | 23 |
23 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) | |
24 verify :method => :post, :only => [ :destroy, :create, :update ], | |
25 :redirect_to => { :template => :index } | |
26 | |
27 def index | 24 def index |
28 @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 |
29 render "auth_sources/index" | |
30 end | 26 end |
31 | 27 |
32 def new | 28 def new |
33 @auth_source = auth_source_class.new | 29 klass_name = params[:type] || 'AuthSourceLdap' |
34 render 'auth_sources/new' | 30 @auth_source = AuthSource.new_subclass_instance(klass_name, params[:auth_source]) |
35 end | 31 end |
36 | 32 |
37 def create | 33 def create |
38 @auth_source = auth_source_class.new(params[:auth_source]) | 34 @auth_source = AuthSource.new_subclass_instance(params[:type], params[:auth_source]) |
39 if @auth_source.save | 35 if @auth_source.save |
40 flash[:notice] = l(:notice_successful_create) | 36 flash[:notice] = l(:notice_successful_create) |
41 redirect_to :action => 'index' | 37 redirect_to :action => 'index' |
42 else | 38 else |
43 render 'auth_sources/new' | 39 render :action => 'new' |
44 end | 40 end |
45 end | 41 end |
46 | 42 |
47 def edit | 43 def edit |
48 @auth_source = AuthSource.find(params[:id]) | 44 @auth_source = AuthSource.find(params[:id]) |
49 render 'auth_sources/edit' | |
50 end | 45 end |
51 | 46 |
52 def update | 47 def update |
53 @auth_source = AuthSource.find(params[:id]) | 48 @auth_source = AuthSource.find(params[:id]) |
54 if @auth_source.update_attributes(params[:auth_source]) | 49 if @auth_source.update_attributes(params[:auth_source]) |
55 flash[:notice] = l(:notice_successful_update) | 50 flash[:notice] = l(:notice_successful_update) |
56 redirect_to :action => 'index' | 51 redirect_to :action => 'index' |
57 else | 52 else |
58 render 'auth_sources/edit' | 53 render :action => 'edit' |
59 end | 54 end |
60 end | 55 end |
61 | 56 |
62 def test_connection | 57 def test_connection |
63 @auth_method = AuthSource.find(params[:id]) | 58 @auth_source = AuthSource.find(params[:id]) |
64 begin | 59 begin |
65 @auth_method.test_connection | 60 @auth_source.test_connection |
66 flash[:notice] = l(:notice_successful_connection) | 61 flash[:notice] = l(:notice_successful_connection) |
67 rescue => text | 62 rescue Exception => e |
68 flash[:error] = l(:error_unable_to_connect, text.message) | 63 flash[:error] = l(:error_unable_to_connect, e.message) |
69 end | 64 end |
70 redirect_to :action => 'index' | 65 redirect_to :action => 'index' |
71 end | 66 end |
72 | 67 |
73 def destroy | 68 def destroy |
76 @auth_source.destroy | 71 @auth_source.destroy |
77 flash[:notice] = l(:notice_successful_delete) | 72 flash[:notice] = l(:notice_successful_delete) |
78 end | 73 end |
79 redirect_to :action => 'index' | 74 redirect_to :action => 'index' |
80 end | 75 end |
81 | |
82 protected | |
83 | |
84 def auth_source_class | |
85 AuthSource | |
86 end | |
87 end | 76 end |