2013-01-20 06:20:50 -05:00
|
|
|
class Admin::UsersController < Admin::ApplicationController
|
2015-06-22 11:12:20 -04:00
|
|
|
before_action :user, except: [:index, :new, :create]
|
2013-01-26 05:08:34 -05:00
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
def index
|
2015-02-05 22:15:05 -05:00
|
|
|
@users = User.order_name_asc.filter(params[:filter])
|
2013-06-26 08:57:02 -04:00
|
|
|
@users = @users.search(params[:name]) if params[:name].present?
|
2014-10-10 08:15:34 -04:00
|
|
|
@users = @users.sort(@sort = params[:sort])
|
2015-02-05 22:15:05 -05:00
|
|
|
@users = @users.page(params[:page])
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2015-06-22 11:12:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def projects
|
2014-06-03 05:44:22 -04:00
|
|
|
@personal_projects = user.personal_projects
|
|
|
|
@joined_projects = user.projects.joined(@user)
|
2015-06-22 11:12:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def groups
|
|
|
|
end
|
|
|
|
|
|
|
|
def keys
|
2015-02-05 17:20:55 -05:00
|
|
|
@keys = user.keys
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2014-06-26 16:24:17 -04:00
|
|
|
@user = User.new
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2013-06-26 08:57:02 -04:00
|
|
|
user
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
2012-09-16 07:44:54 -04:00
|
|
|
def block
|
2013-06-26 08:57:02 -04:00
|
|
|
if user.block
|
2015-10-20 03:28:28 -04:00
|
|
|
redirect_back_or_admin_user(notice: "Successfully blocked")
|
2012-09-16 07:44:54 -04:00
|
|
|
else
|
2015-10-20 03:28:28 -04:00
|
|
|
redirect_back_or_admin_user(alert: "Error occurred. User was not blocked")
|
2012-04-16 16:33:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-16 07:44:54 -04:00
|
|
|
def unblock
|
2015-12-29 15:58:38 -05:00
|
|
|
if user.ldap_blocked?
|
|
|
|
redirect_back_or_admin_user(alert: "This user cannot be unlocked manually from GitLab")
|
|
|
|
elsif user.activate
|
2015-10-20 03:28:28 -04:00
|
|
|
redirect_back_or_admin_user(notice: "Successfully unblocked")
|
2012-09-16 07:44:54 -04:00
|
|
|
else
|
2015-10-20 03:28:28 -04:00
|
|
|
redirect_back_or_admin_user(alert: "Error occurred. User was not unblocked")
|
2012-04-16 16:33:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-02 01:26:14 -04:00
|
|
|
def unlock
|
|
|
|
if user.unlock_access!
|
2015-10-20 03:28:28 -04:00
|
|
|
redirect_back_or_admin_user(alert: "Successfully unlocked")
|
2015-07-02 01:26:14 -04:00
|
|
|
else
|
2015-10-20 03:28:28 -04:00
|
|
|
redirect_back_or_admin_user(alert: "Error occurred. User was not unlocked")
|
2015-07-02 01:26:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-29 10:32:01 -04:00
|
|
|
def confirm
|
2015-09-19 21:15:13 -04:00
|
|
|
if user.confirm
|
2015-10-20 03:28:28 -04:00
|
|
|
redirect_back_or_admin_user(notice: "Successfully confirmed")
|
2015-07-29 10:32:01 -04:00
|
|
|
else
|
2015-10-20 03:28:28 -04:00
|
|
|
redirect_back_or_admin_user(alert: "Error occurred. User was not confirmed")
|
2015-07-29 10:32:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-10 17:11:18 -04:00
|
|
|
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
|
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
def create
|
2013-06-13 14:06:27 -04:00
|
|
|
opts = {
|
|
|
|
force_random_password: true,
|
2014-07-15 08:30:05 -04:00
|
|
|
password_expires_at: nil
|
2013-06-13 14:06:27 -04:00
|
|
|
}
|
|
|
|
|
2014-06-26 16:24:17 -04:00
|
|
|
@user = User.new(user_params.merge(opts))
|
2013-06-26 08:57:02 -04:00
|
|
|
@user.created_by_id = current_user.id
|
2013-10-24 13:27:23 -04:00
|
|
|
@user.generate_password
|
2014-07-15 07:25:11 -04:00
|
|
|
@user.generate_reset_token
|
2013-12-26 03:20:36 -05:00
|
|
|
@user.skip_confirmation!
|
2011-10-08 17:36:38 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
2013-06-26 08:57:02 -04:00
|
|
|
if @user.save
|
|
|
|
format.html { redirect_to [:admin, @user], notice: 'User was successfully created.' }
|
|
|
|
format.json { render json: @user, status: :created, location: @user }
|
2011-10-08 17:36:38 -04:00
|
|
|
else
|
2013-06-22 08:08:11 -04:00
|
|
|
format.html { render "new" }
|
2013-06-26 08:57:02 -04:00
|
|
|
format.json { render json: @user.errors, status: :unprocessable_entity }
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-07-16 08:12:33 -04:00
|
|
|
user_params_with_pass = user_params.dup
|
|
|
|
|
2014-06-26 16:24:17 -04:00
|
|
|
if params[:user][:password].present?
|
2014-07-16 08:12:33 -04:00
|
|
|
user_params_with_pass.merge!(
|
2014-06-26 16:24:17 -04:00
|
|
|
password: params[:user][:password],
|
|
|
|
password_confirmation: params[:user][:password_confirmation],
|
|
|
|
)
|
2014-02-25 03:15:43 -05:00
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
2015-04-06 07:26:41 -04:00
|
|
|
user.skip_reconfirmation!
|
2014-07-16 08:12:33 -04:00
|
|
|
if user.update_attributes(user_params_with_pass)
|
2013-06-26 08:57:02 -04:00
|
|
|
format.html { redirect_to [:admin, user], notice: 'User was successfully updated.' }
|
2011-10-08 17:36:38 -04:00
|
|
|
format.json { head :ok }
|
|
|
|
else
|
2013-03-26 01:42:08 -04:00
|
|
|
# restore username to keep form action url.
|
2013-06-26 08:57:02 -04:00
|
|
|
user.username = params[:id]
|
2013-06-22 08:08:11 -04:00
|
|
|
format.html { render "edit" }
|
2013-06-26 08:57:02 -04:00
|
|
|
format.json { render json: user.errors, status: :unprocessable_entity }
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2016-02-25 03:20:28 -05:00
|
|
|
DeleteUserWorker.perform_async(current_user.id, user.id)
|
2011-10-08 17:36:38 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
2016-02-17 08:41:33 -05:00
|
|
|
format.html { redirect_to admin_users_path, notice: "The user is being deleted." }
|
2011-10-08 17:36:38 -04:00
|
|
|
format.json { head :ok }
|
|
|
|
end
|
|
|
|
end
|
2013-01-25 13:38:24 -05:00
|
|
|
|
2014-06-23 03:45:26 -04:00
|
|
|
def remove_email
|
|
|
|
email = user.emails.find(params[:email_id])
|
|
|
|
email.destroy
|
|
|
|
|
2015-04-30 10:17:03 -04:00
|
|
|
user.update_secondary_emails!
|
2015-02-06 18:23:58 -05:00
|
|
|
|
2014-06-23 03:45:26 -04:00
|
|
|
respond_to do |format|
|
2015-10-20 03:28:28 -04:00
|
|
|
format.html { redirect_back_or_admin_user(notice: "Successfully removed email.") }
|
2014-06-23 03:45:26 -04:00
|
|
|
format.js { render nothing: true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-25 13:38:24 -05:00
|
|
|
protected
|
|
|
|
|
2013-06-26 08:57:02 -04:00
|
|
|
def user
|
2014-01-19 13:55:59 -05:00
|
|
|
@user ||= User.find_by!(username: params[:id])
|
2013-01-25 13:38:24 -05:00
|
|
|
end
|
2014-06-26 08:11:45 -04:00
|
|
|
|
|
|
|
def user_params
|
|
|
|
params.require(:user).permit(
|
2014-06-26 16:24:17 -04:00
|
|
|
:email, :remember_me, :bio, :name, :username,
|
2014-06-26 08:11:45 -04:00
|
|
|
:skype, :linkedin, :twitter, :website_url, :color_scheme_id, :theme_id, :force_random_password,
|
2015-02-13 07:33:28 -05:00
|
|
|
:extern_uid, :provider, :password_expires_at, :avatar, :hide_no_ssh_key, :hide_no_password,
|
2014-12-29 11:07:23 -05:00
|
|
|
:projects_limit, :can_create_group, :admin, :key_id
|
2014-06-26 08:11:45 -04:00
|
|
|
)
|
|
|
|
end
|
2015-10-20 03:28:28 -04:00
|
|
|
|
|
|
|
def redirect_back_or_admin_user(options = {})
|
|
|
|
redirect_back_or_default(default: default_route, options: options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_route
|
|
|
|
[:admin, @user]
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|