Module: Workarea::Impersonation
Instance Method Summary
collapse
#admin_browse_as_guest, #admin_browsing_as_guest?, #stop_admin_guest_browsing, #touch_admin_guest_browsing
#current_user, #login, #logout, #redirect_back_or, #remember_location, #require_login, #require_logout, #require_password_changes, #return_to, #touch_auth_cookie
#authorized?, #check_authorization, #require_admin, #required_permissions, #unauthorized_user
Instance Method Details
#current_admin ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'app/controllers/workarea/impersonation.rb', line 43
def current_admin
@current_admin ||=
if impersonating? || admin_browsing_as_guest?
User.find(session[:admin_id])
elsif current_user.try(:admin?)
current_user
end
end
|
#current_impersonation ⇒ Object
52
53
54
55
|
# File 'app/controllers/workarea/impersonation.rb', line 52
def current_impersonation
return @current_impersonation if defined?(@current_impersonation)
@current_impersonation = User.find(cookies.signed[:user_id]) rescue nil
end
|
#impersonate_user(user) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/controllers/workarea/impersonation.rb', line 15
def impersonate_user(user)
session[:admin_id] = current_user.id
cookies.signed[:user_id] = {
value: user.id,
expires: Workarea.config.customer_session_timeout.from_now
}
user.mark_impersonated_by!(current_user)
@current_user = user
end
|
#impersonating?(user = nil) ⇒ Boolean
36
37
38
39
40
41
|
# File 'app/controllers/workarea/impersonation.rb', line 36
def impersonating?(user = nil)
session[:admin_id].present? &&
cookies.signed[:user_id].present? &&
session[:admin_id] != cookies.signed[:user_id] &&
(user.blank? || user.id.to_s == cookies.signed[:user_id])
end
|
#keep_auth_alive ⇒ Object
64
65
66
67
68
69
70
|
# File 'app/controllers/workarea/impersonation.rb', line 64
def keep_auth_alive
if impersonating?
touch_impersonation
else
super
end
end
|
#logged_in? ⇒ Boolean
Override when impersonating to prevent IP address and user agent validation.
76
77
78
79
80
81
82
|
# File 'app/controllers/workarea/impersonation.rb', line 76
def logged_in?
if impersonating?
current_user.present?
else
super
end
end
|
#stop_impersonation ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'app/controllers/workarea/impersonation.rb', line 27
def stop_impersonation
cookies.signed[:user_id] = {
value: current_admin.id,
expires: Workarea.config.admin_session_timeout.from_now
}
session.delete(:admin_id)
end
|
#touch_impersonation ⇒ Object
57
58
59
60
61
62
|
# File 'app/controllers/workarea/impersonation.rb', line 57
def touch_impersonation
cookies.signed[:user_id] = {
value: cookies.signed[:user_id],
expires: Workarea.config.customer_session_timeout.from_now
}
end
|