From 3c0e3f725dd128df0f8e2e07b29afddd91bf37b0 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 25 Apr 2022 14:28:52 +0200 Subject: [PATCH 1/2] feat(administrateur/procedures#publication): show dubious to administrateur Update app/views/administrateurs/procedures/publication.html.haml Co-authored-by: Paul Chavard --- app/jobs/cron/find_dubious_procedures_job.rb | 11 ++++---- app/models/type_de_champ.rb | 5 ++++ .../procedures/publication.html.haml | 6 ++++ .../administrateurs/procedure_publish_spec.rb | 28 +++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/app/jobs/cron/find_dubious_procedures_job.rb b/app/jobs/cron/find_dubious_procedures_job.rb index d2ed23561..d0137fd3a 100644 --- a/app/jobs/cron/find_dubious_procedures_job.rb +++ b/app/jobs/cron/find_dubious_procedures_job.rb @@ -9,17 +9,18 @@ class Cron::FindDubiousProceduresJob < Cron::CronJob 'médical', 'handicap', 'maladie', 'allergie', 'hospitalisé', 'RQTH', 'vaccin' ] - def perform(*args) - # \\y is a word boundary - forbidden_regexp = FORBIDDEN_KEYWORDS - .map { |keyword| "\\y#{keyword}\\y" } + # \\y is a word boundary + def self.forbidden_regexp + FORBIDDEN_KEYWORDS.map { |keyword| "\\y#{keyword}\\y" } .join('|') + end + def perform(*args) # ~* -> case insensitive regexp match # https://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP forbidden_tdcs = TypeDeChamp .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(procedures: { closed_at: nil, whitelisted_at: nil }) diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 229c56c46..139e85f3c 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -94,6 +94,11 @@ class TypeDeChamp < ApplicationRecord 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 :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 def build(params = {}) super(params.merge(proxy_association.owner.params_for_champ)) diff --git a/app/views/administrateurs/procedures/publication.html.haml b/app/views/administrateurs/procedures/publication.html.haml index 8beeff598..e88f329a0 100644 --- a/app/views/administrateurs/procedures/publication.html.haml +++ b/app/views/administrateurs/procedures/publication.html.haml @@ -4,6 +4,12 @@ link_to(@procedure.libelle, admin_procedure_path(@procedure)), 'Publication'] } .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 %h1 - if @procedure.brouillon? diff --git a/spec/system/administrateurs/procedure_publish_spec.rb b/spec/system/administrateurs/procedure_publish_spec.rb index 21e6192c2..11480f066 100644 --- a/spec/system/administrateurs/procedure_publish_spec.rb +++ b/spec/system/administrateurs/procedure_publish_spec.rb @@ -122,4 +122,32 @@ describe 'Publishing a procedure', js: true do expect(page).to have_selector('#preview-procedure') 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 From 20a78f08c9625bfaa3b89bc1013589b32ab916c8 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 28 Apr 2022 11:14:26 +0200 Subject: [PATCH 2/2] fix(js): add turbo and stimulus polyfills --- app/javascript/shared/polyfills.js | 2 ++ package.json | 2 ++ yarn.lock | 35 ++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/app/javascript/shared/polyfills.js b/app/javascript/shared/polyfills.js index bcf7ce2b4..5998b0158 100644 --- a/app/javascript/shared/polyfills.js +++ b/app/javascript/shared/polyfills.js @@ -6,6 +6,8 @@ import 'regenerator-runtime/runtime'; import 'dom4'; import 'intersection-observer'; import 'whatwg-fetch'; +import '@webcomponents/webcomponentsjs'; +import '@stimulus/polyfills'; import './polyfills/insertAdjacentElement'; import './polyfills/dataset'; diff --git a/package.json b/package.json index 43e7642ac..b017a54f0 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,9 @@ "@reach/combobox": "^0.16.5", "@reach/slider": "^0.16.0", "@sentry/browser": "6.12.0", + "@stimulus/polyfills": "^2.0.0", "@tmcw/togeojson": "^4.3.0", + "@webcomponents/webcomponentsjs": "^2.6.0", "babel-plugin-macros": "^2.8.0", "chartkick": "^4.1.1", "core-js": "^3.6.5", diff --git a/yarn.lock b/yarn.lock index f06ec9512..ba0811326 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2263,6 +2263,16 @@ escape-string-regexp "^2.0.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": version "1.1.2" 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" "@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": version "1.2.0" 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" 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: version "1.0.2" 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" 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: version "0.1.1" 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" 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: version "3.3.0" 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" 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: version "0.0.7" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"