2011-11-17 12:02:58 +00:00
|
|
|
class Admin::UsersController < ApplicationController
|
2010-03-04 08:33:26 +00:00
|
|
|
|
2011-12-05 01:54:41 +00:00
|
|
|
layout "admin"
|
2010-03-04 08:33:26 +00:00
|
|
|
before_filter :authenticate_user!
|
|
|
|
|
|
|
|
def index
|
2011-04-13 10:19:51 +00:00
|
|
|
@users = User.all.entries
|
2010-03-04 08:33:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@user = User.find(params[:id])
|
2011-05-02 04:07:31 +00:00
|
|
|
get_info_role_models
|
2010-03-04 08:33:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@user = User.new
|
2011-05-02 04:07:31 +00:00
|
|
|
get_info_role_models
|
2010-03-04 08:33:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@user = User.new(params[:user])
|
|
|
|
if @user.save
|
2011-12-10 10:12:39 +00:00
|
|
|
@user.user_infos.each do |info|
|
|
|
|
info.save
|
|
|
|
info.attribute_values.each(&:save)
|
2011-04-28 14:47:34 +00:00
|
|
|
end
|
2011-12-10 10:12:39 +00:00
|
|
|
@user.roles.each do |role|
|
|
|
|
role.save
|
|
|
|
role.attribute_values.each(&:save)
|
2011-04-28 14:47:34 +00:00
|
|
|
end
|
2011-11-17 12:02:58 +00:00
|
|
|
flash[:notice] = t('admin.create_success_user')
|
2010-03-04 08:33:26 +00:00
|
|
|
redirect_to :action => :index
|
|
|
|
else
|
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@user = User.find(params[:id])
|
2011-05-02 04:07:31 +00:00
|
|
|
get_info_role_models
|
2010-03-04 08:33:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@user = User.find(params[:id])
|
2011-04-13 10:19:51 +00:00
|
|
|
|
|
|
|
# Update changes to the avatar
|
|
|
|
@user.remove_avatar! if params[:file]
|
|
|
|
@user.avatar = params[:file] if params[:file]
|
|
|
|
|
2011-02-08 06:51:49 +00:00
|
|
|
if @user.id.to_s.eql?(session['warden.user.user.key'][1].to_s) && @user.admin != params[:user][:admin].to_i.to_b
|
2011-11-17 12:02:58 +00:00
|
|
|
flash.now[:error] = t('admin.cant_revoke_self_admin')
|
2011-02-08 06:51:49 +00:00
|
|
|
end
|
|
|
|
if !flash[:error] && @user.update_attributes(params[:user])
|
2011-11-17 12:02:58 +00:00
|
|
|
flash[:notice] = t('admin.update_success_user')
|
2010-03-04 08:33:26 +00:00
|
|
|
redirect_to :action => :index
|
|
|
|
else
|
2011-05-02 04:07:31 +00:00
|
|
|
get_info_role_models
|
2010-03-04 08:33:26 +00:00
|
|
|
render :action => :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2011-02-08 02:07:40 +00:00
|
|
|
if params[:id].eql?(session['warden.user.user.key'][1].to_s)
|
2011-11-17 12:02:58 +00:00
|
|
|
flash[:error] = t('admin.cant_delete_self')
|
2011-02-08 02:07:40 +00:00
|
|
|
else
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
@user.destroy
|
2011-05-02 05:23:39 +00:00
|
|
|
@user.user_attributes.each do |ua|
|
|
|
|
ua.attribute_values.each(&:destroy)
|
|
|
|
ua.destroy
|
|
|
|
end
|
2011-02-08 02:07:40 +00:00
|
|
|
end
|
2010-03-04 08:33:26 +00:00
|
|
|
|
|
|
|
redirect_to :action => :index
|
|
|
|
end
|
|
|
|
|
2011-05-02 04:07:31 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def get_info_role_models
|
2011-12-10 10:12:39 +00:00
|
|
|
@roles = Info.excludes('disabled' => true)
|
|
|
|
@infos = Role.excludes('disabled' => true)
|
2011-05-02 04:07:31 +00:00
|
|
|
end
|
|
|
|
|
2010-03-04 08:33:26 +00:00
|
|
|
end
|