2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-10 11:35:46 +00:00
|
|
|
class UsersController < ApplicationController
|
2011-10-24 14:01:15 +01:00
|
|
|
before_filter :authenticate_user!
|
2011-03-31 00:10:23 +01:00
|
|
|
|
2011-11-24 21:46:19 +00:00
|
|
|
load_and_authorize_resource
|
2011-12-09 23:40:13 +00:00
|
|
|
autocomplete :user, :uname
|
2011-11-17 19:34:02 +00:00
|
|
|
|
2011-03-10 21:48:15 +00:00
|
|
|
def index
|
2011-12-15 16:15:25 +00:00
|
|
|
@user = User.scoped
|
|
|
|
if !params[:filter].blank? && !params[:filter][:email].blank?
|
|
|
|
@users = @users.where(:email => params[:filter][:email])
|
|
|
|
@email = params[:filter][:email]
|
|
|
|
end
|
|
|
|
@users = @users.paginate(:page => params[:user_page])
|
|
|
|
@action_url = users_path
|
2011-03-10 21:48:15 +00:00
|
|
|
end
|
|
|
|
|
2011-03-31 00:10:23 +01:00
|
|
|
def show
|
2011-10-16 21:48:31 +01:00
|
|
|
@groups = @user.groups.uniq
|
|
|
|
@platforms = @user.platforms.paginate(:page => params[:platform_page], :per_page => 10)
|
|
|
|
@projects = @user.projects.paginate(:page => params[:project_page], :per_page => 10)
|
2011-03-31 00:10:23 +01:00
|
|
|
end
|
|
|
|
|
2011-03-10 21:48:15 +00:00
|
|
|
def new
|
|
|
|
@user = User.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@user = User.new params[:user]
|
|
|
|
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 update
|
2012-03-06 18:59:29 +00:00
|
|
|
if params[:user][:role] && current_user.admin?
|
2012-03-05 15:36:23 +00:00
|
|
|
@user.role = params[:user][:role]
|
|
|
|
params[:user].delete(:role)
|
|
|
|
end
|
|
|
|
if @user.update_without_password(params[:user])
|
2011-03-10 21:48:15 +00:00
|
|
|
flash[:notice] = t('flash.user.saved')
|
2012-03-03 16:03:23 +00:00
|
|
|
redirect_to edit_user_path(@user)
|
2011-03-10 21:48:15 +00:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.user.save_error')
|
2012-03-06 11:24:42 +00:00
|
|
|
flash[:warning] = @user.errors.full_messages.join('. ')
|
2012-03-03 16:03:23 +00:00
|
|
|
render(:action => :edit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def private
|
|
|
|
if request.put?
|
2012-03-05 15:36:23 +00:00
|
|
|
if @user.update_with_password(params[:user])
|
2012-03-03 16:03:23 +00:00
|
|
|
flash[:notice] = t('flash.user.saved')
|
|
|
|
redirect_to user_private_settings_path(@user)
|
|
|
|
else
|
|
|
|
flash[:error] = t('flash.user.save_error')
|
2012-03-06 11:24:42 +00:00
|
|
|
flash[:warning] = @user.errors.full_messages.join('. ')
|
2012-03-03 16:03:23 +00:00
|
|
|
render(:action => :private)
|
|
|
|
end
|
2011-03-10 21:48:15 +00:00
|
|
|
end
|
|
|
|
end
|
2011-03-31 00:10:23 +01:00
|
|
|
|
2011-10-26 21:57:51 +01:00
|
|
|
def destroy
|
|
|
|
@user.destroy
|
|
|
|
flash[:notice] = t("flash.user.destroyed")
|
|
|
|
redirect_to users_path
|
|
|
|
end
|
|
|
|
|
2011-03-10 11:35:46 +00:00
|
|
|
end
|