gitlab-org--gitlab-foss/app/controllers/admin/users_controller.rb

165 lines
4.2 KiB
Ruby
Raw Normal View History

class Admin::UsersController < Admin::ApplicationController
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])
@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
end
def projects
@personal_projects = user.personal_projects
@joined_projects = user.projects.joined(@user)
end
def groups
end
def keys
@keys = user.keys
2011-10-08 17:36:38 -04:00
end
def new
@user = User.new
2011-10-08 17:36:38 -04:00
end
def edit
user
2011-10-08 17:36:38 -04:00
end
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
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
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
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
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
opts = {
force_random_password: true,
2014-07-15 08:30:05 -04:00
password_expires_at: nil
}
@user = User.new(user_params.merge(opts))
@user.created_by_id = current_user.id
2013-10-24 13:27:23 -04:00
@user.generate_password
@user.generate_reset_token
@user.skip_confirmation!
2011-10-08 17:36:38 -04:00
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 }
2011-10-08 17:36:38 -04:00
else
format.html { render "new" }
format.json { render json: @user.errors, status: :unprocessable_entity }
2011-10-08 17:36:38 -04:00
end
end
end
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
2011-10-08 17:36:38 -04:00
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.' }
2011-10-08 17:36:38 -04:00
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 }
2011-10-08 17:36:38 -04:00
end
end
end
def destroy
DeleteUserWorker.perform_async(current_user.id, user.id)
2011-10-08 17:36:38 -04:00
respond_to do |format|
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
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
protected
def user
2014-01-19 13:55:59 -05:00
@user ||= User.find_by!(username: params[:id])
end
def user_params
params.require(:user).permit(
:email, :remember_me, :bio, :name, :username,
:skype, :linkedin, :twitter, :website_url, :color_scheme_id, :theme_id, :force_random_password,
: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
)
end
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