Class: Admin::UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#blockObject


52
53
54
55
56
57
58
# File 'app/controllers/admin/users_controller.rb', line 52

def block
  if user.block
    redirect_back_or_admin_user(notice: "Successfully blocked")
  else
    redirect_back_or_admin_user(alert: "Error occurred. User was not blocked")
  end
end

#confirmObject


78
79
80
81
82
83
84
# File 'app/controllers/admin/users_controller.rb', line 78

def confirm
  if user.confirm
    redirect_back_or_admin_user(notice: "Successfully confirmed")
  else
    redirect_back_or_admin_user(alert: "Error occurred. User was not confirmed")
  end
end

#createObject


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/controllers/admin/users_controller.rb', line 92

def create
  opts = {
    force_random_password: true,
    password_expires_at: nil
  }

  @user = User.new(user_params.merge(opts))
  @user.created_by_id = current_user.id
  @user.generate_password
  @user.generate_reset_token
  @user.skip_confirmation!

  respond_to do |format|
    if @user.save
      format.html { redirect_to [:admin, @user], notice: 'User was successfully created.' }
      format.json { render json: @user, status: :created, location: @user }
    else
      format.html { render "new" }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject


139
140
141
142
143
144
145
146
# File 'app/controllers/admin/users_controller.rb', line 139

def destroy
  DeleteUserWorker.perform_async(current_user.id, user.id)

  respond_to do |format|
    format.html { redirect_to admin_users_path, notice: "The user is being deleted." }
    format.json { head :ok }
  end
end

#disable_two_factorObject


86
87
88
89
90
# File 'app/controllers/admin/users_controller.rb', line 86

def disable_two_factor
  user.disable_two_factor!
  redirect_to admin_user_path(user),
    notice: 'Two-factor Authentication has been disabled for this user'
end

#editObject


30
31
32
# File 'app/controllers/admin/users_controller.rb', line 30

def edit
  user
end

#groupsObject


19
20
# File 'app/controllers/admin/users_controller.rb', line 19

def groups
end

#impersonateObject


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/admin/users_controller.rb', line 34

def impersonate
  if user.blocked?
    flash[:alert] = "You cannot impersonate a blocked user"

    redirect_to admin_user_path(user)
  else
    session[:impersonator_id] = current_user.id

    warden.set_user(user, scope: :user)

    Gitlab::AppLogger.info("User #{current_user.username} has started impersonating #{user.username}")

    flash[:alert] = "You are now impersonating #{user.username}"

    redirect_to root_path
  end
end

#indexObject


4
5
6
7
8
9
# File 'app/controllers/admin/users_controller.rb', line 4

def index
  @users = User.order_name_asc.filter(params[:filter])
  @users = @users.search(params[:name]) if params[:name].present?
  @users = @users.sort(@sort = params[:sort])
  @users = @users.page(params[:page])
end

#keysObject


22
23
24
# File 'app/controllers/admin/users_controller.rb', line 22

def keys
  @keys = user.keys
end

#newObject


26
27
28
# File 'app/controllers/admin/users_controller.rb', line 26

def new
  @user = User.new
end

#projectsObject


14
15
16
17
# File 'app/controllers/admin/users_controller.rb', line 14

def projects
  @personal_projects = user.personal_projects
  @joined_projects = user.projects.joined(@user)
end

#remove_emailObject


148
149
150
151
152
153
154
155
156
157
158
# File 'app/controllers/admin/users_controller.rb', line 148

def remove_email
  email = user.emails.find(params[:email_id])
  email.destroy

  user.update_secondary_emails!

  respond_to do |format|
    format.html { redirect_back_or_admin_user(notice: "Successfully removed email.") }
    format.js { render nothing: true }
  end
end

#showObject


11
12
# File 'app/controllers/admin/users_controller.rb', line 11

def show
end

#unblockObject


60
61
62
63
64
65
66
67
68
# File 'app/controllers/admin/users_controller.rb', line 60

def unblock
  if user.ldap_blocked?
    redirect_back_or_admin_user(alert: "This user cannot be unlocked manually from GitLab")
  elsif user.activate
    redirect_back_or_admin_user(notice: "Successfully unblocked")
  else
    redirect_back_or_admin_user(alert: "Error occurred. User was not unblocked")
  end
end

#unlockObject


70
71
72
73
74
75
76
# File 'app/controllers/admin/users_controller.rb', line 70

def unlock
  if user.unlock_access!
    redirect_back_or_admin_user(alert: "Successfully unlocked")
  else
    redirect_back_or_admin_user(alert: "Error occurred. User was not unlocked")
  end
end

#updateObject


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/controllers/admin/users_controller.rb', line 115

def update
  user_params_with_pass = user_params.dup

  if params[:user][:password].present?
    user_params_with_pass.merge!(
      password: params[:user][:password],
      password_confirmation: params[:user][:password_confirmation],
    )
  end

  respond_to do |format|
    user.skip_reconfirmation!
    if user.update_attributes(user_params_with_pass)
      format.html { redirect_to [:admin, user], notice: 'User was successfully updated.' }
      format.json { head :ok }
    else
      # restore username to keep form action url.
      user.username = params[:id]
      format.html { render "edit" }
      format.json { render json: user.errors, status: :unprocessable_entity }
    end
  end
end