Module: Foreman::ThreadSession::Cleaner

Included in:
Api::BaseController, ApplicationController
Defined in:
lib/foreman/thread_session.rb

Overview

module to be include in controller to clear the session data after (and evenutally before) the request processing. Without it we're risking inter-users interference.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


22
23
24
# File 'lib/foreman/thread_session.rb', line 22

def self.included(base)
  base.around_filter :clear_thread
end

Instance Method Details

#clear_threadObject


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/foreman/thread_session.rb', line 26

def clear_thread
  if Thread.current[:user] && !Rails.env.test?
    Rails.logger.warn("Current user is set, but not expected. Clearing")
    Thread.current[:user] = nil
  end
  yield
ensure
  [:user, :organization, :location].each do |key|
    Thread.current[key] = nil
  end
end