Merge pull request #7206 from betagouv/main

2022-04-28-01
This commit is contained in:
Paul Chavard 2022-04-28 11:27:27 +02:00 committed by GitHub
commit 961b9ab512
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 84 additions and 5 deletions

View file

@ -6,6 +6,8 @@ import 'regenerator-runtime/runtime';
import 'dom4'; import 'dom4';
import 'intersection-observer'; import 'intersection-observer';
import 'whatwg-fetch'; import 'whatwg-fetch';
import '@webcomponents/webcomponentsjs';
import '@stimulus/polyfills';
import './polyfills/insertAdjacentElement'; import './polyfills/insertAdjacentElement';
import './polyfills/dataset'; import './polyfills/dataset';

View file

@ -9,17 +9,18 @@ class Cron::FindDubiousProceduresJob < Cron::CronJob
'médical', 'handicap', 'maladie', 'allergie', 'hospitalisé', 'RQTH', 'vaccin' 'médical', 'handicap', 'maladie', 'allergie', 'hospitalisé', 'RQTH', 'vaccin'
] ]
def perform(*args)
# \\y is a word boundary # \\y is a word boundary
forbidden_regexp = FORBIDDEN_KEYWORDS def self.forbidden_regexp
.map { |keyword| "\\y#{keyword}\\y" } FORBIDDEN_KEYWORDS.map { |keyword| "\\y#{keyword}\\y" }
.join('|') .join('|')
end
def perform(*args)
# ~* -> case insensitive regexp match # ~* -> case insensitive regexp match
# https://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP # https://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP
forbidden_tdcs = TypeDeChamp forbidden_tdcs = TypeDeChamp
.joins(:procedure) .joins(:procedure)
.where("unaccent(types_de_champ.libelle) ~* unaccent(?)", forbidden_regexp) .where("unaccent(types_de_champ.libelle) ~* unaccent(?)", Cron::FindDubiousProceduresJob.forbidden_regexp)
.where(type_champ: [TypeDeChamp.type_champs.fetch(:text), TypeDeChamp.type_champs.fetch(:textarea)]) .where(type_champ: [TypeDeChamp.type_champs.fetch(:text), TypeDeChamp.type_champs.fetch(:textarea)])
.where(procedures: { closed_at: nil, whitelisted_at: nil }) .where(procedures: { closed_at: nil, whitelisted_at: nil })

View file

@ -94,6 +94,11 @@ class TypeDeChamp < ApplicationRecord
scope :not_repetition, -> { where.not(type_champ: type_champs.fetch(:repetition)) } scope :not_repetition, -> { where.not(type_champ: type_champs.fetch(:repetition)) }
scope :fillable, -> { where.not(type_champ: [type_champs.fetch(:header_section), type_champs.fetch(:explication)]) } scope :fillable, -> { where.not(type_champ: [type_champs.fetch(:header_section), type_champs.fetch(:explication)]) }
scope :dubious, -> {
where("unaccent(types_de_champ.libelle) ~* unaccent(?)", Cron::FindDubiousProceduresJob.forbidden_regexp)
.where(type_champ: [TypeDeChamp.type_champs.fetch(:text), TypeDeChamp.type_champs.fetch(:textarea)])
}
has_many :champ, inverse_of: :type_de_champ, dependent: :destroy do has_many :champ, inverse_of: :type_de_champ, dependent: :destroy do
def build(params = {}) def build(params = {})
super(params.merge(proxy_association.owner.params_for_champ)) super(params.merge(proxy_association.owner.params_for_champ))

View file

@ -4,6 +4,12 @@
link_to(@procedure.libelle, admin_procedure_path(@procedure)), link_to(@procedure.libelle, admin_procedure_path(@procedure)),
'Publication'] } 'Publication'] }
.container .container
- if @procedure.draft_types_de_champ.dubious.present?
.card.warning.mb-3
.card-title Attention, certains champs ne peuvent être demandé par l'administration. Voici les champs qui nous semblent suspect :
%ul
- @procedure.draft_types_de_champ.dubious.each do |dubious_champs|
%li.dubious-champs= "#{dubious_champs.libelle} (#{dubious_champs.description})"
.lien-demarche .lien-demarche
%h1 %h1
- if @procedure.brouillon? - if @procedure.brouillon?

