Sha256: 4a99a0f2b5eaae8bdaf65ad963ae83b492a6e3c42a87558587788528feceac9b

Contents?: true

Size: 1.94 KB

Versions: 5

Compression:

Stored size: 1.94 KB

Contents

module Protected
  module Admin
    class UsersController < ProtectedController
      before_filter :find_user, :except => [:index, :new, :create, :new_search, :search]
      def index
        @users = User.paginate(pagination_params)
      end

      def new
        @user = User.new
        @user.is_admin = false
      end

      def update
        @user.is_admin = params[:user][:is_admin] unless current_user == @user
        params[:user].delete(:is_admin)
        if @user.update_without_password(params[:user])
          flash[:success] = "User #{@user.name} updated successfully."
          redirect_to admin_users_url
        else
          render :action => 'edit'
        end
      end

      def destroy
        unless @user == current_user
          @user.destroy
          flash[:success] = "The user was deleted"
          redirect_to ['admin','users']
        else
          flash[:error] = "The user could not be deleted"
          redirect_to ['admin',@user]
        end
      end

      def create
        @user = User.new
        if params[:user].present?
          @user.is_admin = params[:user][:is_admin]
          params[:user].delete(:is_admin)
        end
        @user.attributes = params[:user]
        @user.random_password
        if @user.save
          flash[:success] = "User #{@user.name} created successfully."
          redirect_to ['admin','users']
        else
          render :action => :new
        end
      rescue Errno::ETIMEDOUT
        @user.errors.add(:base, I18n.t('devise.failure.user.service_error'))
        render :action => :new
      end

      def unlock
        @user.unlock_access!
        flash[:success] = "User's account has been unlocked"
        redirect_to admin_users_url
      end

      protected
        def find_user
          @user = User.find(params[:id])
        rescue ActiveRecord::RecordNotFound => e
          flash[:error] = e.message
          redirect_to ['admin','users']
        end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
protected-1.0.4 app/controllers/protected/admin/users_controller.rb
protected-1.0.3 app/controllers/protected/admin/users_controller.rb
protected-1.0.2 app/controllers/protected/admin/users_controller.rb
protected-1.0.1 app/controllers/protected/admin/users_controller.rb
protected-1.0.0 app/controllers/protected/admin/users_controller.rb