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

- (Object) create



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

def create
  authorize Faalis::User
  group_ids = user_params[:groups]

  @user = Faalis::User.new(user_params)
  @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

- (Object) destroy



87
88
89
90
91
92
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 87

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

  @user.destroy
end

- (Object) edit



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

- (Object) edit_password



67
68
69
70
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 67

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

- (Object) index



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

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

- (Object) new



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

- (Object) password_params (private)



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

def password_params
  params.require(:user).permit(:password, :password_confirmation)
end

- (Object) show



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

- (Object) update



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 44

def update
  puts "---", user_params
  parameters = user_params
  #groups     = parameters.delete(:groups)
  group_ids  = parameters.delete(:groups).map(&:to_i)

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

  @user.groups = Faalis::Group.where(id: group_ids)
  @user.save

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

- (Object) update_password



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 72

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

- (Object) user_params (private)



100
101
102
103
104
105
106
107
108
# File 'app/controllers/faalis/dashboard/users_controller.rb', line 100

def user_params
  params[:user][:groups] ||= []
  params.require(:user).permit(:first_name,
                               :last_name,
                               :email,
                               :password,
                               :password_confirmation,
                               :groups => [])
end