|
1class ApplicationController < ActionController::Base
|
|
2 protect_from_forgery with: :exception
|
|
|
|
4 before_action :reload_site
|
|
5 before_action :reload_parliament
|
|
6 before_action :service_unavailable, unless: :site_enabled?
|
|
7 before_action :authenticate, if: :site_protected?
|
|
8 before_action :redirect_to_url_without_format, if: :unknown_format?
|
|
|
|
10 before_action :set_seen_cookie_message, if: :show_cookie_message?
|
|
11 helper_method :show_cookie_message?, :public_petition_facets
|
|
|
|
13 hide_action :admin_request?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 authenticate_or_request_with_http_basic(Site.name) do |username, password|
|
|
23 Site.authenticate(username, password)
|
|
|
|
|
|
|
|
|
|
28 request.format.symbol == :csv
|
|
|
|
|
|
|
|
32 request.format.symbol == :json
|
|
|
|
|
- NilCheck - performs a nil-check » reek
- Complexity 1 » saikuro
|
|
|
|
|
|
|
|
- DuplicateMethodCall - calls 'request.path' 2 times » reek
- UncommunicativeVariableName - has the variable name 'e' » reek
- Complexity 3 » saikuro
|
39 def url_without_format
|
|
40 URI.parse(request.original_url).tap do |uri|
|
|
41 uri.path = File.join(File.dirname(request.path), File.basename(request.path, '.*'))
|
|
|
|
43 rescue URI::InvalidURIError => e
|
|
|
|
|
|
|
|
47 def redirect_to_url_without_format
|
|
48 redirect_to url_without_format
|
|
|
|
|
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
- Complexity 1 » saikuro
|
|
|
|
|
|
|
|
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
- Complexity 1 » saikuro
|
|
|
|
|
|
|
|
|
59 def service_unavailable
|
|
60 raise Site::ServiceUnavailable, "Sorry, the website is temporarily unavailable"
|
|
|
|
|
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
- Complexity 1 » saikuro
|
|
|
|
|
|
|
|
|
|
|
68 Site.protected? unless request.local?
|
|
|
|
|
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
- Complexity 1 » saikuro
|
71 def parliament_dissolved?
|
|
|
|
|
|
|
|
75 def redirect_to_home_page
|
|
|
|
|
|
|
|
79 def set_seen_cookie_message
|
|
80 cookies[:seen_cookie_message] = { value: 'yes', expires: 1.year.from_now, httponly: true }
|
|
|
|
|
|
|
|
84 headers['Access-Control-Allow-Origin'] = '*'
|
|
85 headers['Access-Control-Allow-Methods'] = 'GET'
|
|
86 headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept'
|
|
|
|
|
|
89 def show_cookie_message?
|
|
90 @show_cookie_message ||= cookies[:seen_cookie_message] != 'yes'
|
|
|
|
|
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
- Complexity 1 » saikuro
|
93 def public_petition_facets
|
|
94 I18n.t('public', scope: :"petitions.facets")
|
|
|
|
|
|
|
|
98 response.headers['Cache-Control'] = 'no-store, no-cache'
|
|
|
|
|
- UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
- Complexity 1 » saikuro
|
|
|
102 Time.current.getutc.iso8601
|
|
|
|
|