2013-01-20 12:20:50 +01:00
|
|
|
class Admin::UsersController < Admin::ApplicationController
|
2013-01-26 11:08:34 +01:00
|
|
|
before_filter :admin_user, only: [:show, :edit, :update, :destroy]
|
|
|
|
|
2011-10-08 23:36:38 +02:00
|
|
|
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-12-30 12:50:23 +01:00
|
|
|
@admin_users = @admin_users.alphabetically.page(params[:page])
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2013-01-26 11:08:34 +01:00
|
|
|
@projects = Project.scoped
|
|
|
|
@projects = @projects.without_user(admin_user) if admin_user.authorized_projects.empty?
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
2012-02-11 18:56:18 +01:00
|
|
|
def team_update
|
2013-01-04 20:45:30 +01:00
|
|
|
UsersProject.add_users_into_projects(
|
2012-02-11 18:56:18 +01:00
|
|
|
params[:project_ids],
|
2013-01-25 19:38:24 +01:00
|
|
|
[admin_user.id],
|
2012-03-05 23:26:40 +01:00
|
|
|
params[:project_access]
|
2012-02-11 18:56:18 +01:00
|
|
|
)
|
|
|
|
|
2013-01-25 19:38:24 +01:00
|
|
|
redirect_to [:admin, admin_user], notice: 'Teams were successfully updated.'
|
2012-02-11 18:56:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-10-08 23:36:38 +02:00
|
|
|
def new
|
2012-12-15 01:16:25 +01:00
|
|
|
@admin_user = User.new({ projects_limit: Gitlab.config.gitlab.default_projects_limit }, as: :admin)
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2013-01-25 19:38:24 +01:00
|
|
|
admin_user
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
2012-09-16 13:44:54 +02:00
|
|
|
def block
|
2013-01-25 19:38:24 +01:00
|
|
|
if admin_user.block
|
2012-04-16 22:33:03 +02:00
|
|
|
redirect_to :back, alert: "Successfully blocked"
|
2012-09-16 13:44:54 +02:00
|
|
|
else
|
2012-04-16 22:33:03 +02:00
|
|
|
redirect_to :back, alert: "Error occured. User was not blocked"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-16 13:44:54 +02:00
|
|
|
def unblock
|
2013-01-25 19:38:24 +01:00
|
|
|
if admin_user.update_attribute(:blocked, false)
|
2012-04-16 22:33:03 +02:00
|
|
|
redirect_to :back, alert: "Successfully unblocked"
|
2012-09-16 13:44:54 +02:00
|
|
|
else
|
2012-04-16 22:33:03 +02:00
|
|
|
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")
|
|
|
|
|
2012-09-26 13:20:44 +02:00
|
|
|
@admin_user = User.new(params[:user], as: :admin)
|
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
|
|
|
|
|
2013-01-25 19:38:24 +01:00
|
|
|
admin_user.admin = (admin && admin.to_i > 0)
|
2011-10-08 23:36:38 +02:00
|
|
|
|
|
|
|
respond_to do |format|
|
2013-01-25 19:38:24 +01:00
|
|
|
if admin_user.update_attributes(params[:user], as: :admin)
|
|
|
|
format.html { redirect_to [:admin, admin_user], notice: 'User was successfully updated.' }
|
2011-10-08 23:36:38 +02:00
|
|
|
format.json { head :ok }
|
|
|
|
else
|
|
|
|
format.html { render action: "edit" }
|
2013-01-25 19:38:24 +01:00
|
|
|
format.json { render json: admin_user.errors, status: :unprocessable_entity }
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2013-01-25 19:38:24 +01:00
|
|
|
if admin_user.personal_projects.count > 0
|
2012-11-02 12:26:41 +01:00
|
|
|
redirect_to admin_users_path, alert: "User is a project owner and can't be removed." and return
|
|
|
|
end
|
2013-01-25 19:38:24 +01:00
|
|
|
admin_user.destroy
|
2011-10-08 23:36:38 +02:00
|
|
|
|
|
|
|
respond_to do |format|
|
2013-01-25 19:38:24 +01:00
|
|
|
format.html { redirect_to admin_users_path }
|
2011-10-08 23:36:38 +02:00
|
|
|
format.json { head :ok }
|
|
|
|
end
|
|
|
|
end
|
2013-01-25 19:38:24 +01:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def admin_user
|
2013-01-26 11:08:34 +01:00
|
|
|
@admin_user ||= User.find_by_username!(params[:id])
|
2013-01-25 19:38:24 +01:00
|
|
|
end
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|