Newer
Older
class Management::UsersController < ManagementController
before_action :set_user, only: [:show, :edit, :update, :destroy, :change_roles]
Mauricio Giacomini Girardello
committed
before_action :set_roles, only: [:new, :edit]
Mauricio Giacomini Girardello
committed
@users = User.includes(:roles).all.order(:name).page(params[:page]).per(params[:limit])
Mauricio Giacomini Girardello
committed
# GET /users/1
# GET /users/1.json
Mauricio Giacomini Girardello
committed
# GET /users/new
def new
@user = User.new
end
# GET /users/1/edit
def edit
end
# POST /users
# POST /users.json
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to management_users_path, notice: "User created!" }
Mauricio Giacomini Girardello
committed
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /users/1
# PATCH/PUT /users/1.json
def update
respond_to do |format|
if @user.update(user_params)
format.html { redirect_to management_users_path, notice: "User updated!" }
Mauricio Giacomini Girardello
committed
else
format.html { render :edit }
end
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
Mauricio Giacomini Girardello
committed
respond_to do |format|
format.html { redirect_to management_users_path, notice: "User destroyed!" }
Mauricio Giacomini Girardello
committed
end
end
@user.roles << Role.find(params[:role_id])
format.html {redirect_to :back, notice: "Usuário #{@user.name} definido como #{@user.roles[0].name}"}
else
format.html {redirect_to :back, notice: "Erro na atribuição!"}
end
def curators
@curators = Array.new
@users = User.includes(:roles).all
@users.all.each do |user|
@curators << user unless !(user.roles[0].name == "curator")
@curators = Kaminari.paginate_array(@curators).page(params[:page]).per(params[:limit])
end
def admins
@admins = Array.new
@users = User.includes(:roles).all
@users.all.each do |user|
@admins << user unless !(user.roles[0].name == "admin")
@admins = Kaminari.paginate_array(@admins).page(params[:page]).per(params[:limit])
Mauricio Giacomini Girardello
committed
private
# Use callbacks to share common setup or constraints between actions.
def set_user
Mauricio Giacomini Girardello
committed
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation, role_ids: [])
Mauricio Giacomini Girardello
committed
end
Mauricio Giacomini Girardello
committed
def set_roles
Mauricio Giacomini Girardello
committed
end