Sha256: 9a1384f72ba2059a1e9e382b82c78063e90a0f959540b76114dd045ce90d8d90

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

class Admin::UsersController < AlchemyController

  filter_access_to [:edit, :update, :destroy], :attribute_check => true
  filter_access_to [:index, :new, :create], :attribute_check => false

  def index
    if !params[:query].blank?
      @users = User.where([
        "users.login LIKE ? OR users.email LIKE ? OR users.firstname LIKE ? OR users.lastname LIKE ?",
        "%#{params[:query]}%",
        "%#{params[:query]}%",
        "%#{params[:query]}%",
        "%#{params[:query]}%"
      ]).order('login')
    else
      @users = User.all
    end
  end

  def new
    @user = User.new
    render :layout => false
  end

  def create
    @user = User.new(params[:user])
    if @user.save
      if @user.role == "registered" && params[:send_credentials]
        Notifications.registered_user_created(@user).deliver
      elsif params[:send_credentials]
        Notifications.admin_user_created(@user).deliver
      end
    end
    render_errors_or_redirect(
      @user,
      admin_users_path,
      ( _("User: '%{name}' created") % {:name => @user.name} ),
      "form#new_user button.button"
    )
  rescue
    exception_handler($!)
  end

  def edit
    # User is fetched via before filter from authentication plugin
    render :layout => false
  end

  def update
    # User is fetched via before filter from authentication plugin
    @user.update_attributes(params[:user])
    Notifications.admin_user_created(@user).deliver if params[:send_credentials]
    render_errors_or_redirect(
      @user,
      admin_users_path,
      ( _("User: '%{name}' updated") % {:name => @user.name} ),
      "form#edit_user_#{@user.id} button.button"
    )
  end

  def destroy
    # User is fetched via before filter from authentication plugin
    name = @user.name
    if @user.destroy
      flash[:notice] = ( _("User: '%{name}' deleted") % {:name => name} )
    end
    render :update do |page|
      page.redirect_to admin_users_path
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alchemy_cms-2.0.rc2 app/controllers/admin/users_controller.rb
alchemy_cms-2.0.rc1 app/controllers/admin/users_controller.rb
alchemy_cms-2.0.pre5 app/controllers/admin/users_controller.rb