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

121 lines
3.1 KiB
Ruby
Raw Normal View History

class Admin::UsersController < Admin::ApplicationController
before_filter :user, only: [:show, :edit, :update, :destroy]
2013-01-26 05:08:34 -05:00
2011-10-08 17:36:38 -04:00
def index
2013-12-14 08:43:48 -05:00
@users = User.filter(params[:filter])
@users = @users.search(params[:name]) if params[:name].present?
@users = @users.alphabetically.page(params[:page])
2011-10-08 17:36:38 -04:00
end
def show
@personal_projects = user.personal_projects
@joined_projects = user.projects.joined(@user)
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_to :back, alert: "Successfully blocked"
else
2013-07-29 06:46:00 -04:00
redirect_to :back, alert: "Error occurred. User was not blocked"
end
end
def unblock
if user.activate
redirect_to :back, alert: "Successfully unblocked"
else
2013-07-29 06:46:00 -04:00
redirect_to :back, alert: "Error occurred. User was not unblocked"
end
end
2011-10-08 17:36:38 -04:00
def create
opts = {
force_random_password: true,
password_expires_at: Time.now
}
@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.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
if params[:user][:password].present?
user_params.merge(
password: params[:user][:password],
password_confirmation: params[:user][:password_confirmation],
)
end
2011-10-08 17:36:38 -04:00
respond_to do |format|
if user.update_attributes(user_params)
2013-10-15 04:19:19 -04:00
user.confirm!
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
# 1. Remove groups where user is the only owner
user.solo_owned_groups.map(&:destroy)
# 2. Remove user with all authored content including personal projects
user.destroy
2011-10-08 17:36:38 -04:00
respond_to do |format|
format.html { redirect_to admin_users_path }
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
respond_to do |format|
format.html { redirect_to :back, 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,
:projects_limit, :can_create_group, :admin
)
end
2011-10-08 17:36:38 -04:00
end