This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/admin/users_controller.rb

79 lines
1.8 KiB
Ruby
Raw Normal View History

2011-12-10 10:03:32 +00:00
class Admin::UsersController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :set_attribute, :only => [:index, :show, :new, :edit]
def index
@users = User.all.entries
end
def show
@user = User.find(params[:id])
2011-12-23 10:34:21 +00:00
get_info_and_roles
2011-12-10 10:03:32 +00:00
end
def new
@user = User.new
2011-12-23 10:34:21 +00:00
get_info_and_roles
2011-12-10 10:03:32 +00:00
end
def create
2011-12-23 10:34:21 +00:00
puts params.to_yaml
2011-12-10 10:03:32 +00:00
@user = User.new(params[:user])
if @user.save
flash[:notice] = t('admin.create_success_user')
redirect_to :action => :index
else
render :action => :new
end
end
def edit
@user = User.find(params[:id])
2011-12-23 10:34:21 +00:00
get_info_and_roles
2011-12-10 10:03:32 +00:00
end
def update
@user = User.find(params[:id])
# Update changes to the avatar
@user.remove_avatar! if params[:file]
@user.avatar = params[:file] if params[:file]
if @user.id.to_s.eql?(session['warden.user.user.key'][1].to_s) && @user.admin != params[:user][:admin].to_i.to_b
flash.now[:error] = t('admin.cant_revoke_self_admin')
end
if !flash[:error] && @user.update_attributes(params[:user])
flash[:notice] = t('admin.update_success_user')
redirect_to :action => :index
else
2011-12-23 10:34:21 +00:00
get_info_and_roles
2011-12-10 10:03:32 +00:00
render :action => :edit
end
end
def destroy
if params[:id].eql?(session['warden.user.user.key'][1].to_s)
flash[:error] = t('admin.cant_delete_self')
else
@user = User.find(params[:id])
@user.destroy
end
redirect_to :action => :index
end
protected
2011-12-23 10:34:21 +00:00
def get_info_and_roles
@infos = Info.excludes('disabled' => true)
@roles = Role.excludes('disabled' => true)
2011-12-10 10:03:32 +00:00
end
2011-12-23 10:34:21 +00:00
2011-12-10 10:03:32 +00:00
def set_attribute
@class = 'users'
end
end