View file

@ -16,7 +16,9 @@
"@reach/combobox": "^0.16.5", "@reach/combobox": "^0.16.5",
"@reach/slider": "^0.16.0", "@reach/slider": "^0.16.0",
"@sentry/browser": "6.12.0", "@sentry/browser": "6.12.0",
"@stimulus/polyfills": "^2.0.0",
"@tmcw/togeojson": "^4.3.0", "@tmcw/togeojson": "^4.3.0",
"@webcomponents/webcomponentsjs": "^2.6.0",
"babel-plugin-macros": "^2.8.0", "babel-plugin-macros": "^2.8.0",
"chartkick": "^4.1.1", "chartkick": "^4.1.1",
"core-js": "^3.6.5", "core-js": "^3.6.5",

View file

@ -122,4 +122,32 @@ describe 'Publishing a procedure', js: true do
expect(page).to have_selector('#preview-procedure') expect(page).to have_selector('#preview-procedure')
end end
end end
context 'when a procedure has dubious champs' do
let(:dubious_champs) do
[
build(:type_de_champ_text, libelle: 'NIR'),
build(:type_de_champ_text, libelle: 'carte bancaire')
]
end
let(:not_dubious_champs) do
[build(:type_de_champ_text, libelle: 'Prénom')]
end
let!(:procedure) do
create(:procedure,
:with_service,
instructeurs: instructeurs,
administrateur: administrateur,
types_de_champ: not_dubious_champs + dubious_champs)
end
scenario 'an admin can publish it, but a warning appears' do
visit admin_procedures_path(statut: "brouillons")
click_on procedure.libelle
find('#publish-procedure-link').click
expect(page).to have_content("Attention, certains champs ne peuvent être demandé par l'administration.")
expect(page).to have_selector(".dubious-champs", count: dubious_champs.size)
end
end
end end

View file

