Class: Forge::UsersController

Inherits:
ForgeController show all
Defined in:
lib/forge/app/controllers/forge/users_controller.rb

Instance Method Summary collapse

Methods inherited from ForgeController

#get_menu_items, #load_help, #set_crumbs, #set_title, #uses_ckeditor

Methods inherited from ApplicationController

#app_init

Instance Method Details

#approveObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/forge/app/controllers/forge/users_controller.rb', line 55

def approve
  if @user.id == current_user.id
    flash[:warning] = 'You cannot unapprove yourself'
  else
    @user.approved = @user.approved? ? false : true
    @user.save
    UserMailer.approved(@user).deliver if @user.approved?
  end
  redirect_to forge_users_path
end

#createObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/forge/app/controllers/forge/users_controller.rb', line 20

def create
  @user = User.new(params[:user])
  @user.role_ids = params[:role_ids]
  @user.approved = true unless @user.role_ids.join(" ").match(/1|2/).blank?
  if @user.save
    flash[:notice] = 'User was successfully created.'
    redirect_to(forge_users_path)
  else
    render :action => "new"
  end
end

#destroyObject



50
51
52
53
# File 'lib/forge/app/controllers/forge/users_controller.rb', line 50

def destroy
  @user.destroy
  redirect_to(forge_users_path)
end

#indexObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/forge/app/controllers/forge/users_controller.rb', line 5

def index
  respond_to do |format|
    format.html { @users = User.paginate(:per_page => 10, :page => params[:page]) }
    format.js { 
      params[:q] ||= ''
      @users = User.where("LOWER(email) LIKE ?", "%#{params[:q].downcase}%")
      render :partial => "user", :collection => @users
    }
  end
end

#newObject



16
17
18
# File 'lib/forge/app/controllers/forge/users_controller.rb', line 16

def new
  @user = User.new
end

#updateObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/forge/app/controllers/forge/users_controller.rb', line 32

def update
  params[:user].delete_if { |key, value| [:password, :password_confirmation].include?(key.to_sym) && value.blank? } # passing blank password causes devise to complain
  # TODO: make this a lot nicer than it is now
  # ensure that only admins and super_admins can change roles
  if current_user.is_admin? || current_user.is_super_admin?
    if current_user.is_admin?
      params[:role_ids].delete(Role.find_by_title("Super Admin").id.to_s) rescue nil # ensure admin can't escalate to super_admin
    end
    @user.role_ids = params[:role_ids]
  end
  if @user.update_attributes(params[:user])
    flash[:notice] = 'User was successfully updated.'
    redirect_to(forge_users_path)
  else
    render :action => "edit"
  end
end