File: app/controllers/auth_sources_controller.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  class: AuthSourcesController#18
inherits from
  ApplicationController   
has properties
method: index #24
method: new #28
method: create #33
method: edit #43
method: update #47
method: test_connection #57
method: destroy #68

Class Hierarchy

Code

   1  # Redmine - project management software
   2  # Copyright (C) 2006-2011  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    layout 'admin'
  20    menu_item :ldap_authentication
  21 
  22    before_filter :require_admin
  23 
  24    def index
  25      @auth_source_pages, @auth_sources = paginate AuthSource, :per_page => 10
  26    end
  27 
  28    def new
  29      klass_name = params[:type] || 'AuthSourceLdap'
  30      @auth_source = AuthSource.new_subclass_instance(klass_name, params[:auth_source])
  31    end
  32 
  33    def create
  34      @auth_source = AuthSource.new_subclass_instance(params[:type], params[:auth_source])
  35      if @auth_source.save
  36        flash[:notice] = l(:notice_successful_create)
  37        redirect_to :action => 'index'
  38      else
  39        render :action => 'new'
  40      end
  41    end
  42 
  43    def edit
  44      @auth_source = AuthSource.find(params[:id])
  45    end
  46 
  47    def update
  48      @auth_source = AuthSource.find(params[:id])
  49      if @auth_source.update_attributes(params[:auth_source])
  50        flash[:notice] = l(:notice_successful_update)
  51        redirect_to :action => 'index'
  52      else
  53        render :action => 'edit'
  54      end
  55    end
  56 
  57    def test_connection
  58      @auth_source = AuthSource.find(params[:id])
  59      begin
  60        @auth_source.test_connection
  61        flash[:notice] = l(:notice_successful_connection)
  62      rescue Exception => e
  63        flash[:error] = l(:error_unable_to_connect, e.message)
  64      end
  65      redirect_to :action => 'index'
  66    end
  67 
  68    def destroy
  69      @auth_source = AuthSource.find(params[:id])
  70      unless @auth_source.users.find(:first)
  71        @auth_source.destroy
  72        flash[:notice] = l(:notice_successful_delete)
  73      end
  74      redirect_to :action => 'index'
  75    end
  76  end