rosa-build/app/controllers/admin/users_controller.rb

70 lines
2.0 KiB
Ruby
Raw Normal View History

2012-03-20 18:11:28 +00:00
# -*- encoding : utf-8 -*-
class Admin::UsersController < ApplicationController
before_filter :authenticate_user!
2012-03-21 17:45:51 +00:00
load_and_authorize_resource :except => :create
authorize_resource :only => :create
2012-03-20 18:11:28 +00:00
def index
@filter = params[:filter] || 'all'
end
def new
end
def create
2012-03-22 11:17:11 +00:00
@user = User.new params[:user]
2012-03-22 14:50:15 +00:00
@user.role = params[:role]
2012-03-22 11:17:11 +00:00
@user.uname = params[:uname]
2012-03-20 18:11:28 +00:00
if @user.save
flash[:notice] = t('flash.user.saved')
redirect_to users_path
else
flash[:error] = t('flash.user.save_error')
render :action => :new
end
end
def profile
end
def update
2012-03-22 14:50:15 +00:00
@user.role = params[:role]
2012-03-20 18:11:28 +00:00
if @user.update_without_password(params[:user])
if @user.avatar && params[:delete_avatar] == '1'
@user.avatar = nil
@user.save
end
flash[:notice] = t('flash.user.saved')
2012-03-20 20:06:51 +00:00
redirect_to users_path#edit_user_path(@user)
2012-03-20 18:11:28 +00:00
else
flash[:error] = t('flash.user.save_error')
flash[:warning] = @user.errors.full_messages.join('. ')
render(:action => :profile)
end
end
def destroy
@user.destroy
flash[:notice] = t("flash.user.destroyed")
redirect_to users_path
end
def list
colName = ['users.name', 'users.uname', 'users.email']
sort_col = params[:iSortCol_0] || 0
sort_dir = params[:sSortDir_0]=="asc" ? 'asc' : 'desc'
order = "#{colName[sort_col.to_i]} #{sort_dir}"
@users = @users.paginate(:page => (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i).to_i + 1, :per_page => params[:iDisplayLength])
@total_users = @users.count
if !params[:sSearch].blank? && search = "%#{params[:sSearch]}%"
@users = @users.where('users.name ILIKE ? or users.uname ILIKE ? or users.email ILIKE ?', search, search, search)
end
2012-03-21 18:02:58 +00:00
@filter = params[:filter] || 'all'
@users = @users.send(@filter) if ['real', 'admin', 'banned'].include? @filter
2012-03-20 18:11:28 +00:00
@total_user = @users.count
@users = @users.order(order)
render :partial =>'users_ajax', :layout => false
end
2012-03-22 14:50:15 +00:00
end