comparison app/controllers/auth_sources_controller.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children e248c7af89ec
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 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.
18 class AuthSourcesController < ApplicationController 18 class AuthSourcesController < ApplicationController
19 layout 'admin' 19 layout 'admin'
20 menu_item :ldap_authentication 20 menu_item :ldap_authentication
21 21
22 before_filter :require_admin 22 before_filter :require_admin
23 before_filter :find_auth_source, :only => [:edit, :update, :test_connection, :destroy]
23 24
24 def index 25 def index
25 @auth_source_pages, @auth_sources = paginate AuthSource, :per_page => 10 26 @auth_source_pages, @auth_sources = paginate AuthSource, :per_page => 25
26 end 27 end
27 28
28 def new 29 def new
29 klass_name = params[:type] || 'AuthSourceLdap' 30 klass_name = params[:type] || 'AuthSourceLdap'
30 @auth_source = AuthSource.new_subclass_instance(klass_name, params[:auth_source]) 31 @auth_source = AuthSource.new_subclass_instance(klass_name, params[:auth_source])
32 render_404 unless @auth_source
31 end 33 end
32 34
33 def create 35 def create
34 @auth_source = AuthSource.new_subclass_instance(params[:type], params[:auth_source]) 36 @auth_source = AuthSource.new_subclass_instance(params[:type], params[:auth_source])
35 if @auth_source.save 37 if @auth_source.save
36 flash[:notice] = l(:notice_successful_create) 38 flash[:notice] = l(:notice_successful_create)
37 redirect_to :action => 'index' 39 redirect_to auth_sources_path
38 else 40 else
39 render :action => 'new' 41 render :action => 'new'
40 end 42 end
41 end 43 end
42 44
43 def edit 45 def edit
44 @auth_source = AuthSource.find(params[:id])
45 end 46 end
46 47
47 def update 48 def update
48 @auth_source = AuthSource.find(params[:id])
49 if @auth_source.update_attributes(params[:auth_source]) 49 if @auth_source.update_attributes(params[:auth_source])
50 flash[:notice] = l(:notice_successful_update) 50 flash[:notice] = l(:notice_successful_update)
51 redirect_to :action => 'index' 51 redirect_to auth_sources_path
52 else 52 else
53 render :action => 'edit' 53 render :action => 'edit'
54 end 54 end
55 end 55 end
56 56
57 def test_connection 57 def test_connection
58 @auth_source = AuthSource.find(params[:id])
59 begin 58 begin
60 @auth_source.test_connection 59 @auth_source.test_connection
61 flash[:notice] = l(:notice_successful_connection) 60 flash[:notice] = l(:notice_successful_connection)
62 rescue Exception => e 61 rescue Exception => e
63 flash[:error] = l(:error_unable_to_connect, e.message) 62 flash[:error] = l(:error_unable_to_connect, e.message)
64 end 63 end
65 redirect_to :action => 'index' 64 redirect_to auth_sources_path
66 end 65 end
67 66
68 def destroy 67 def destroy
69 @auth_source = AuthSource.find(params[:id]) 68 unless @auth_source.users.exists?
70 unless @auth_source.users.find(:first)
71 @auth_source.destroy 69 @auth_source.destroy
72 flash[:notice] = l(:notice_successful_delete) 70 flash[:notice] = l(:notice_successful_delete)
73 end 71 end
74 redirect_to :action => 'index' 72 redirect_to auth_sources_path
73 end
74
75 def autocomplete_for_new_user
76 results = AuthSource.search(params[:term])
77
78 render :json => results.map {|result| {
79 'value' => result[:login],
80 'label' => "#{result[:login]} (#{result[:firstname]} #{result[:lastname]})",
81 'login' => result[:login].to_s,
82 'firstname' => result[:firstname].to_s,
83 'lastname' => result[:lastname].to_s,
84 'mail' => result[:mail].to_s,
85 'auth_source_id' => result[:auth_source_id].to_s
86 }}
87 end
88
89 private
90
91 def find_auth_source
92 @auth_source = AuthSource.find(params[:id])
93 rescue ActiveRecord::RecordNotFound
94 render_404
75 end 95 end
76 end 96 end