Merge pull request #5291 from betagouv/dev

This commit is contained in:
Pierre de La Morinerie 2020-06-23 16:53:35 +02:00 committed by GitHub
commit 858741a381
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 84 additions and 56 deletions

View file

@ -59,7 +59,7 @@ gem 'puma' # Use Puma as the app server
gem 'pundit'
gem 'rack-attack'
gem 'rack-mini-profiler'
gem 'rails', '= 5.2.4.2'
gem 'rails', '= 5.2.4.3'
gem 'rails-i18n' # Locales par défaut
gem 'rake-progressbar', require: false
gem 'react-rails'

View file

@ -20,25 +20,25 @@ GEM
specs:
aasm (5.0.1)
concurrent-ruby (~> 1.0)
actioncable (5.2.4.2)
actionpack (= 5.2.4.2)
actioncable (5.2.4.3)
actionpack (= 5.2.4.3)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.4.2)
actionpack (= 5.2.4.2)
actionview (= 5.2.4.2)
activejob (= 5.2.4.2)
actionmailer (5.2.4.3)
actionpack (= 5.2.4.3)
actionview (= 5.2.4.3)
activejob (= 5.2.4.3)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.4.2)
actionview (= 5.2.4.2)
activesupport (= 5.2.4.2)
actionpack (5.2.4.3)
actionview (= 5.2.4.3)
activesupport (= 5.2.4.3)
rack (~> 2.0, >= 2.0.8)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.4.2)
activesupport (= 5.2.4.2)
actionview (5.2.4.3)
activesupport (= 5.2.4.3)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
@ -53,25 +53,25 @@ GEM
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
active_storage_validations (0.8.7)
rails (>= 5.2.0)
activejob (5.2.4.2)
activesupport (= 5.2.4.2)
activejob (5.2.4.3)
activesupport (= 5.2.4.3)
globalid (>= 0.3.6)
activemodel (5.2.4.2)
activesupport (= 5.2.4.2)
activerecord (5.2.4.2)
activemodel (= 5.2.4.2)
activesupport (= 5.2.4.2)
activemodel (5.2.4.3)
activesupport (= 5.2.4.3)
activerecord (5.2.4.3)
activemodel (= 5.2.4.3)
activesupport (= 5.2.4.3)
arel (>= 9.0)
activestorage (5.2.4.2)
actionpack (= 5.2.4.2)
activerecord (= 5.2.4.2)
activestorage (5.2.4.3)
actionpack (= 5.2.4.3)
activerecord (= 5.2.4.3)
marcel (~> 0.3.1)
activestorage-openstack (1.4.1)
fog-openstack (~> 1.0)
marcel
mime-types
rails (>= 5.2.2)
activesupport (5.2.4.2)
activesupport (5.2.4.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
@ -317,7 +317,7 @@ GEM
domain_name (~> 0.5)
http_parser.rb (0.6.0)
httpclient (2.8.3)
i18n (1.8.2)
i18n (1.8.3)
concurrent-ruby (~> 1.0)
ipaddress (0.8.3)
jaro_winkler (1.5.4)
@ -361,7 +361,7 @@ GEM
railties (>= 4)
request_store (~> 1.0)
logstash-event (1.2.02)
loofah (2.5.0)
loofah (2.6.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
lumberjack (1.0.13)
@ -377,7 +377,7 @@ GEM
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.1009)
mimemagic (0.3.4)
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.1)
@ -462,7 +462,7 @@ GEM
pundit (2.0.1)
activesupport (>= 3.0.0)
raabro (1.1.6)
rack (2.2.2)
rack (2.2.3)
rack-attack (6.0.0)
rack (>= 1.0, < 3)
rack-mini-profiler (1.0.1)
@ -479,18 +479,18 @@ GEM
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.4.2)
actioncable (= 5.2.4.2)
actionmailer (= 5.2.4.2)
actionpack (= 5.2.4.2)
actionview (= 5.2.4.2)
activejob (= 5.2.4.2)
activemodel (= 5.2.4.2)
activerecord (= 5.2.4.2)
activestorage (= 5.2.4.2)
activesupport (= 5.2.4.2)
rails (5.2.4.3)
actioncable (= 5.2.4.3)
actionmailer (= 5.2.4.3)
actionpack (= 5.2.4.3)
actionview (= 5.2.4.3)
activejob (= 5.2.4.3)
activemodel (= 5.2.4.3)
activerecord (= 5.2.4.3)
activestorage (= 5.2.4.3)
activesupport (= 5.2.4.3)
bundler (>= 1.3.0)
railties (= 5.2.4.2)
railties (= 5.2.4.3)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.4)
actionpack (>= 5.0.1.x)
@ -504,9 +504,9 @@ GEM
rails-i18n (5.1.2)
i18n (>= 0.7, < 2)
railties (>= 5.0, < 6)
railties (5.2.4.2)
actionpack (= 5.2.4.2)
activesupport (= 5.2.4.2)
railties (5.2.4.3)
actionpack (= 5.2.4.3)
activesupport (= 5.2.4.3)
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
@ -701,7 +701,7 @@ GEM
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
websocket-driver (0.7.1)
websocket-driver (0.7.2)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
@ -795,7 +795,7 @@ DEPENDENCIES
pundit
rack-attack
rack-mini-profiler
rails (= 5.2.4.2)
rails (= 5.2.4.3)
rails-controller-testing
rails-i18n
rake-progressbar

