Sha256: 547ed751ad5cea1426a4632f377a81e1b4031caae5d8c617489c1ce0114ece37

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

class Manage::UsersController < Manage::BaseController
  inherit_resources
  defaults :route_prefix => 'manage'
  
  load_and_authorize_resource  
  
  before_filter :make_filter, :only=>[:index]
  before_filter :check_params, :only => [:create, :update]
  
  def create
    @user.attributes = params[:user]
    create! { manage_users_path } 
  end
  
  def update
    update!{ manage_users_path }
  end
  
  def destroy
    destroy!{ manage_users_path }
  end
  
  # POST /manage/users/1/activate
  def activate
    @user.confirm!    
    respond_with(@user, :location => manage_users_path)
  end
  
  # POST /manage/users/1/suspend
  def suspend
    @user.suspend! 
    respond_with(@user, :location => manage_users_path)
  end

  # POST /manage/users/1/unsuspend
  def unsuspend
    @user.unsuspend!
    respond_with(@user, :location => manage_users_path)
  end

  # POST /manage/users/1/delete
  def delete
    @user.delete!
    respond_with(@user, :location => manage_users_path)
  end
  
  protected
    
    def collection
      @users = (@users || end_of_association_chain).merge(@search.scoped).includes(:avatar).page(params[:page])
    end
    
    def make_filter
      @search = Sunrise::ModelFilter.new(User, :attributes=>[:name, :email])
      @search.update_attributes(params[:search])
    end
    
    def check_params
      unless params[:user].blank?
        if params[:user][:password].blank?
          params[:user].delete(:password)
          params[:user].delete(:password_confirmation)
        end
        
        @user.accessible = :all
      end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sunrise-core-0.1.4 app/controllers/manage/users_controller.rb