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 'pundit'
gem 'rack-attack' gem 'rack-attack'
gem 'rack-mini-profiler' gem 'rack-mini-profiler'
gem 'rails', '= 5.2.4.2' gem 'rails', '= 5.2.4.3'
gem 'rails-i18n' # Locales par défaut gem 'rails-i18n' # Locales par défaut
gem 'rake-progressbar', require: false gem 'rake-progressbar', require: false
gem 'react-rails' gem 'react-rails'

View file

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

View file

@ -1,11 +1,16 @@
class PingController < ApplicationController class PingController < ApplicationController
def index def index
Rails.logger.silence do Rails.logger.silence do
if (ActiveRecord::Base.connected?) status_code = if File.file?(Rails.root.join("maintenance"))
head :ok, content_type: "application/json" # 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 else
head :internal_server_error, content_type: "application/json" :internal_server_error
end end
head status_code, content_type: "application/json"
end end
end end
end end

View file

@ -1,7 +1,7 @@
module StringToHtmlHelper module StringToHtmlHelper
def string_to_html(str, wrapper_tag = 'p') def string_to_html(str, wrapper_tag = 'p')
html_formatted = simple_format(str, {}, { wrapper_tag: wrapper_tag }) 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']) sanitize(with_links, attributes: ['target', 'rel', 'href'])
end end
end end

View file

@ -174,11 +174,13 @@ class ProcedurePresentation < ApplicationRecord
end end
def human_value_for_filter(filter) 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']) 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 end
filter['value']
end end
def add_filter(statut, field, value) def add_filter(statut, field, value)
@ -187,7 +189,8 @@ class ProcedurePresentation < ApplicationRecord
table, column = field.split('/') table, column = field.split('/')
label = find_field(table, column)['label'] 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) type_de_champ = TypeDeChamp.find_by(id: column)
value = type_de_champ.dynamic_type.human_to_filter(value) value = type_de_champ.dynamic_type.human_to_filter(value)
end end

View file

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

View file

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

View file

@ -11,5 +11,15 @@ describe PingController, type: :controller do
it { expect(subject.status).to eq 500 } it { expect(subject.status).to eq 500 }
end 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
end end

View file

@ -9,9 +9,20 @@ RSpec.describe StringToHtmlHelper, type: :helper do
end end
context "with a link" do 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 end
context "with empty decription" do context "with empty decription" do