2013-01-20 06:20:50 -05:00
|
|
|
class Admin::UsersController < Admin::ApplicationController
|
2013-06-26 08:57:02 -04:00
|
|
|
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])
|
2013-06-26 08:57:02 -04:00
|
|
|
@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
|
2014-06-03 05:44:22 -04:00
|
|
|
@personal_projects = user.personal_projects
|
|
|
|
@joined_projects = user.projects.joined(@user)
|
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
|
2012-04-16 16:33:03 -04:00
|
|
|
redirect_to :back, alert: "Successfully blocked"
|
2012-09-16 07:44:54 -04:00
|
|
|
else
|
2013-07-29 06:46:00 -04:00
|
|
|
redirect_to :back, 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
|
2013-06-26 08:57:02 -04:00
|
|
|
if user.activate
|
2012-04-16 16:33:03 -04:00
|
|
|
redirect_to :back, alert: "Successfully unblocked"
|
2012-09-16 07:44:54 -04:00
|
|
|
else
|
2013-07-29 06:46:00 -04:00
|
|
|
redirect_to :back, alert: "Error occurred. User was not unblocked"
|
2012-04-16 16:33:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
def create
|
2013-06-13 14:06:27 -04:00
|
|
|
opts = {
|
|
|
|
force_random_password: true,
|
|
|
|
password_expires_at: Time.now
|
|
|
|
}
|
|
|
|
|
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
|
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-06-26 16:24:17 -04:00
|
|
|
if params[:user][:password].present?
|
|
|
|
user_params.merge(
|
|
|
|
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|
|
2014-06-26 16:24:17 -04:00
|
|
|
if user.update_attributes(user_params)
|
2013-10-15 04:19:19 -04:00
|
|
|
user.confirm!
|
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
|
2013-08-27 13:40:42 -04:00
|
|
|
# 1. Remove groups where user is the only owner
|
|
|
|
user.solo_owned_groups.map(&:destroy)
|
2013-08-27 06:44:58 -04:00
|
|
|
|
2013-08-27 13:40:42 -04:00
|
|
|
# 2. Remove user with all authored content including personal projects
|
2013-06-26 08:57:02 -04:00
|
|
|
user.destroy
|
2011-10-08 17:36:38 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
2013-01-25 13:38:24 -05:00
|
|
|
format.html { redirect_to admin_users_path }
|
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
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :back, notice: "Successfully removed email." }
|
|
|
|
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,
|
|
|
|
:extern_uid, :provider, :password_expires_at, :avatar, :hide_no_ssh_key,
|
2014-06-26 16:24:17 -04:00
|
|
|
:projects_limit, :can_create_group, :admin
|
2014-06-26 08:11:45 -04:00
|
|
|
)
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|