users_controller.rb 1.78 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 12 13 14
  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])
  end

  def new
Valera Sizov's avatar
Valera Sizov committed
15
    @admin_user = User.new(:projects_limit => 10)
gitlabhq's avatar
gitlabhq committed
16 17 18 19 20 21 22 23 24
  end

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

  def create
    admin = params[:user].delete("admin")

Nihad Abbasov's avatar
Nihad Abbasov committed
25
    @admin_user = User.new(params[:user])
gitlabhq's avatar
gitlabhq committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    @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")
41
    if params[:user][:password].blank?
Nihad Abbasov's avatar
Nihad Abbasov committed
42 43
      params[:user].delete(:password)
      params[:user].delete(:password_confirmation)
gitlabhq's avatar
gitlabhq committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    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