Class: Dunlop::UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/dunlop/users_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#store_or_reset_params_q

Instance Method Details

#become_userObject



67
68
69
70
71
# File 'app/controllers/dunlop/users_controller.rb', line 67

def become_user
  @user = User.find(params[:id])
   @user, bypass_sign_in: true
  respond_with(@user, location: user_path)
end

#createObject



34
35
36
37
38
39
40
41
42
# File 'app/controllers/dunlop/users_controller.rb', line 34

def create
  @user = User.new user_params
  authorize! :create, @user
  if @user.save
    redirect_to dunlop.users_path
  else
    render action: :edit
  end
end

#destroyObject



73
74
75
76
77
# File 'app/controllers/dunlop/users_controller.rb', line 73

def destroy
  authorize! :destroy, @user
  @user.destroy
  redirect_to dunlop.users_path
end

#editObject



48
49
50
# File 'app/controllers/dunlop/users_controller.rb', line 48

def edit
  authorize! :update, @user
end

#edit_profileObject



11
12
# File 'app/controllers/dunlop/users_controller.rb', line 11

def edit_profile
end

#indexObject



24
25
26
27
# File 'app/controllers/dunlop/users_controller.rb', line 24

def index
  authorize! :index, User
  @users = User.active.page(params[:page])
end

#newObject



29
30
31
32
# File 'app/controllers/dunlop/users_controller.rb', line 29

def new
  @user = User.new
  authorize! :create, @user
end

#permissions_tableObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/dunlop/users_controller.rb', line 79

def permissions_table
  authorize! :permissions_table, User
  @table = Hash.new{|h,k| h[k] = Hash.new{|h2, k2| h2[k2] = []} }
  @users = User.active
  @users.each do |user|
    user.role_names.each do |role|
      if match = role.match(/(^[a-z0-9]+)-class-(.*)/)
        role_class = match[2].safe_constantize
        if role_class.respond_to?(:model_name)
          role = role_class.model_name.human
        else
          role = role_class.try(:name)
        end
        @table[role][user] << match[1]
      else
        @table[role][user] << "check"
      end
    end
  end
end

#profileObject



8
9
# File 'app/controllers/dunlop/users_controller.rb', line 8

def profile
end

#showObject



44
45
46
# File 'app/controllers/dunlop/users_controller.rb', line 44

def show
  authorize! :show, @user
end

#updateObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/dunlop/users_controller.rb', line 52

def update
  authorize! :update, @user
  if user_params[:password].blank?
    @user.update_without_password(user_params)
  else
    @user.update_attributes(user_params)
  end

  if @user.errors.present?
    render action: :edit
  else
    redirect_to dunlop.users_path
  end
end

#update_profileObject



14
15
16
17
18
19
20
21
22
# File 'app/controllers/dunlop/users_controller.rb', line 14

def update_profile
  user_params = params.require(:user).permit(:password, :confirmation_password)
  if @user.update_attributes(user_params)
     @user, bypass_sign_in: true
    redirect_to dunlop.profile_users_path
  else
    render action: :edit_profile
  end
end