-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
application_controller.rb
54 lines (45 loc) · 1.19 KB
/
application_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# All Administrate controllers inherit from this `Admin::ApplicationController`,
# making it the ideal place to put authentication logic or other
# before_actions.
#
# If you want to add pagination or other controller-level concerns,
# you're free to overwrite the RESTful controller actions.
module Admin
class ApplicationController < Administrate::ApplicationController
include Administrate::Punditize
class AdminUser
def id
nil
end
def name
"Admin"
end
def admin?
true
end
end
before_action :authenticate_admin
def authenticate_admin
user_id = session[:user_id]
@current_user = user_id ? Customer.find(user_id) : AdminUser.new
end
def pundit_user
@current_user
end
after_action :audit_log, only: [:create, :update, :destroy]
def audit_log
if resource = @requested_resource || @new_resource
Rails.logger.info(
sprintf(
"Audit Log: %s %s #%d by %s at %s",
action_name.capitalize,
resource.class,
resource.id,
pundit_user.name,
Time.zone.now.to_s
)
)
end
end
end
end