Class: Faalis::Dashboard::UsersController

Inherits:
Dashboard::ApplicationController
  • Object
show all
Defined in:
app/controllers/faalis/dashboard/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 26

def create

  authorize Faalis::User
  #group_ids = user_params[:groups]

  parameters = user_params
  groups     = parameters.delete(:groups)
  @user = Faalis::User.new(parameters)
  group_ids    = groups.map(&:to_i)
  @user.groups = Faalis::Group.where(id: group_ids)

  respond_to do |f|
    if @user.save
      f.js
      f.html
    else
      f.js { render :errors }
      f.html
    end
  end
end

#destroyObject



93
94
95
96
97
98
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 93

def destroy
  @user = Faalis::User.find(params[:id])
  authorize @user

  @user.destroy
end

#editObject



20
21
22
23
24
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 20

def edit
  @user   = Faalis::User.find(params[:id])
  @groups = Faalis::Group.all
  authorize @user
end

#edit_passwordObject



73
74
75
76
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 73

def edit_password
  @user = Faalis::User.find(params[:id])
  authorize @user, :update?
end

#indexObject



4
5
6
7
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 4

def index
  authorize Faalis::User
  @users = Faalis::User.all
end

#newObject



9
10
11
12
13
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 9

def new
  authorize Faalis::User
  @user   = Faalis::User.new
  @groups = Faalis::Group.all
end

#showObject



15
16
17
18
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 15

def show
  @user = Faalis::User.find(params[:id])
  authorize @user
end

#updateObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 48

def update
  parameters = user_params
  groups     = parameters.delete(:groups)


  @user = Faalis::User.find(params[:id])
  authorize @user

  unless groups.nil?
    group_ids    = groups.map(&:to_i)
    @user.groups = Faalis::Group.where(id: group_ids)
    @user.save
  end

  respond_to do |f|
    if @user.update_without_password(parameters)
      f.js
      f.html
    else
      f.js { render :errors }
      f.html
    end
  end
end

#update_passwordObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 78

def update_password
  @user = Faalis::User.find(params[:id])
  authorize @user, :update?

  respond_to do |f|
    if @user.update(password_params)
      f.js
      f.html
    else
      f.js { render :errors }
      f.html
    end
  end
end