2011-10-08 23:36:38 +02:00
|
|
|
class Admin::UsersController < ApplicationController
|
2011-11-02 16:21:17 +01:00
|
|
|
layout "admin"
|
2011-10-08 23:36:38 +02:00
|
|
|
before_filter :authenticate_user!
|
|
|
|
before_filter :authenticate_admin!
|
|
|
|
|
|
|
|
def index
|
2012-04-16 22:33:03 +02:00
|
|
|
@admin_users = User.scoped
|
|
|
|
@admin_users = @admin_users.filter(params[:filter])
|
2012-06-21 18:05:09 +02:00
|
|
|
@admin_users = @admin_users.search(params[:name]) if params[:name].present?
|
2012-04-16 22:33:03 +02:00
|
|
|
@admin_users = @admin_users.order("updated_at DESC").page(params[:page])
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@admin_user = User.find(params[:id])
|
2012-02-11 18:56:18 +01:00
|
|
|
|
|
|
|
@projects = if @admin_user.projects.empty?
|
|
|
|
Project
|
|
|
|
else
|
|
|
|
Project.without_user(@admin_user)
|
|
|
|
end.all
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
2012-02-11 18:56:18 +01:00
|
|
|
def team_update
|
|
|
|
@admin_user = User.find(params[:id])
|
|
|
|
|
|
|
|
UsersProject.user_bulk_import(
|
|
|
|
@admin_user,
|
|
|
|
params[:project_ids],
|
2012-03-05 23:26:40 +01:00
|
|
|
params[:project_access]
|
2012-02-11 18:56:18 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
redirect_to [:admin, @admin_user], notice: 'Teams were successfully updated.'
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-10-08 23:36:38 +02:00
|
|
|
def new
|
2012-08-11 00:07:50 +02:00
|
|
|
@admin_user = User.new(projects_limit: Gitlab.config.default_projects_limit)
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@admin_user = User.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2012-04-16 22:33:03 +02:00
|
|
|
def block
|
|
|
|
@admin_user = User.find(params[:id])
|
|
|
|
|
|
|
|
if @admin_user.block
|
|
|
|
redirect_to :back, alert: "Successfully blocked"
|
|
|
|
else
|
|
|
|
redirect_to :back, alert: "Error occured. User was not blocked"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unblock
|
|
|
|
@admin_user = User.find(params[:id])
|
|
|
|
|
|
|
|
if @admin_user.update_attribute(:blocked, false)
|
|
|
|
redirect_to :back, alert: "Successfully unblocked"
|
|
|
|
else
|
|
|
|
redirect_to :back, alert: "Error occured. User was not unblocked"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-08 23:36:38 +02:00
|
|
|
def create
|
|
|
|
admin = params[:user].delete("admin")
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
@admin_user = User.new(params[:user])
|
2011-10-08 23:36:38 +02:00
|
|
|
@admin_user.admin = (admin && admin.to_i > 0)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @admin_user.save
|
|
|
|
format.html { redirect_to [:admin, @admin_user], notice: 'User was successfully created.' }
|
|
|
|
format.json { render json: @admin_user, status: :created, location: @admin_user }
|
|
|
|
else
|
|
|
|
format.html { render action: "new" }
|
|
|
|
format.json { render json: @admin_user.errors, status: :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
admin = params[:user].delete("admin")
|
2012-04-13 07:12:34 +02:00
|
|
|
|
2012-01-11 16:21:15 +01:00
|
|
|
if params[:user][:password].blank?
|
2011-10-26 15:46:25 +02:00
|
|
|
params[:user].delete(:password)
|
|
|
|
params[:user].delete(:password_confirmation)
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
@admin_user = User.find(params[:id])
|
|
|
|
@admin_user.admin = (admin && admin.to_i > 0)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @admin_user.update_attributes(params[:user])
|
|
|
|
format.html { redirect_to [:admin, @admin_user], notice: 'User was successfully updated.' }
|
|
|
|
format.json { head :ok }
|
|
|
|
else
|
|
|
|
format.html { render action: "edit" }
|
|
|
|
format.json { render json: @admin_user.errors, status: :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@admin_user = User.find(params[:id])
|
|
|
|
@admin_user.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to admin_users_url }
|
|
|
|
format.json { head :ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|