@ -2263,6 +2263,16 @@
escape-string-regexp "^2.0.0" escape-string-regexp "^2.0.0"
lodash.deburr "^4.1.0" lodash.deburr "^4.1.0"
"@stimulus/polyfills@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@stimulus/polyfills/-/polyfills-2.0.0.tgz#64b3e247c762330f80d88e993d1d26b24e3c13b1"
integrity sha512-XrN0AGSpBg9e7LHcOGjuyKx3a1SIcaNDqQkjMU0dy63NKsqYccjRGCvtBBE2U3NwcCQX3H22kMpeXCERUwl0ag==
dependencies:
core-js "^3.4.0"
element-closest "^2.0.2"
eventlistener-polyfill "^1.0.5"
mutation-observer-inner-html-shim "^1.0.0"
"@szmarczak/http-timer@^1.1.2": "@szmarczak/http-timer@^1.1.2":
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-1.1.2.tgz#b1665e2c461a2cd92f4c1bbf50d5454de0d4b421" resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-1.1.2.tgz#b1665e2c461a2cd92f4c1bbf50d5454de0d4b421"
@ -2830,6 +2840,11 @@
"@webassemblyjs/wast-parser" "1.9.0" "@webassemblyjs/wast-parser" "1.9.0"
"@xtuc/long" "4.2.2" "@xtuc/long" "4.2.2"
"@webcomponents/webcomponentsjs@^2.6.0":
version "2.6.0"
resolved "https://registry.yarnpkg.com/@webcomponents/webcomponentsjs/-/webcomponentsjs-2.6.0.tgz#7d1674c40bddf0c6dd974c44ffd34512fe7274ff"
integrity sha512-Moog+Smx3ORTbWwuPqoclr+uvfLnciVd6wdCaVscHPrxbmQ/IJKm3wbB7hpzJtXWjAq2l/6QMlO85aZiOdtv5Q==
"@xtuc/ieee754@^1.2.0": "@xtuc/ieee754@^1.2.0":
version "1.2.0" version "1.2.0"
resolved "https://registry.yarnpkg.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790" resolved "https://registry.yarnpkg.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790"
@ -4569,6 +4584,11 @@ core-js@^3.16.2, core-js@^3.6.5:
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.20.0.tgz#1c5ac07986b8d15473ab192e45a2e115a4a95b79" resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.20.0.tgz#1c5ac07986b8d15473ab192e45a2e115a4a95b79"
integrity sha512-KjbKU7UEfg4YPpskMtMXPhUKn7m/1OdTHTVjy09ScR2LVaoUXe8Jh0UdvN2EKUR6iKTJph52SJP95mAB0MnVLQ== integrity sha512-KjbKU7UEfg4YPpskMtMXPhUKn7m/1OdTHTVjy09ScR2LVaoUXe8Jh0UdvN2EKUR6iKTJph52SJP95mAB0MnVLQ==
core-js@^3.4.0:
version "3.22.3"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.22.3.tgz#498c41d997654cb00e81c7a54b44f0ab21ab01d5"
integrity sha512-1t+2a/d2lppW1gkLXx3pKPVGbBdxXAkqztvWb1EJ8oF8O2gIGiytzflNiFEehYwVK/t2ryUsGBoOFFvNx95mbg==
core-util-is@1.0.2: core-util-is@1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@ -5511,6 +5531,11 @@ elegant-spinner@^1.0.1:
resolved "https://registry.yarnpkg.com/elegant-spinner/-/elegant-spinner-1.0.1.tgz#db043521c95d7e303fd8f345bedc3349cfb0729e" resolved "https://registry.yarnpkg.com/elegant-spinner/-/elegant-spinner-1.0.1.tgz#db043521c95d7e303fd8f345bedc3349cfb0729e"
integrity sha1-2wQ1IcldfjA/2PNFvtwzSc+wcp4= integrity sha1-2wQ1IcldfjA/2PNFvtwzSc+wcp4=
element-closest@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/element-closest/-/element-closest-2.0.2.tgz#72a740a107453382e28df9ce5dbb5a8df0f966ec"
integrity sha1-cqdAoQdFM4LijfnOXbtajfD5Zuw=
elf-cam@^0.1.1: elf-cam@^0.1.1:
version "0.1.1" version "0.1.1"
resolved "https://registry.yarnpkg.com/elf-cam/-/elf-cam-0.1.1.tgz#46883b10835ed9e417860636a870d57490ce9eda" resolved "https://registry.yarnpkg.com/elf-cam/-/elf-cam-0.1.1.tgz#46883b10835ed9e417860636a870d57490ce9eda"
@ -5901,6 +5926,11 @@ eventemitter3@^4.0.0:
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f" resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==
eventlistener-polyfill@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/eventlistener-polyfill/-/eventlistener-polyfill-1.0.5.tgz#d3c96e57d52ca4dc30b3b8f3cf9698dc8e277d8a"
integrity sha512-xqqTj0eyJWqAMg1U+Sr20Upi86bOlbLfk/cbVnHuTEKh2S59PszLNwsc4miaUwLR7YRnCnxwSkdCZpxdo3MPwA==
events@^3.0.0: events@^3.0.0:
version "3.3.0" version "3.3.0"
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400" resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
@ -9131,6 +9161,11 @@ mustache@^2.2.1:
resolved "https://registry.yarnpkg.com/mustache/-/mustache-2.3.2.tgz#a6d4d9c3f91d13359ab889a812954f9230a3d0c5" resolved "https://registry.yarnpkg.com/mustache/-/mustache-2.3.2.tgz#a6d4d9c3f91d13359ab889a812954f9230a3d0c5"
integrity sha512-KpMNwdQsYz3O/SBS1qJ/o3sqUJ5wSb8gb0pul8CO0S56b9Y2ALm8zCfsjPXsqGFfoNBkDwZuZIAjhsZI03gYVQ== integrity sha512-KpMNwdQsYz3O/SBS1qJ/o3sqUJ5wSb8gb0pul8CO0S56b9Y2ALm8zCfsjPXsqGFfoNBkDwZuZIAjhsZI03gYVQ==
mutation-observer-inner-html-shim@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/mutation-observer-inner-html-shim/-/mutation-observer-inner-html-shim-1.0.1.tgz#84349f51dfc390d0af85011de8fa14e645fb400e"
integrity sha512-YmJPDSUWJgBhwqRJP6AMvjdfDHU1gsrT5YdgpxMit2+x1khLYhdYq9fvp4clPsYecVT3JOprBf/KjEX7IqlU+g==
mute-stream@0.0.7: mute-stream@0.0.7:
version "0.0.7" version "0.0.7"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"