diff --git a/Gemfile b/Gemfile index 71bd1ab65..c3a79fbed 100755 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,7 @@ gem "webpack-rails" gem "rollbar" gem "skylight", "1.4.0" gem "bunny" +gem "request_store" group :development, :test do gem "codecov", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 3ada5bd2c..996902092 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -204,6 +204,7 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (12.1.0) + request_store (1.3.2) responders (2.4.0) actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) @@ -291,6 +292,7 @@ DEPENDENCIES rails rails-erd rails_12factor + request_store rollbar rspec (~> 3.5.0) rspec-rails (~> 3.5.0) diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 9b8f3213c..d69743495 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -41,9 +41,12 @@ class ApplicationRecord < ActiveRecord::Base }.to_json end + def klass_name_as_string + (SPECIAL_NAMES[self.class] || self.class.name) + end + def chan_name - klass = self.class - "sync.#{(SPECIAL_NAMES[klass] || klass.name)}.#{self.id}" + "sync.#{klass_name_as_string}.#{self.id}" end def broadcast! diff --git a/app/models/device.rb b/app/models/device.rb index 16478803f..ad0246800 100644 --- a/app/models/device.rb +++ b/app/models/device.rb @@ -42,15 +42,15 @@ class Device < ApplicationRecord end def self.current - Thread.current[:device] + RequestStore.current[:device] end def self.current=(dev) - Thread.current[:device] = dev + RequestStore.current[:device] = dev end def self.current_jwt - Thread.current[:jwt] + RequestStore.current[:jwt] end def self.mine # For development mode debugging. diff --git a/app/mutations/auth/from_jwt.rb b/app/mutations/auth/from_jwt.rb index 9c3616b42..98ddb475c 100644 --- a/app/mutations/auth/from_jwt.rb +++ b/app/mutations/auth/from_jwt.rb @@ -7,7 +7,7 @@ module Auth def execute token = SessionToken.decode!(just_the_token) claims = token.unencoded - Thread.current[:jwt] = claims.deep_symbolize_keys + RequestStore.current[:jwt] = claims.deep_symbolize_keys User .find_by_email_or_id(claims["sub"]) rescue JWT::DecodeError, ActiveRecord::RecordNotFound, User::BadSub