From 8e5aa5093ab6e67db4f603a44bb7027245b91a21 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 15 Oct 2013 14:31:52 +0200 Subject: detect os in browser and show proper download link We add a class to the html element based on the detected os and use that to pick which download link should be visible. If we detect an os that is not supported we display a deactivated download link instead with all alternatives. --- core/app/assets/javascripts/platform.js | 92 ++++++++++++++++++++++ core/app/helpers/core_helper.rb | 38 ++++++++- core/app/views/common/_download_for_os.html.haml | 16 ++++ core/app/views/common/_home_page_buttons.html.haml | 5 +- core/config/locales/en.yml | 12 ++- 5 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 core/app/assets/javascripts/platform.js create mode 100644 core/app/views/common/_download_for_os.html.haml (limited to 'core') diff --git a/core/app/assets/javascripts/platform.js b/core/app/assets/javascripts/platform.js new file mode 100644 index 0000000..3ab77d7 --- /dev/null +++ b/core/app/assets/javascripts/platform.js @@ -0,0 +1,92 @@ +/* Inspired by mozillas platform detection: + https://github.com/mozilla/bedrock/tree/master/media/js/base +*/ + (function () { + 'use strict'; + function getPlatform() { + var ua = navigator.userAgent, + pf = navigator.platform; + if (/Win(16|9[x58]|NT( [1234]| 5\.0| [^0-9]|[^ -]|$))/.test(ua) || + /Windows ([MC]E|9[x58]|3\.1|4\.10|NT( [1234]| 5\.0| [^0-9]|[^ ]|$))/.test(ua) || + /Windows_95/.test(ua)) { + /** + * Officially unsupported platforms are Windows 95, 98, ME, NT 4.x, 2000 + * These regular expressions match: + * - Win16 + * - Win9x + * - Win95 + * - Win98 + * - WinNT (not followed by version or followed by version <= 5) + * - Windows ME + * - Windows CE + * - Windows 9x + * - Windows 95 + * - Windows 98 + * - Windows 3.1 + * - Windows 4.10 + * - Windows NT (not followed by version or followed by version <= 5) + * - Windows_95 + */ + return 'oldwin'; + } + if (ua.indexOf("MSIE 6.0") !== -1 && + ua.indexOf("Windows NT 5.1") !== -1 && + ua.indexOf("SV1") === -1) { + // Windows XP SP1 + return 'oldwin'; + } + if (pf.indexOf("Win32") !== -1 || + pf.indexOf("Win64") !== -1) { + return 'windows'; + } + if (/android/i.test(ua)) { + return 'android'; + } + if (/armv[6-7]l/.test(pf)) { + return 'android'; + } + if (pf.indexOf("Linux") !== -1) { + if (pf.indexOf("64") !== -1) { + return 'linux64'; + } else { + return 'linux32'; + } + } + if (pf.indexOf("MacPPC") !== -1) { + return 'oldmac'; + } + if (/Mac OS X 10.[0-5]/.test(ua)) { + return 'oldmac'; + } + if (pf.indexOf('iPhone') !== -1 || + pf.indexOf('iPad') !== -1 || + pf.indexOf('iPod') !== -1 ) { + return 'ios'; + } + if (ua.indexOf("Mac OS X") !== -1) { + return 'osx'; + } + if (ua.indexOf("MSIE 5.2") !== -1) { + return 'oldmac'; + } + if (pf.indexOf("Mac") !== -1) { + return 'oldmac'; + } + if (navigator.platform === '' && + navigator.userAgent.indexOf("Firefox") !== -1 && + navigator.userAgent.indexOf("Mobile") !== -1) { + return 'fxos'; + } + + return 'other'; + } + (function () { + // Immediately set the platform classname on the html-element + // to avoid lots of flickering + var h = document.documentElement; + window.site = { + platform : getPlatform() + }; + h.className = window.site.platform; + })(); + })(); diff --git a/core/app/helpers/core_helper.rb b/core/app/helpers/core_helper.rb index a496144..29a4700 100644 --- a/core/app/helpers/core_helper.rb +++ b/core/app/helpers/core_helper.rb @@ -10,4 +10,40 @@ module CoreHelper render 'common/home_page_buttons' end -end \ No newline at end of file + def available_clients + CLIENT_AVAILABILITY + end + + def alternative_client_links(os = nil) + alternative_clients(os).map do |client| + link_to(client.capitalize, client_download_url(client)) + end + end + + def alternative_clients(os = nil) + CLIENT_AVAILABILITY - [os] + end + + def client_download_url(os = nil) + client_download_domain(os) + client_download_path(os) + end + + def client_download_domain(os) + "https://downloads.leap.se" + end + + def client_download_path(os) + CLIENT_DOWNLOAD_PATHS[os] || '/client' + end + + + CLIENT_AVAILABILITY = %w/linux32 linux64 mac windows android/ + CLIENT_DOWNLOAD_PATHS = { + android: '/client/android', + linux: '/client/linux', + linux32: '/client/linux/Bitmask-linux32-latest.tar.bz2', + linux64: '/client/linux/Bitmask-linux64-latest.tar.bz2', + osx: '/client/osx/Bitmask-OSC-latest.dmg', + windows: '/client/windows' + }.with_indifferent_access +end diff --git a/core/app/views/common/_download_for_os.html.haml b/core/app/views/common/_download_for_os.html.haml new file mode 100644 index 0000000..b7c88ba --- /dev/null +++ b/core/app/views/common/_download_for_os.html.haml @@ -0,0 +1,16 @@ +- os = download_for_os +%div{:class => "os-#{os}"} + %span.link + - btn_class = (os == "other") ? "disabled" : "btn-primary" + = link_to client_download_url(os), :class => "btn btn-large #{btn_class}" do + .pull-left= huge_icon('mask') + = t(:download_client) + %br/ + %small= I18n.t("os.#{os}") + %span.info + = t(:client_info, :provider => content_tag(:b,APP_CONFIG[:domain])).html_safe + %br/ + - if os == "other" + = t(:all_downloads_info, :clients => alternative_client_links(os).to_sentence).html_safe + - else + = t(:other_downloads_info, :clients => alternative_client_links(os).to_sentence).html_safe diff --git a/core/app/views/common/_home_page_buttons.html.haml b/core/app/views/common/_home_page_buttons.html.haml index 7eb4c40..b87c867 100644 --- a/core/app/views/common/_home_page_buttons.html.haml +++ b/core/app/views/common/_home_page_buttons.html.haml @@ -1,11 +1,10 @@ - icon_color = :black -.home-buttons +.home-buttons.linux64 .row-fluid.first .span3 .download.span6 - %span.link= link_to(big_icon('arrow-down', icon_color) + t(:download_client), "https://downloads.leap.se/client", :class => 'btn btn-large') - %span.info= t(:download_client_info, :provider => content_tag(:b,APP_CONFIG[:domain])).html_safe + = render partial: 'common/download_for_os', collection: available_clients + ['other'] .span3 .row-fluid.second .login.span4 diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 25b377a..344eee4 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -21,10 +21,20 @@ en: are_you_sure: "Are you sure? This change cannot be undone." download_client: "Download Bitmask" - download_client_info: "The Bitmask application allows you to use %{provider} services. It is available for Linux, Mac, Windows, and Android." + client_info: "The Bitmask application allows you to use %{provider} services." + all_downloads_info: "It is available for %{clients}." + other_downloads_info: "It is also available for %{clients}." login_info: "Log in to change your account settings, create support tickets, and manage payments." signup_info: "Sign up for a new user account via this website (it is better if you use the Bitmask application to sign up, but this website works too)." welcome: "Welcome to %{provider}." get_help: "Get Help" help_info: "Can't login? Create a new support ticket anonymously." example_email: 'user@domain.org' + os: + linux32: "Linux (32 bit)" + linux64: "Linux (64 bit)" + windows: "Windows" + android: "Android" + mac: "Mac OSX" + other: "(not available for your OS.)" + -- cgit v1.2.3 From 4618bf296e735f47561dc1ddcccaaa701cae9daa Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 16 Oct 2013 11:25:58 +0200 Subject: remove leftover from testing os specific sections --- core/app/views/common/_home_page_buttons.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/app/views/common/_home_page_buttons.html.haml b/core/app/views/common/_home_page_buttons.html.haml index b87c867..e10fd38 100644 --- a/core/app/views/common/_home_page_buttons.html.haml +++ b/core/app/views/common/_home_page_buttons.html.haml @@ -1,6 +1,6 @@ - icon_color = :black -.home-buttons.linux64 +.home-buttons .row-fluid.first .span3 .download.span6 -- cgit v1.2.3 From 1384f6c43dde6a19f270416e34e39130a3d0a53d Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 18 Oct 2013 09:50:37 +0200 Subject: Make download links configurable This way we won't have to redeploy once the new links to the windows and the android version are there. Also this obviously offers more flexibility for providers. --- core/app/helpers/core_helper.rb | 36 ------------------------------------ core/app/helpers/download_helper.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 36 deletions(-) create mode 100644 core/app/helpers/download_helper.rb (limited to 'core') diff --git a/core/app/helpers/core_helper.rb b/core/app/helpers/core_helper.rb index 29a4700..4126906 100644 --- a/core/app/helpers/core_helper.rb +++ b/core/app/helpers/core_helper.rb @@ -10,40 +10,4 @@ module CoreHelper render 'common/home_page_buttons' end - def available_clients - CLIENT_AVAILABILITY - end - - def alternative_client_links(os = nil) - alternative_clients(os).map do |client| - link_to(client.capitalize, client_download_url(client)) - end - end - - def alternative_clients(os = nil) - CLIENT_AVAILABILITY - [os] - end - - def client_download_url(os = nil) - client_download_domain(os) + client_download_path(os) - end - - def client_download_domain(os) - "https://downloads.leap.se" - end - - def client_download_path(os) - CLIENT_DOWNLOAD_PATHS[os] || '/client' - end - - - CLIENT_AVAILABILITY = %w/linux32 linux64 mac windows android/ - CLIENT_DOWNLOAD_PATHS = { - android: '/client/android', - linux: '/client/linux', - linux32: '/client/linux/Bitmask-linux32-latest.tar.bz2', - linux64: '/client/linux/Bitmask-linux64-latest.tar.bz2', - osx: '/client/osx/Bitmask-OSC-latest.dmg', - windows: '/client/windows' - }.with_indifferent_access end diff --git a/core/app/helpers/download_helper.rb b/core/app/helpers/download_helper.rb new file mode 100644 index 0000000..f9c6c40 --- /dev/null +++ b/core/app/helpers/download_helper.rb @@ -0,0 +1,33 @@ +module DownloadHelper + + def alternative_client_links(os = nil) + alternative_clients(os).map do |client| + link_to(client.capitalize, client_download_url(client)) + end + end + + def alternative_clients(os = nil) + available_clients - [os] + end + + def client_download_url(os = nil) + client_download_domain + client_download_path(os) + end + + def client_download_path(os) + download_paths[os.to_s] || download_paths['other'] || '' + end + + def available_clients + APP_CONFIG[:available_clients] || [] + end + + def client_download_domain + APP_CONFIG[:client_download_domain] || '' + end + + def download_paths + APP_CONFIG[:download_paths] || {} + end + +end -- cgit v1.2.3 From 936015afe051c82d5677601f7f58944ed42b4623 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 18 Oct 2013 13:12:50 +0200 Subject: use https sources in Gemfiles and also in the documentation (#4109) --- core/Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/Gemfile b/core/Gemfile index 52ed377..b552dc5 100644 --- a/core/Gemfile +++ b/core/Gemfile @@ -1,4 +1,4 @@ -source "http://rubygems.org" +source "https://rubygems.org" # Declare your gem's dependencies in leap_web_core.gemspec. # Bundler will treat runtime dependencies like base dependencies, and -- cgit v1.2.3 From 23b9c58c4bd2e62ba63064c0e606d84f26fe74fa Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 21 Oct 2013 18:18:13 +0200 Subject: use osx not mac as an identifier for the os. --- core/config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 344eee4..4710a16 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -35,6 +35,6 @@ en: linux64: "Linux (64 bit)" windows: "Windows" android: "Android" - mac: "Mac OSX" + osx: "Mac OSX" other: "(not available for your OS.)" -- cgit v1.2.3 From 108938615ff7490080f80ea2d6bd1cd8037cdd84 Mon Sep 17 00:00:00 2001 From: elijah Date: Thu, 14 Nov 2013 02:19:57 -0800 Subject: minor improvements to the download button (proper localization, better image, better hooks for customization) --- core/app/helpers/download_helper.rb | 2 +- core/app/views/common/_download_for_os.html.haml | 4 ++-- core/app/views/common/_home_page_buttons.html.haml | 10 +++++++--- core/config/locales/en.yml | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) (limited to 'core') diff --git a/core/app/helpers/download_helper.rb b/core/app/helpers/download_helper.rb index f9c6c40..ee0fe73 100644 --- a/core/app/helpers/download_helper.rb +++ b/core/app/helpers/download_helper.rb @@ -2,7 +2,7 @@ module DownloadHelper def alternative_client_links(os = nil) alternative_clients(os).map do |client| - link_to(client.capitalize, client_download_url(client)) + link_to(I18n.t("os."+client), client_download_url(client)) end end diff --git a/core/app/views/common/_download_for_os.html.haml b/core/app/views/common/_download_for_os.html.haml index b7c88ba..4c096ce 100644 --- a/core/app/views/common/_download_for_os.html.haml +++ b/core/app/views/common/_download_for_os.html.haml @@ -8,8 +8,8 @@ %br/ %small= I18n.t("os.#{os}") %span.info - = t(:client_info, :provider => content_tag(:b,APP_CONFIG[:domain])).html_safe - %br/ + %div= t(:client_info, :provider => content_tag(:b,APP_CONFIG[:domain])).html_safe + %div - if os == "other" = t(:all_downloads_info, :clients => alternative_client_links(os).to_sentence).html_safe - else diff --git a/core/app/views/common/_home_page_buttons.html.haml b/core/app/views/common/_home_page_buttons.html.haml index e10fd38..3be12e2 100644 --- a/core/app/views/common/_home_page_buttons.html.haml +++ b/core/app/views/common/_home_page_buttons.html.haml @@ -2,10 +2,14 @@ .home-buttons .row-fluid.first - .span3 - .download.span6 + .span2 + .download.span8 = render partial: 'common/download_for_os', collection: available_clients + ['other'] - .span3 + .span2 + - if local_assigns[:divider] + .row-fluid + .span12 + = render local_assigns[:divider] .row-fluid.second .login.span4 %span.link= link_to(icon('ok-sign', icon_color) + t(:login), login_path, :class => 'btn') diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 4710a16..4abf4e8 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -23,7 +23,7 @@ en: download_client: "Download Bitmask" client_info: "The Bitmask application allows you to use %{provider} services." all_downloads_info: "It is available for %{clients}." - other_downloads_info: "It is also available for %{clients}." + other_downloads_info: "Bitmask is also available for %{clients}." login_info: "Log in to change your account settings, create support tickets, and manage payments." signup_info: "Sign up for a new user account via this website (it is better if you use the Bitmask application to sign up, but this website works too)." welcome: "Welcome to %{provider}." @@ -35,6 +35,6 @@ en: linux64: "Linux (64 bit)" windows: "Windows" android: "Android" - osx: "Mac OSX" + osx: "Mac OS" other: "(not available for your OS.)" -- cgit v1.2.3 From e7a8b49ae30bce36846a5ab8f1fa2bb981100224 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 19 Nov 2013 11:51:42 +0100 Subject: add dump_design_docs to CouchRest::Model::Utils:Migrate This is similar to the migrations but instead of uploading the design documents to couch it stores them in tmp/database/design.json within the rails directory. database is the supposed database name without prefixes or suffixes design is the name of the design doc CouchRest model would have created The files also contain a couchrest checksum so couchrest can detect they are up to date. This commit also cleans up a few redundant things in the extension to CouchRest::Model:Utils::Migrate that we used to have. There's no need to loop through the 'normal' models in load_all_models_with_engines since load_all_models_without_engines already does that. We were also overwriting all_models_and_proxies with exactly the same code as in the original. --- core/lib/extensions/couchrest.rb | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'core') diff --git a/core/lib/extensions/couchrest.rb b/core/lib/extensions/couchrest.rb index 91dfc1c..84cfbb3 100644 --- a/core/lib/extensions/couchrest.rb +++ b/core/lib/extensions/couchrest.rb @@ -47,28 +47,45 @@ module CouchRest def self.load_all_models_with_engines self.load_all_models_without_engines return unless defined?(Rails) - Dir[Rails.root + 'app/models/**/*.rb'].each do |path| - require path - end Dir[Rails.root + '*/app/models/**/*.rb'].each do |path| require path end end - def self.all_models_and_proxies - callbacks = migrate_each_model(find_models) - callbacks += migrate_each_proxying_model(find_proxying_models) - cleanup(callbacks) + class << self + alias_method_chain :load_all_models, :engines + end + + def dump_all_models + prepare_directory + find_models.each do |model| + model.design_docs.each do |design| + dump_design(model, design) + end + end end + protected + def dump_design(model, design) + dir = prepare_directory model.name.tableize + filename = design.id.sub('_design/','') + '.json' + puts dir + filename + design.checksum + File.open(dir + filename, "w") do |file| + file.write(JSON.pretty_generate(design.to_hash)) + end + end - class << self - alias_method_chain :load_all_models, :engines + def prepare_directory(dir = '') + dir = Rails.root + 'tmp' + 'designs' + dir + Dir.mkdir(dir) unless Dir.exists?(dir) + return dir end end end + end class ModelRailtie -- cgit v1.2.3 From cf68a79639861e69f61af85b43a3f72ed7763439 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 19 Nov 2013 15:04:14 +0100 Subject: couchrest:dump task will dump all design docs --- core/lib/tasks/leap_web_core_tasks.rake | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/lib/tasks/leap_web_core_tasks.rake b/core/lib/tasks/leap_web_core_tasks.rake index ae5b79b..734fae9 100644 --- a/core/lib/tasks/leap_web_core_tasks.rake +++ b/core/lib/tasks/leap_web_core_tasks.rake @@ -1,4 +1,9 @@ -# desc "Explaining what the task does" -# task :leap_web_core do -# # Task goes here -# end +namespace :couchrest do + + desc "Dump all the design docs found in each model" + task :dump => :environment do + CouchRest::Model::Utils::Migrate.load_all_models + CouchRest::Model::Utils::Migrate.dump_all_models + end +end + -- cgit v1.2.3 From 7596b6dbfa38d52acd447982e03e26374fb0d747 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 21 Nov 2013 12:49:25 +0100 Subject: rake tasks clean up expired tokens and sessions (#4568) --- core/leap_web_core.gemspec | 2 +- core/lib/tasks/leap_web_core_tasks.rake | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/leap_web_core.gemspec b/core/leap_web_core.gemspec index e98c892..c745f00 100644 --- a/core/leap_web_core.gemspec +++ b/core/leap_web_core.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.add_dependency "couchrest", "~> 1.1.3" s.add_dependency "couchrest_model", "~> 2.0.0" - s.add_dependency "couchrest_session_store", "~> 0.2.0" + s.add_dependency "couchrest_session_store", "~> 0.2.1" s.add_dependency "json" end diff --git a/core/lib/tasks/leap_web_core_tasks.rake b/core/lib/tasks/leap_web_core_tasks.rake index 734fae9..ec6abac 100644 --- a/core/lib/tasks/leap_web_core_tasks.rake +++ b/core/lib/tasks/leap_web_core_tasks.rake @@ -7,3 +7,19 @@ namespace :couchrest do end end +namespace :cleanup do + + desc "Cleanup all expired session documents" + task :sessions => :environment do + # make sure this is the same as in + # config/initializers/session_store.rb + store = CouchRest::Session::Store.new expire_after: 1800 + store.cleanup(store.expired) + end + + desc "Cleanup all expired tokens" + task :tokens => :environment do + Token.destroy_all_expired + end +end + -- cgit v1.2.3 From d6cd73bca7b2e368d5c044a0bb473a89b88aaf2f Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 9 Dec 2013 19:58:20 +0100 Subject: update couchrest session store and Gemfile.lock This will fix the crash when loading the landing page without a couch connection. --- core/leap_web_core.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/leap_web_core.gemspec b/core/leap_web_core.gemspec index c745f00..4109a03 100644 --- a/core/leap_web_core.gemspec +++ b/core/leap_web_core.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.add_dependency "couchrest", "~> 1.1.3" s.add_dependency "couchrest_model", "~> 2.0.0" - s.add_dependency "couchrest_session_store", "~> 0.2.1" + s.add_dependency "couchrest_session_store", "~> 0.2.2" s.add_dependency "json" end -- cgit v1.2.3 From e3b48ee60194b58c98cded485df4d936c5a4779d Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 12 Dec 2013 10:13:50 +0100 Subject: use the latest couchrest_session_store This one does not use our own error class for connection issues anymore. We'll remove that class in the next commit. So let's not rely on it. --- core/leap_web_core.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/leap_web_core.gemspec b/core/leap_web_core.gemspec index 4109a03..05874b2 100644 --- a/core/leap_web_core.gemspec +++ b/core/leap_web_core.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.add_dependency "couchrest", "~> 1.1.3" s.add_dependency "couchrest_model", "~> 2.0.0" - s.add_dependency "couchrest_session_store", "~> 0.2.2" + s.add_dependency "couchrest_session_store", "~> 0.2.3" s.add_dependency "json" end -- cgit v1.2.3 From 8fba6fae51e96ec3330896d107ab01fce2e322d9 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 12 Dec 2013 10:15:43 +0100 Subject: reraise with a better explaination on couch failure Removing our own error class for this. It interferes with couch_rest_session_store tryign to catch the same errors. --- core/lib/extensions/couchrest.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/lib/extensions/couchrest.rb b/core/lib/extensions/couchrest.rb index 84cfbb3..7450f59 100644 --- a/core/lib/extensions/couchrest.rb +++ b/core/lib/extensions/couchrest.rb @@ -23,10 +23,6 @@ module CouchRest end end - module Errors - class ConnectionFailed < CouchRestModelError; end - end - module Connection module ClassMethods @@ -36,7 +32,9 @@ module CouchRest rescue RestClient::Unauthorized, Errno::EHOSTUNREACH, Errno::ECONNREFUSED => e - raise CouchRest::Model::Errors::ConnectionFailed.new(e.to_s) + message = "Could not connect to couch database #{db} due to #{e.to_s}" + Rails.logger.warn message + raise e.class.new(message) end end -- cgit v1.2.3 From 72087656e5092fd744f4314c9a0e91825399fefc Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 13 Dec 2013 11:16:11 +0100 Subject: proceed even if the couch is unreachable * in case the user has a session id, keep it but proceed without a session * in case we can't initialize the models proceed * if APP_CONFIG[:reraise_errors] is set we'll crash instead in the latter case default to reraise errors in dev and test environments. --- core/leap_web_core.gemspec | 2 +- core/lib/extensions/couchrest.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/leap_web_core.gemspec b/core/leap_web_core.gemspec index 05874b2..7ca4d90 100644 --- a/core/leap_web_core.gemspec +++ b/core/leap_web_core.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.add_dependency "couchrest", "~> 1.1.3" s.add_dependency "couchrest_model", "~> 2.0.0" - s.add_dependency "couchrest_session_store", "~> 0.2.3" + s.add_dependency "couchrest_session_store", "~> 0.2.4" s.add_dependency "json" end diff --git a/core/lib/extensions/couchrest.rb b/core/lib/extensions/couchrest.rb index 7450f59..9f27c3a 100644 --- a/core/lib/extensions/couchrest.rb +++ b/core/lib/extensions/couchrest.rb @@ -34,7 +34,7 @@ module CouchRest Errno::ECONNREFUSED => e message = "Could not connect to couch database #{db} due to #{e.to_s}" Rails.logger.warn message - raise e.class.new(message) + raise e.class.new(message) if APP_CONFIG[:reraise_errors] end end -- cgit v1.2.3 From 95bd5d46095c3552a31cf719adab1c84971b95e8 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 17 Dec 2013 11:37:37 +0100 Subject: catch all rest client exceptions during initialization --- core/lib/extensions/couchrest.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/lib/extensions/couchrest.rb b/core/lib/extensions/couchrest.rb index 9f27c3a..a9a195e 100644 --- a/core/lib/extensions/couchrest.rb +++ b/core/lib/extensions/couchrest.rb @@ -29,7 +29,7 @@ module CouchRest def use_database(db) @database = prepare_database(db) - rescue RestClient::Unauthorized, + rescue RestClient::Exception, Errno::EHOSTUNREACH, Errno::ECONNREFUSED => e message = "Could not connect to couch database #{db} due to #{e.to_s}" -- cgit v1.2.3