Skip to content

Commit 2c1c0d2

Browse files
committed
remove all users from /admin and improve auth method
1 parent 82572cb commit 2c1c0d2

3 files changed

Lines changed: 10 additions & 17 deletions

File tree

app/admin/dashboard.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@
1414
#
1515
columns do
1616
column do
17-
panel "User" do
18-
ul do
19-
User.all.map do |user|
20-
li link_to(user.email, edit_user_registration_path(user))
21-
end
17+
panel "Users" do
18+
para link_to("Manage all users (#{User.count})", admin_users_path)
2219
end
2320
end
24-
end
2521

2622
column do
2723
panel "Info" do

app/controllers/application_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def configure_permitted_parameters
1818
devise_parameter_sanitizer.permit(:account_update, keys: [:username])
1919
end
2020

21+
def authenticate_admin!
22+
redirect_to root_path unless current_user&.admin
23+
end
24+
2125
def user_not_authorized
2226
flash[:alert] = 'You are not authorized to perform this action.'
2327
redirect_to(request.referrer || root_path)

config/initializers/active_admin.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@
9898
# will call the method to return the path.
9999
#
100100
# Default:
101-
config.logout_link_path = :destroy_admin_user_session_path
101+
config.logout_link_path = :destroy_user_session_path
102+
config.logout_link_method = :delete
103+
config.authentication_method = :authenticate_admin!
104+
config.current_user_method = :current_user
102105

103106
# This setting changes the http method used when rendering the
104107
# link. For example :get, :delete, :put, etc..
@@ -290,14 +293,4 @@
290293
# You can inherit it with own class and inject it for all resources
291294
#
292295
# config.order_clause = MyOrderClause
293-
def authenticate_admin!
294-
redirect_to new_user_session_path unless current_user && current_user.admin
295-
end
296-
297-
ActiveAdmin.setup do |config|
298-
config.authentication_method = :authenticate_admin!
299-
config.current_user_method = :current_user
300-
config.logout_link_path = :destroy_user_session_path
301-
config.logout_link_method = :delete
302-
end
303296
end

0 commit comments

Comments
 (0)