users_controller.rb 2.36 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1
class Admin::UsersController < ApplicationController
gitlabhq's avatar
gitlabhq committed
2
  layout "admin"
gitlabhq's avatar
gitlabhq committed
3 4 5 6 7 8 9 10 11
  before_filter :authenticate_user!
  before_filter :authenticate_admin!

  def index
    @admin_users = User.page(params[:page])
  end

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

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

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

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

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


gitlabhq's avatar
gitlabhq committed
33
  def new
Valera Sizov's avatar
Valera Sizov committed
34
    @admin_user = User.new(:projects_limit => 10)
gitlabhq's avatar
gitlabhq committed
35 36 37 38 39 40 41 42
  end

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

  def create
    admin = params[:user].delete("admin")
randx's avatar
randx committed
43
    blocked = params[:user].delete("blocked")
gitlabhq's avatar
gitlabhq committed
44

Nihad Abbasov's avatar
Nihad Abbasov committed
45
    @admin_user = User.new(params[:user])
gitlabhq's avatar
gitlabhq committed
46
    @admin_user.admin = (admin && admin.to_i > 0)
randx's avatar
randx committed
47
    @admin_user.blocked = blocked
gitlabhq's avatar
gitlabhq committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61

    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
62 63
    blocked = params[:user].delete("blocked")

64
    if params[:user][:password].blank?
Nihad Abbasov's avatar
Nihad Abbasov committed
65 66
      params[:user].delete(:password)
      params[:user].delete(:password_confirmation)
gitlabhq's avatar
gitlabhq committed
67 68 69 70
    end

    @admin_user = User.find(params[:id])
    @admin_user.admin = (admin && admin.to_i > 0)
randx's avatar
randx committed
71
    @admin_user.blocked = blocked
gitlabhq's avatar
gitlabhq committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

    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