users_controller.rb 2.85 KB
Newer Older
1
class Admin::UsersController < AdminController
gitlabhq's avatar
gitlabhq committed
2
  def index
3 4
    @admin_users = User.scoped
    @admin_users = @admin_users.filter(params[:filter])
randx's avatar
randx committed
5
    @admin_users = @admin_users.search(params[:name]) if params[:name].present?
6
    @admin_users = @admin_users.order("updated_at DESC").page(params[:page])
gitlabhq's avatar
gitlabhq committed
7 8 9 10
  end

  def show
    @admin_user = User.find(params[:id])
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
11 12 13 14 15 16

    @projects = if @admin_user.projects.empty?
               Project
             else
               Project.without_user(@admin_user)
             end.all
gitlabhq's avatar
gitlabhq committed
17 18
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
19 20 21 22
  def team_update
    @admin_user = User.find(params[:id])

    UsersProject.user_bulk_import(
23
      @admin_user,
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
24
      params[:project_ids],
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
25
      params[:project_access]
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
26 27 28 29 30 31
    )

    redirect_to [:admin, @admin_user], notice: 'Teams were successfully updated.'
  end


gitlabhq's avatar
gitlabhq committed
32
  def new
33
    @admin_user = User.new({ projects_limit: Gitlab.config.default_projects_limit }, as: :admin)
gitlabhq's avatar
gitlabhq committed
34 35 36 37 38 39
  end

  def edit
    @admin_user = User.find(params[:id])
  end

40
  def block
41 42 43 44
    @admin_user = User.find(params[:id])

    if @admin_user.block
      redirect_to :back, alert: "Successfully blocked"
45
    else
46 47 48 49
      redirect_to :back, alert: "Error occured. User was not blocked"
    end
  end

50
  def unblock
51 52 53 54
    @admin_user = User.find(params[:id])

    if @admin_user.update_attribute(:blocked, false)
      redirect_to :back, alert: "Successfully unblocked"
55
    else
56 57 58 59
      redirect_to :back, alert: "Error occured. User was not unblocked"
    end
  end

gitlabhq's avatar
gitlabhq committed
60 61 62
  def create
    admin = params[:user].delete("admin")

63
    @admin_user = User.new(params[:user], as: :admin)
gitlabhq's avatar
gitlabhq committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    @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")
randx's avatar
randx committed
79

80
    if params[:user][:password].blank?
Nihad Abbasov's avatar
Nihad Abbasov committed
81 82
      params[:user].delete(:password)
      params[:user].delete(:password_confirmation)
gitlabhq's avatar
gitlabhq committed
83 84 85 86 87 88
    end

    @admin_user = User.find(params[:id])
    @admin_user.admin = (admin && admin.to_i > 0)

    respond_to do |format|
89
      if @admin_user.update_attributes(params[:user], as: :admin)
gitlabhq's avatar
gitlabhq committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
        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