Class: Webhookdb::Service::Auth::Impersonation

Inherits:
Object
  • Object
show all
Defined in:
lib/webhookdb/service/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_customerObject (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

#wardenObject (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

Returns:

  • (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