Class: Admin::UsersController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/admin/users_controller.rb', line 27

def create
  @user.update_attributes(params[:user])
  if params[:user]["client"] == "1"
    @user.client = true
  end
  if @user.save
    flash[:notice] = t(:user_created_successfully)
    redirect_to admin_users_path
  else
    flash[:error] = t(:user_created_unsuccessfully)
    redirect_to new_admin_user_path
  end
end

#editObject



41
42
# File 'app/controllers/admin/users_controller.rb', line 41

def edit
end

#indexObject



6
7
8
9
10
# File 'app/controllers/admin/users_controller.rb', line 6

def index
  # This is extremely inefficient but we won't have enough users for this
  # in-memory sort to matter
  @users = User.unlocked.sort_by_name.select{|u| !u.client? }
end

#locked_clientsObject



20
21
22
# File 'app/controllers/admin/users_controller.rb', line 20

def locked_clients
  @users = User.locked.sort_by_name.select{|u| u.client? }
end

#locked_usersObject



12
13
14
# File 'app/controllers/admin/users_controller.rb', line 12

def locked_users
  @users = User.locked.sort_by_name.select{|u| !u.client? }
end

#newObject



24
25
# File 'app/controllers/admin/users_controller.rb', line 24

def new
end

#projectsObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/admin/users_controller.rb', line 57

def projects
  if request.post?
    params[:project].each do |key, value|
      project = Project.find(key.to_i)
      role = value.to_sym
      @user.has_no_roles_for!(project)
      @user.has_role!(role, project) unless role == :no_access
    end
    flash[:notice] = t(:roles_updated_successfully)
    redirect_to admin_users_path
  end
end

#unlocked_clientsObject



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

def unlocked_clients
  @users = User.unlocked.sort_by_name.select{|u| u.client? }
end

#updateObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/admin/users_controller.rb', line 44

def update
  params[:user]["locked"] == "1" ? @user.lock_access! : @user.unlock_access!

  @user.update_attributes(params[:user])
  if @user.save
    flash[:notice] = t(:user_updated_successfully)
    redirect_to user_path(@user)
  else
    flash[:error] = t(:user_updated_unsuccessfully)
    redirect_to edit_admin_user_path(@user)
  end
end