Remove global BROWSER and use browser helper

This commit is contained in:
Paul Chavard 2018-01-18 16:30:06 +01:00
parent aadc7c79dd
commit 8a55ac79f1
5 changed files with 10 additions and 29 deletions

View file

@ -2,7 +2,6 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :check_browser
before_action :load_navbar_left_pannel_partial_url
before_action :set_raven_context
before_action :authorize_request_for_profiler
@ -26,10 +25,6 @@ class ApplicationController < ActionController::Base
{}
end
def check_browser
BROWSER.value = BrowserService.get_browser(request)
end
def load_navbar_left_pannel_partial_url
controller = request.controller_class
method = params[:action]

View file

@ -1,17 +0,0 @@
class BrowserService
def self.get_browser request
BROWSER.value = Browser.new(request.user_agent)
end
def self.recommended_browser?
browser = BROWSER.value
return false if browser.chrome? && browser.version.to_i < 40
return false if browser.ie?(["<10"])
return false if browser.firefox? && browser.version.to_i < 45
return false if browser.opera? && browser.version.to_i < 19
return false if browser.safari? && browser.version.to_i < 8
true
end
end

View file

@ -1,7 +1,7 @@
- if !BrowserService.recommended_browser?
- if !browser.modern?
#support-navigator-banner.row
.col-xs-12
= BROWSER.value.name
= BROWSER.value.version
= browser.name
= browser.version
\-
Attention, votre navigateur n'est pas recommandé pour la navigation sur ce site internet. Aucun support ne pourra vous être prodigué en cas de dysfonctionnement.

View file

@ -1,3 +1,7 @@
BROWSER = Hashie::Mash.new ({
value: nil
})
Browser.modern_rules.clear
Browser.modern_rules << -> b { b.chrome? && b.version.to_i >= 40 }
Browser.modern_rules << -> b { b.ie?([">=10"]) }
Browser.modern_rules << -> b { b.edge? }
Browser.modern_rules << -> b { b.firefox? && b.version.to_i >= 45 }
Browser.modern_rules << -> b { b.opera? && b.version.to_i >= 19 }
Browser.modern_rules << -> b { b.safari? && b.version.to_i >= 8 }

View file

@ -69,7 +69,6 @@ end
DatabaseCleaner.strategy = :transaction
SIADETOKEN = :valid_token if !defined? SIADETOKEN
BROWSER.value = Browser.new('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)')
include Warden::Test::Helpers