From 7c3ea5b7bc6c94b729800f8e09c2aa82491091a3 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 25 Feb 2015 11:37:21 +0100 Subject: [PATCH] Fix subscribing to private channels This was a combination of 2 bugs: * we didn't do deep_merge on config in ruby app, so that any nested properties set in the javascript app would be overwritten * channelPrefix was not properly set for Travis CI Pro --- app/utils/pusher.coffee | 2 +- config/environment.js | 1 + waiter/lib/travis/utils/deep_merge.rb | 11 +++++++++++ waiter/lib/travis/web/app.rb | 4 +++- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 waiter/lib/travis/utils/deep_merge.rb diff --git a/app/utils/pusher.coffee b/app/utils/pusher.coffee index 05c97e5b..f1cff14e 100644 --- a/app/utils/pusher.coffee +++ b/app/utils/pusher.coffee @@ -39,7 +39,7 @@ TravisPusher.prototype.unsubscribe = (channel) -> @pusher.unsubscribe(channel) if @pusher?.channel(channel) TravisPusher.prototype.prefix = (channel) -> - prefix = ENV.pusher.channel_prefix || '' + prefix = ENV.pusher.channelPrefix || '' if channel.indexOf(prefix) != 0 "#{prefix}#{channel}" else diff --git a/config/environment.js b/config/environment.js index 3383b64c..ab37334f 100644 --- a/config/environment.js +++ b/config/environment.js @@ -42,6 +42,7 @@ module.exports = function(environment) { ENV.pro = true; ENV.apiEndpoint = 'https://api.travis-ci.com'; ENV.pusher.key = '59236bc0716a551eab40'; + ENV.pusher.channelPrefix = 'private-'; ENV.pagesEndpoint = 'https://billing.travis-ci.com'; ENV.billingEndpoint = 'https://billing.travis-ci.com'; ENV.endpoints = { diff --git a/waiter/lib/travis/utils/deep_merge.rb b/waiter/lib/travis/utils/deep_merge.rb new file mode 100644 index 00000000..ac0a5f1a --- /dev/null +++ b/waiter/lib/travis/utils/deep_merge.rb @@ -0,0 +1,11 @@ +module Travis + module DeepMerge + def deep_merge(hash, other_hash) + hash.merge(other_hash) do |key, oldval, newval| + oldval = oldval.to_hash if oldval.respond_to?(:to_hash) + newval = newval.to_hash if newval.respond_to?(:to_hash) + oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? deep_merge(oldval, newval) : newval + end + end + end +end diff --git a/waiter/lib/travis/web/app.rb b/waiter/lib/travis/web/app.rb index 91211447..bf5ba49a 100644 --- a/waiter/lib/travis/web/app.rb +++ b/waiter/lib/travis/web/app.rb @@ -4,10 +4,12 @@ require 'rack/protection' require 'delegate' require 'time' require 'json' +require 'travis/utils/deep_merge' class Travis::Web::App autoload :AltVersions, 'travis/web/app/alt_versions' autoload :MobileRedirect, 'travis/web/app/mobile_redirect' + include Travis::DeepMerge S3_URL = 'https://s3.amazonaws.com/travis-web-production/assets' @@ -206,7 +208,7 @@ class Travis::Web::App string.gsub!(regexp) do ember_config = JSON.parse(URI.unescape($1)) - config = ember_config.merge config + config = deep_merge ember_config, config config = URI.escape config.to_json %(