2020-04-30 08:09:45 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ApplicationCable
|
|
|
|
class Connection < ActionCable::Connection::Base
|
2020-06-01 14:08:07 -04:00
|
|
|
include Logging
|
|
|
|
|
2020-04-30 08:09:45 -04:00
|
|
|
identified_by :current_user
|
|
|
|
|
2020-06-01 14:08:07 -04:00
|
|
|
public :request
|
|
|
|
|
2020-04-30 08:09:45 -04:00
|
|
|
def connect
|
|
|
|
self.current_user = find_user_from_session_store
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_user_from_session_store
|
2020-10-02 08:09:03 -04:00
|
|
|
session = ActiveSession.sessions_from_ids(Array.wrap(session_id)).first
|
2020-04-30 08:09:45 -04:00
|
|
|
Warden::SessionSerializer.new('rack.session' => session).fetch(:user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def session_id
|
2020-10-02 08:09:03 -04:00
|
|
|
session_cookie = cookies[Gitlab::Application.config.session_options[:key]]
|
|
|
|
|
|
|
|
Rack::Session::SessionId.new(session_cookie).private_id if session_cookie.present?
|
2020-04-30 08:09:45 -04:00
|
|
|
end
|
2020-06-01 14:08:07 -04:00
|
|
|
|
|
|
|
def notification_payload(_)
|
|
|
|
super.merge!(params: request.params)
|
|
|
|
end
|
2020-04-30 08:09:45 -04:00
|
|
|
end
|
|
|
|
end
|