Class: Webhookdb::Service::Auth::Impersonation
- Inherits:
-
Object
- Object
- Webhookdb::Service::Auth::Impersonation
- Defined in:
- lib/webhookdb/service/auth.rb
Instance Attribute Summary collapse
-
#admin_customer ⇒ Object
readonly
Returns the value of attribute admin_customer.
-
#warden ⇒ Object
readonly
Returns the value of attribute warden.
Instance Method Summary collapse
-
#initialize(warden) ⇒ Impersonation
constructor
A new instance of Impersonation.
- #is? ⇒ Boolean
- #off(admin_customer) ⇒ Object
- #on(target_customer) ⇒ Object
Constructor Details
#initialize(warden) ⇒ Impersonation
Returns a new instance of Impersonation.
117 118 119 |
# File 'lib/webhookdb/service/auth.rb', line 117 def initialize(warden) @warden = warden end |
Instance Attribute Details
#admin_customer ⇒ Object (readonly)
Returns the value of attribute admin_customer.
115 116 117 |
# File 'lib/webhookdb/service/auth.rb', line 115 def admin_customer @admin_customer end |
#warden ⇒ Object (readonly)
Returns the value of attribute warden.
115 116 117 |
# File 'lib/webhookdb/service/auth.rb', line 115 def warden @warden end |
Instance Method Details
#is? ⇒ Boolean
121 122 123 124 |
# File 'lib/webhookdb/service/auth.rb', line 121 def is? return false unless self.warden.authenticated?(:admin) return self.warden.session(:admin)["impersonating"].present? end |
#off(admin_customer) ⇒ Object
132 133 134 135 136 |
# File 'lib/webhookdb/service/auth.rb', line 132 def off(admin_customer) self.warden.logout(:customer) self.warden.session(:admin).delete("impersonating") self.warden.set_user(admin_customer, scope: :customer) end |
#on(target_customer) ⇒ Object
126 127 128 129 130 |
# File 'lib/webhookdb/service/auth.rb', line 126 def on(target_customer) self.warden.session(:admin)["impersonating"] = target_customer.id self.warden.logout(:customer) self.warden.set_user(target_customer, scope: :customer) end |