2011-10-26 21:57:51 +01:00
|
|
|
# coding: 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
|
|
|
before_filter :find_user, :only => [:show, :edit, :update, :destroy]
|
2011-11-15 20:05:08 +00:00
|
|
|
#before_filter :check_global_access
|
2011-03-31 00:10:23 +01:00
|
|
|
|
2011-03-10 21:48:15 +00:00
|
|
|
def index
|
2011-10-26 21:57:51 +01:00
|
|
|
@users = User.paginate(:page => params[:user_page])
|
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)
|
|
|
|
@repositories = @user.repositories.paginate(:page => params[:repository_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
|
2011-10-29 14:39:40 +01:00
|
|
|
@global_roles = Role.by_acter(User).by_target(:system) + Role.by_acter(:all).by_target(:system)
|
|
|
|
@global_roles.map! {|role| [role.name, role.id]}
|
2011-03-10 21:48:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2011-10-29 14:39:40 +01:00
|
|
|
@global_roles = Role.by_acter(User).by_target(:system) + Role.by_acter(:all).by_target(:system)
|
|
|
|
@global_roles.map! {|role| [role.name, role.id]}
|
2011-03-10 21:48:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@user = User.new params[:user]
|
2011-10-29 15:14:41 +01:00
|
|
|
@user.global_role_id = params[:user]['global_role_id']
|
2011-03-10 21:48:15 +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 update
|
2011-10-29 15:14:41 +01:00
|
|
|
@user.global_role_id = params[:user]['global_role_id']
|
2011-03-10 21:48:15 +00:00
|
|
|
if @user.update_attributes(params[:user])
|
|
|
|
flash[:notice] = t('flash.user.saved')
|
|
|
|
redirect_to users_path
|
|
|
|
else
|
|
|
|
flash[:error] = t('flash.user.save_error')
|
|
|
|
render :action => :edit
|
|
|
|
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-31 00:10:23 +01:00
|
|
|
protected
|
2011-10-26 21:57:51 +01:00
|
|
|
|
2011-03-31 00:10:23 +01:00
|
|
|
def find_user
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
end
|
2011-03-10 11:35:46 +00:00
|
|
|
end
|