Class: RailsOnboarding::Admin::UsersController
Overview
Admin users controller
Manage and view user onboarding progress
Constant Summary
collapse
- MYSQL_ADAPTERS =
%w[mysql2 trilogy mysql].freeze
BaseController::DEFAULT_PER_PAGE, BaseController::MAX_PER_PAGE
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.id_cast_type_for(adapter_name) ⇒ Object
The cast target for turning an integer id into something LIKE can match
is not portable. MySQL rejects CAST(x AS TEXT) outright as a syntax
error, and PostgreSQL accepts CAST(x AS CHAR) but reads it as
character(1), silently truncating the id to its first digit. SQLite
takes either. Defined on the class rather than as an instance method so
Rails doesn't expose it as a controller action.
16
17
18
|
# File 'app/controllers/rails_onboarding/admin/users_controller.rb', line 16
def self.id_cast_type_for(adapter_name)
MYSQL_ADAPTERS.include?(adapter_name.to_s.downcase) ? "CHAR" : "TEXT"
end
|
Instance Method Details
#bulk_action ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/controllers/rails_onboarding/admin/users_controller.rb', line 71
def bulk_action
action = params[:bulk_action]
user_ids = params[:user_ids] || []
case action
when "reset_onboarding"
bulk_reset_onboarding(user_ids)
when "complete_onboarding"
bulk_complete_onboarding(user_ids)
else
flash[:alert] = "Invalid bulk action"
end
redirect_to admin_users_path
end
|
#complete_onboarding ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/controllers/rails_onboarding/admin/users_controller.rb', line 45
def complete_onboarding
@user = user_class.find(params[:id])
if @user.complete_onboarding!
flash[:notice] = "Onboarding completed for user #{@user.id}"
redirect_to admin_user_path(@user)
else
flash[:alert] = "Failed to complete onboarding"
redirect_to admin_user_path(@user)
end
rescue StandardError => e
flash[:alert] = "Error completing onboarding: #{e.message}"
redirect_to admin_users_path
end
|
#export ⇒ Object
Exports every user matching the current filters, not just the page being
viewed - the button sits under the filter form, so "export what I'm
looking at" is the expectation. Deliberately unpaginated.
CSV is the only representation, so this deliberately doesn't respond_to:
a bare /admin/users/export would otherwise raise UnknownFormat, which the
admin error handler turns into a dashboard redirect with an alert.
93
94
95
96
97
|
# File 'app/controllers/rails_onboarding/admin/users_controller.rb', line 93
def export
send_data generate_users_csv,
filename: "onboarding_users_#{Date.current}.csv",
type: "text/csv"
end
|
#index ⇒ Object
20
21
22
23
|
# File 'app/controllers/rails_onboarding/admin/users_controller.rb', line 20
def index
@pagy, @users = paginate(filtered_users)
@stats = calculate_stats
end
|
#reset_onboarding ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/rails_onboarding/admin/users_controller.rb', line 30
def reset_onboarding
@user = user_class.find(params[:id])
if @user.reset_onboarding!
flash[:notice] = "Onboarding reset for user #{@user.id}"
redirect_to admin_user_path(@user)
else
flash[:alert] = "Failed to reset onboarding"
redirect_to admin_user_path(@user)
end
rescue StandardError => e
flash[:alert] = "Error resetting onboarding: #{e.message}"
redirect_to admin_users_path
end
|
#restart_onboarding ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'app/controllers/rails_onboarding/admin/users_controller.rb', line 60
def restart_onboarding
@user = user_class.find(params[:id])
@user.restart_onboarding!
flash[:notice] = "Onboarding restarted for user #{@user.id}"
redirect_to admin_user_path(@user)
rescue StandardError => e
flash[:alert] = "Error restarting onboarding: #{e.message}"
redirect_to admin_users_path
end
|
#show ⇒ Object
25
26
27
28
|
# File 'app/controllers/rails_onboarding/admin/users_controller.rb', line 25
def show
@user = user_class.find(params[:id])
load_user_analytics
end
|