View file

@ -1,11 +1,16 @@
class PingController < ApplicationController
def index
Rails.logger.silence do
if (ActiveRecord::Base.connected?)
head :ok, content_type: "application/json"
status_code = if File.file?(Rails.root.join("maintenance"))
# See https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#4.2-http-check%20disable-on-404
:not_found
elsif (ActiveRecord::Base.connected?)
:ok
else
head :internal_server_error, content_type: "application/json"
:internal_server_error
end
head status_code, content_type: "application/json"
end
end
end

View file

@ -1,7 +1,7 @@
module StringToHtmlHelper
def string_to_html(str, wrapper_tag = 'p')
html_formatted = simple_format(str, {}, { wrapper_tag: wrapper_tag })
with_links = html_formatted.gsub(URI.regexp, '<a target="_blank" rel="noopener" href="\0">\0</a>')
with_links = Anchored::Linker.auto_link(html_formatted, target: '_blank', rel: 'noopener')
sanitize(with_links, attributes: ['target', 'rel', 'href'])
end
end

View file

@ -174,11 +174,13 @@ class ProcedurePresentation < ApplicationRecord
end
def human_value_for_filter(filter)
if filter['table'] == 'type_de_champ'
case filter['table']
when 'type_de_champ', 'type_de_champ_private'
type_de_champ = TypeDeChamp.find_by(id: filter['column'])
return type_de_champ.dynamic_type.filter_to_human(filter['value'])
type_de_champ.dynamic_type.filter_to_human(filter['value'])
else
filter['value']
end
filter['value']
end
def add_filter(statut, field, value)
@ -187,7 +189,8 @@ class ProcedurePresentation < ApplicationRecord
table, column = field.split('/')
label = find_field(table, column)['label']
if table == 'type_de_champ'
case table
when 'type_de_champ', 'type_de_champ_private'
type_de_champ = TypeDeChamp.find_by(id: column)
value = type_de_champ.dynamic_type.human_to_filter(value)
end

View file

@ -69,7 +69,7 @@ Rails.application.routes.draw do
# Monitoring
#
get "/ping" => "ping#index", :constraints => { :ip => /127.0.0.1/ }
get "/ping" => "ping#index"
#
# Authentication

View file

@ -38,7 +38,6 @@ task :rollback do
branch = ENV.fetch('BRANCH')
domains.each do |domain|
sh "mina rollback domain=#{domain} branch=#{branch}"
sh "mina service:restart_puma domain=#{domain} branch=#{branch}"
sh "mina rollback service:restart_puma service:reload_nginx service:restart_delayed_job domain=#{domain} branch=#{branch}"
end
end

View file

@ -11,5 +11,15 @@ describe PingController, type: :controller do
it { expect(subject.status).to eq 500 }
end
context 'when a maintenance file is present' do
before do
allow(File).to receive(:file?).and_return(true)
end
it 'tells HAProxy that the app is in maintenance, but will be available again soon' do
expect(subject.status).to eq 404
end
end
end
end

View file

@ -9,9 +9,20 @@ RSpec.describe StringToHtmlHelper, type: :helper do
end
context "with a link" do
let(:description) { "https://d-s.fr" }
context "using an authorized scheme" do
let(:description) { "Cliquez sur https://d-s.fr pour continuer." }
it { is_expected.to eq("<p>Cliquez sur <a href=\"https://d-s.fr\" target=\"_blank\" rel=\"noopener\">https://d-s.fr</a> pour continuer.</p>") }
end
it { is_expected.to eq("<p><a target=\"_blank\" rel=\"noopener\" href=\"https://d-s.fr\">https://d-s.fr</a></p>") }
context "using a non-authorized scheme" do
let(:description) { "Cliquez sur file://etc/password pour continuer." }
it { is_expected.to eq("<p>Cliquez sur file://etc/password pour continuer.</p>") }
end
context "not actually an URL" do
let(:description) { "Pour info: il ne devrait y avoir aucun lien." }
it { is_expected.to eq("<p>Pour info: il ne devrait y avoir aucun lien.</p>") }
end
end
context "with empty decription" do