OSDN Git Service

add Redmine trunk rev 3089
[redminele/redminele.git] / redmine / app / controllers / auth_sources_controller.rb
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 AuthSourcesController < ApplicationController
19   before_filter :require_admin
20
21   def index
22     list
23     render :action => 'list' unless request.xhr?
24   end
25
26   # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
27   verify :method => :post, :only => [ :destroy, :create, :update ],
28          :redirect_to => { :action => :list }
29
30   def list
31     @auth_source_pages, @auth_sources = paginate :auth_sources, :per_page => 10
32     render :action => "list", :layout => false if request.xhr?
33   end
34
35   def new
36     @auth_source = AuthSourceLdap.new
37   end
38
39   def create
40     @auth_source = AuthSourceLdap.new(params[:auth_source])
41     if @auth_source.save
42       flash[:notice] = l(:notice_successful_create)
43       redirect_to :action => 'list'
44     else
45       render :action => 'new'
46     end
47   end
48
49   def edit
50     @auth_source = AuthSource.find(params[:id])
51   end
52
53   def update
54     @auth_source = AuthSource.find(params[:id])
55     if @auth_source.update_attributes(params[:auth_source])
56       flash[:notice] = l(:notice_successful_update)
57       redirect_to :action => 'list'
58     else
59       render :action => 'edit'
60     end
61   end
62   
63   def test_connection
64     @auth_method = AuthSource.find(params[:id])
65     begin
66       @auth_method.test_connection
67       flash[:notice] = l(:notice_successful_connection)
68     rescue => text
69       flash[:error] = "Unable to connect (#{text})"
70     end
71     redirect_to :action => 'list'
72   end
73
74   def destroy
75     @auth_source = AuthSource.find(params[:id])
76     unless @auth_source.users.find(:first)
77       @auth_source.destroy
78       flash[:notice] = l(:notice_successful_delete)
79     end
80     redirect_to :action => 'list'
81   end
82 end