From b6255ba47090af69797e6caeef0ecf3bcf395f76 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 30 May 2018 15:58:54 +0200 Subject: [PATCH 01/11] Fix cerfa to pj --- lib/tasks/2018_05_21_cerfa_to_pj.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/2018_05_21_cerfa_to_pj.rake b/lib/tasks/2018_05_21_cerfa_to_pj.rake index 2dcabd4c9..59406195a 100644 --- a/lib/tasks/2018_05_21_cerfa_to_pj.rake +++ b/lib/tasks/2018_05_21_cerfa_to_pj.rake @@ -3,9 +3,9 @@ namespace :'2018_05_21_cerfa_to_pj' do dossiers = Cerfa.includes(dossier: [:procedure]).all.reject(&:empty?).map(&:dossier).compact.uniq dossiers.group_by(&:procedure).each do |procedure, dossiers| - if !procedure.type_de_champs.find_by(libelle: 'CERFA') + if !procedure.types_de_champ.find_by(libelle: 'CERFA') procedure.administrateur.enable_feature(:champ_pj) - type_de_champ = procedure.type_de_champs.create( + type_de_champ = procedure.types_de_champ.create( type_champ: 'piece_justificative', libelle: 'CERFA' ) From d77530b6a6763d8870fe2d623d5d61b05d0fba70 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 27 Jun 2018 11:37:06 +0200 Subject: [PATCH 02/11] dossiers: move link back to the old ui --- app/views/layouts/_new_header.haml | 2 +- spec/views/layouts/_new_header_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index dad1e8d20..a5c6f5883 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -36,7 +36,7 @@ - if nav_bar_profile == :user %ul.header-tabs %li - = active_link_to "Dossiers", dossiers_path, active: :inclusive, class: 'tab-link' + = active_link_to "Dossiers", users_dossiers_path, active: :inclusive, class: 'tab-link' %ul.header-right-content - if nav_bar_profile == :gestionnaire && gestionnaire_signed_in? diff --git a/spec/views/layouts/_new_header_spec.rb b/spec/views/layouts/_new_header_spec.rb index 17ceb970b..49fd3345a 100644 --- a/spec/views/layouts/_new_header_spec.rb +++ b/spec/views/layouts/_new_header_spec.rb @@ -15,7 +15,7 @@ describe 'layouts/_new_header.html.haml', type: :view do let(:profile) { :user } it { is_expected.to have_css("a.header-logo[href=\"#{users_dossiers_path}\"]") } - it { is_expected.to have_link("Dossiers", href: dossiers_path) } + it { is_expected.to have_link("Dossiers", href: users_dossiers_path) } end context 'when rendering for gestionnaire' do From fee961ea1e2de7fd694a205e6f4dcd8b5cc53402 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 27 Jun 2018 14:20:15 +0200 Subject: [PATCH 03/11] In dev env, load xray --- app/views/layouts/new_application.html.haml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/views/layouts/new_application.html.haml b/app/views/layouts/new_application.html.haml index affb3ad19..a6a10c443 100644 --- a/app/views/layouts/new_application.html.haml +++ b/app/views/layouts/new_application.html.haml @@ -17,6 +17,9 @@ = stylesheet_link_tag "new_design/new_application", media: "all", "data-turbolinks-track": "reload" = stylesheet_link_tag "new_design/print", media: "print", "data-turbolinks-track": true + - if Rails.env.development? + = stylesheet_link_tag :xray + %body .page-wrapper = render partial: "layouts/support_navigator_banner" @@ -35,6 +38,10 @@ = render partial: "layouts/mailjet_newsletter" = javascript_include_tag "new_design/application", "data-turbolinks-eval": false + + - if Rails.env.development? + = javascript_include_tag :xray + = yield :charts_js - if Rails.env == "test" %script{ type: "text/javascript" } From 2214fc6b86688d80f38e2bcb807597ef604f754e Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 21 Jun 2018 09:48:33 +0200 Subject: [PATCH 04/11] [#1421] Extract contents of both drop down lists --- .../champs/linked_drop_down_list_champ.rb | 1 + .../linked_drop_down_list_type_de_champ.rb | 29 ++++++++++++++ ...inked_drop_down_list_type_de_champ_spec.rb | 40 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index 20fb7455a..3d1832fc5 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -1,2 +1,3 @@ class Champs::LinkedDropDownListChamp < Champ + delegate :master_options, :slave_options, to: :type_de_champ end diff --git a/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb b/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb index e54cbef7f..1d8b369d2 100644 --- a/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb +++ b/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb @@ -1,2 +1,31 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypeDeChamp + MASTER_PATTERN = /^--(.*)--$/ + + def master_options + master_options = unpack_options.map(&:first) + if master_options.present? + master_options.unshift('') + end + master_options + end + + def slave_options + slave_options = unpack_options.to_h + if slave_options.present? + slave_options[''] = [] + end + slave_options + end + + private + + def unpack_options + _, *options = drop_down_list.options + chunked = options.slice_before(MASTER_PATTERN) + chunked.map do |chunk| + master, *slave = chunk + slave.unshift('') + [MASTER_PATTERN.match(master)[1], slave] + end + end end diff --git a/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb b/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb new file mode 100644 index 000000000..7bbe5a3e5 --- /dev/null +++ b/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe TypesDeChamp::LinkedDropDownListTypeDeChamp do + describe '#unpack_options' do + let(:drop_down_list) { build(:drop_down_list, value: menu_options) } + let(:type_de_champ) { described_class.new(drop_down_list: drop_down_list) } + + context 'with no options' do + let(:menu_options) { '' } + it { expect(type_de_champ.slave_options).to eq({}) } + it { expect(type_de_champ.master_options).to eq([]) } + end + + context 'with two master options' do + let(:menu_options) do + <<~END_OPTIONS + --Master 1-- + slave 1.1 + slave 1.2 + --Master 2-- + slave 2.1 + slave 2.2 + slave 2.3 + END_OPTIONS + end + + it do + expect(type_de_champ.slave_options).to eq( + { + '' => [], + 'Master 1' => [ '', 'slave 1.1', 'slave 1.2'], + 'Master 2' => [ '', 'slave 2.1', 'slave 2.2', 'slave 2.3'] + } + ) + end + + it { expect(type_de_champ.master_options).to eq([ '', 'Master 1', 'Master 2' ]) } + end + end +end From 7b1e8c2110e049a6845c2a72925e53f74425c4d7 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 21 Jun 2018 09:50:34 +0200 Subject: [PATCH 05/11] [#1421] Extract values for both drop down lists --- .../champs/linked_drop_down_list_champ.rb | 29 +++++++++++++++++++ .../linked_drop_down_list_champ_spec.rb | 18 ++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 spec/models/champs/linked_drop_down_list_champ_spec.rb diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index 3d1832fc5..6bd1f4f9f 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -1,3 +1,32 @@ class Champs::LinkedDropDownListChamp < Champ + attr_reader :master_value, :slave_value delegate :master_options, :slave_options, to: :type_de_champ + + after_initialize :unpack_value + + def unpack_value + if value.present? + master, slave = JSON.parse(value) + else + master = slave = '' + end + @master_value ||= master + @slave_value ||= slave + end + + def master_value=(value) + @master_value = value + pack_value + end + + def slave_value=(value) + @slave_value = value + pack_value + end + + private + + def pack_value + self.value = JSON.generate([ master_value, slave_value ]) + end end diff --git a/spec/models/champs/linked_drop_down_list_champ_spec.rb b/spec/models/champs/linked_drop_down_list_champ_spec.rb new file mode 100644 index 000000000..0b9586203 --- /dev/null +++ b/spec/models/champs/linked_drop_down_list_champ_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe Champs::LinkedDropDownListChamp do + describe '#unpack_value' do + let(:champ) { described_class.new(value: '["tata", "tutu"]') } + + it { expect(champ.master_value).to eq('tata') } + it { expect(champ.slave_value).to eq('tutu') } + end + + describe '#pack_value' do + let(:champ) { described_class.new(master_value: 'tata', slave_value: 'tutu') } + + before { champ.save } + + it { expect(champ.value).to eq('["tata","tutu"]') } + end +end From 2f206af0d6c1612f603796b33e1c99864fe90ed3 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 21 Jun 2018 15:23:24 +0200 Subject: [PATCH 06/11] [#1421] Make label clickable for drop-down lists --- app/models/champ.rb | 4 ++++ app/models/champs/linked_drop_down_list_champ.rb | 4 ++++ .../shared/dossiers/editable_champs/_champ_label.html.haml | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/champ.rb b/app/models/champ.rb index f396e988c..67601b599 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -35,6 +35,10 @@ class Champ < ApplicationRecord end end + def main_value_name + :value + end + private def string_value diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index 6bd1f4f9f..aff0259f0 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -24,6 +24,10 @@ class Champs::LinkedDropDownListChamp < Champ pack_value end + def main_value_name + :master_value + end + private def pack_value diff --git a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml index 8c1070299..6ba997ae9 100644 --- a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml +++ b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml @@ -1,4 +1,4 @@ -= form.label :value do += form.label champ.main_value_name do #{champ.libelle} - if champ.mandatory? %span.mandatory * From dad3bc092b0b636cf9471cd7ebff90b39d45d917 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 21 Jun 2018 16:17:59 +0200 Subject: [PATCH 07/11] [#1421] linked dropdwon user view --- .../champs/linked_drop_down_list.js | 30 ++++++++ .../new_user/dossiers_controller.rb | 2 +- .../_linked_drop_down_list.html.haml | 10 +++ .../features/new_user/linked_dropdown_spec.rb | 76 +++++++++++++++++++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/new_design/champs/linked_drop_down_list.js create mode 100644 app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml create mode 100644 spec/features/new_user/linked_dropdown_spec.rb diff --git a/app/assets/javascripts/new_design/champs/linked_drop_down_list.js b/app/assets/javascripts/new_design/champs/linked_drop_down_list.js new file mode 100644 index 000000000..70a3628ca --- /dev/null +++ b/app/assets/javascripts/new_design/champs/linked_drop_down_list.js @@ -0,0 +1,30 @@ +document.addEventListener('turbolinks:load', function() { + var masters, i, master, slave, slaveOptions; + + masters = document.querySelectorAll('select[data-slave-options]'); + for (i = 0; i < masters.length; i++) { + master = masters[i]; + slave = document.querySelector('select[data-slave-id="' + master.dataset.masterId + '"]'); + slaveOptions = JSON.parse(master.dataset.slaveOptions); + + master.addEventListener('change', function(e) { + var option, options, element; + + while ((option = slave.firstChild)) { + slave.removeChild(option); + } + + options = slaveOptions[e.target.value]; + + for (i = 0; i < options.length; i++) { + option = options[i]; + element = document.createElement("option"); + element.textContent = option; + element.value = option; + slave.appendChild(element); + } + + slave.selectedIndex = 0; + }); + } +}); diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 905f78ebe..c90d82075 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -145,7 +145,7 @@ module NewUser def champs_params params.permit(dossier: { champs_attributes: [ - :id, :value, :piece_justificative_file, value: [], + :id, :value, :master_value, :slave_value, :piece_justificative_file, value: [], etablissement_attributes: Champs::SiretChamp::ETABLISSEMENT_ATTRIBUTES ] }) diff --git a/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml b/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml new file mode 100644 index 000000000..330465aeb --- /dev/null +++ b/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml @@ -0,0 +1,10 @@ +- if champ.drop_down_list && champ.drop_down_list.options.any? + - champ_id = champ.object_id + = form.select :master_value, + champ.master_options, + { required: champ.mandatory? }, + { data: { "slave-options" => champ.slave_options, "master-id" => champ_id } } + = form.select :slave_value, + champ.slave_options[champ.master_value], + { required: champ.mandatory? }, + { data: { "slave-id" => champ_id } } diff --git a/spec/features/new_user/linked_dropdown_spec.rb b/spec/features/new_user/linked_dropdown_spec.rb new file mode 100644 index 000000000..9a32d2423 --- /dev/null +++ b/spec/features/new_user/linked_dropdown_spec.rb @@ -0,0 +1,76 @@ +require 'spec_helper' + +feature 'linked dropdown lists' do + let(:password) { 'secret_password' } + let!(:user) { create(:user, password: password) } + + let(:list_items) do + <<~END_OF_LIST + --Master 1-- + Slave 1.1 + Slave 1.2 + --Master 2-- + Slave 2.1 + Slave 2.2 + Slave 2.3 + END_OF_LIST + end + let(:drop_down_list) { create(:drop_down_list, value: list_items) } + let(:type_de_champ) { create(:type_de_champ_linked_drop_down_list, libelle: 'linked dropdown', drop_down_list: drop_down_list) } + + let!(:procedure) do + p = create(:procedure, :published, :for_individual) + p.types_de_champ << type_de_champ + p + end + + let(:user_dossier) { user.dossiers.first } + + scenario 'change master value, slave options are updated', js: true do + log_in(user.email, password, procedure) + + fill_individual + + # Select a master value + select('Master 2', from: master_id_for('linked dropdown')) + + # Slave menu reflects chosen master value + expect(page).to have_select(slave_id_for('linked dropdown'), options: ['', 'Slave 2.1', 'Slave 2.2', 'Slave 2.3']) + + # Select another master value + select('Master 1', from: master_id_for('linked dropdown')) + + # Slave menu gets updated + expect(page).to have_select(slave_id_for('linked dropdown'), options: ['', 'Slave 1.1', 'Slave 1.2']) + end + + private + + def log_in(email, password, procedure) + visit "/commencer/#{procedure.procedure_path.path}" + expect(page).to have_current_path(new_user_session_path) + + fill_in 'user_email', with: email + fill_in 'user_password', with: password + click_on 'Se connecter' + expect(page).to have_current_path(identite_dossier_path(user_dossier)) + end + + def fill_individual + fill_in('individual_prenom', with: 'prenom') + fill_in('individual_nom', with: 'nom') + check 'dossier_autorisation_donnees' + click_on 'Continuer' + expect(page).to have_current_path(modifier_dossier_path(user_dossier)) + end + + def master_id_for(libelle) + find(:xpath, ".//label[contains(text()[normalize-space()], '#{libelle}')]")[:for] + end + + def slave_id_for(libelle) + master_id = master_id_for(libelle) + link = find("\##{master_id}")['data-master-id'] + find("[data-slave-id=\"#{link}\"]")['id'] + end +end From 0cebf60c46e7fdbf0c71ac76ea9ac1cadaa53dc4 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 27 Jun 2018 14:31:34 +0200 Subject: [PATCH 08/11] [#1421] replace master/slave by primary/secondary --- .../champs/linked_drop_down_list.js | 24 +++++------ .../new_user/dossiers_controller.rb | 2 +- .../champs/linked_drop_down_list_champ.rb | 24 +++++------ .../linked_drop_down_list_type_de_champ.rb | 30 ++++++------- .../_linked_drop_down_list.html.haml | 12 +++--- .../features/new_user/linked_dropdown_spec.rb | 42 +++++++++---------- .../linked_drop_down_list_champ_spec.rb | 6 +-- ...inked_drop_down_list_type_de_champ_spec.rb | 28 ++++++------- 8 files changed, 84 insertions(+), 84 deletions(-) diff --git a/app/assets/javascripts/new_design/champs/linked_drop_down_list.js b/app/assets/javascripts/new_design/champs/linked_drop_down_list.js index 70a3628ca..d82bf438f 100644 --- a/app/assets/javascripts/new_design/champs/linked_drop_down_list.js +++ b/app/assets/javascripts/new_design/champs/linked_drop_down_list.js @@ -1,30 +1,30 @@ document.addEventListener('turbolinks:load', function() { - var masters, i, master, slave, slaveOptions; + var primaries, i, primary, secondary, secondaryOptions; - masters = document.querySelectorAll('select[data-slave-options]'); - for (i = 0; i < masters.length; i++) { - master = masters[i]; - slave = document.querySelector('select[data-slave-id="' + master.dataset.masterId + '"]'); - slaveOptions = JSON.parse(master.dataset.slaveOptions); + primaries = document.querySelectorAll('select[data-secondary-options]'); + for (i = 0; i < primaries.length; i++) { + primary = primaries[i]; + secondary = document.querySelector('select[data-secondary-id="' + primary.dataset.primaryId + '"]'); + secondaryOptions = JSON.parse(primary.dataset.secondaryOptions); - master.addEventListener('change', function(e) { + primary.addEventListener('change', function(e) { var option, options, element; - while ((option = slave.firstChild)) { - slave.removeChild(option); + while ((option = secondary.firstChild)) { + secondary.removeChild(option); } - options = slaveOptions[e.target.value]; + options = secondaryOptions[e.target.value]; for (i = 0; i < options.length; i++) { option = options[i]; element = document.createElement("option"); element.textContent = option; element.value = option; - slave.appendChild(element); + secondary.appendChild(element); } - slave.selectedIndex = 0; + secondary.selectedIndex = 0; }); } }); diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index c90d82075..361eb3765 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -145,7 +145,7 @@ module NewUser def champs_params params.permit(dossier: { champs_attributes: [ - :id, :value, :master_value, :slave_value, :piece_justificative_file, value: [], + :id, :value, :primary_value, :secondary_value, :piece_justificative_file, value: [], etablissement_attributes: Champs::SiretChamp::ETABLISSEMENT_ATTRIBUTES ] }) diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index aff0259f0..ef02e78f4 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -1,36 +1,36 @@ class Champs::LinkedDropDownListChamp < Champ - attr_reader :master_value, :slave_value - delegate :master_options, :slave_options, to: :type_de_champ + attr_reader :primary_value, :secondary_value + delegate :primary_options, :secondary_options, to: :type_de_champ after_initialize :unpack_value def unpack_value if value.present? - master, slave = JSON.parse(value) + primary, secondary = JSON.parse(value) else - master = slave = '' + primary = secondary = '' end - @master_value ||= master - @slave_value ||= slave + @primary_value ||= primary + @secondary_value ||= secondary end - def master_value=(value) - @master_value = value + def primary_value=(value) + @primary_value = value pack_value end - def slave_value=(value) - @slave_value = value + def secondary_value=(value) + @secondary_value = value pack_value end def main_value_name - :master_value + :primary_value end private def pack_value - self.value = JSON.generate([ master_value, slave_value ]) + self.value = JSON.generate([ primary_value, secondary_value ]) end end diff --git a/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb b/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb index 1d8b369d2..6e602a97f 100644 --- a/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb +++ b/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb @@ -1,31 +1,31 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypeDeChamp - MASTER_PATTERN = /^--(.*)--$/ + PRIMARY_PATTERN = /^--(.*)--$/ - def master_options - master_options = unpack_options.map(&:first) - if master_options.present? - master_options.unshift('') + def primary_options + primary_options = unpack_options.map(&:first) + if primary_options.present? + primary_options.unshift('') end - master_options + primary_options end - def slave_options - slave_options = unpack_options.to_h - if slave_options.present? - slave_options[''] = [] + def secondary_options + secondary_options = unpack_options.to_h + if secondary_options.present? + secondary_options[''] = [] end - slave_options + secondary_options end private def unpack_options _, *options = drop_down_list.options - chunked = options.slice_before(MASTER_PATTERN) + chunked = options.slice_before(PRIMARY_PATTERN) chunked.map do |chunk| - master, *slave = chunk - slave.unshift('') - [MASTER_PATTERN.match(master)[1], slave] + primary, *secondary = chunk + secondary.unshift('') + [PRIMARY_PATTERN.match(primary)[1], secondary] end end end diff --git a/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml b/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml index 330465aeb..03afe6832 100644 --- a/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml +++ b/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml @@ -1,10 +1,10 @@ - if champ.drop_down_list && champ.drop_down_list.options.any? - champ_id = champ.object_id - = form.select :master_value, - champ.master_options, + = form.select :primary_value, + champ.primary_options, { required: champ.mandatory? }, - { data: { "slave-options" => champ.slave_options, "master-id" => champ_id } } - = form.select :slave_value, - champ.slave_options[champ.master_value], + { data: { "secondary-options" => champ.secondary_options, "primary-id" => champ_id } } + = form.select :secondary_value, + champ.secondary_options[champ.primary_value], { required: champ.mandatory? }, - { data: { "slave-id" => champ_id } } + { data: { "secondary-id" => champ_id } } diff --git a/spec/features/new_user/linked_dropdown_spec.rb b/spec/features/new_user/linked_dropdown_spec.rb index 9a32d2423..01758f0bc 100644 --- a/spec/features/new_user/linked_dropdown_spec.rb +++ b/spec/features/new_user/linked_dropdown_spec.rb @@ -6,13 +6,13 @@ feature 'linked dropdown lists' do let(:list_items) do <<~END_OF_LIST - --Master 1-- - Slave 1.1 - Slave 1.2 - --Master 2-- - Slave 2.1 - Slave 2.2 - Slave 2.3 + --Primary 1-- + Secondary 1.1 + Secondary 1.2 + --Primary 2-- + Secondary 2.1 + Secondary 2.2 + Secondary 2.3 END_OF_LIST end let(:drop_down_list) { create(:drop_down_list, value: list_items) } @@ -26,22 +26,22 @@ feature 'linked dropdown lists' do let(:user_dossier) { user.dossiers.first } - scenario 'change master value, slave options are updated', js: true do + scenario 'change primary value, secondary options are updated', js: true do log_in(user.email, password, procedure) fill_individual - # Select a master value - select('Master 2', from: master_id_for('linked dropdown')) + # Select a primary value + select('Primary 2', from: primary_id_for('linked dropdown')) - # Slave menu reflects chosen master value - expect(page).to have_select(slave_id_for('linked dropdown'), options: ['', 'Slave 2.1', 'Slave 2.2', 'Slave 2.3']) + # Secondary menu reflects chosen primary value + expect(page).to have_select(secondary_id_for('linked dropdown'), options: ['', 'Secondary 2.1', 'Secondary 2.2', 'Secondary 2.3']) - # Select another master value - select('Master 1', from: master_id_for('linked dropdown')) + # Select another primary value + select('Primary 1', from: primary_id_for('linked dropdown')) - # Slave menu gets updated - expect(page).to have_select(slave_id_for('linked dropdown'), options: ['', 'Slave 1.1', 'Slave 1.2']) + # Secondary menu gets updated + expect(page).to have_select(secondary_id_for('linked dropdown'), options: ['', 'Secondary 1.1', 'Secondary 1.2']) end private @@ -64,13 +64,13 @@ feature 'linked dropdown lists' do expect(page).to have_current_path(modifier_dossier_path(user_dossier)) end - def master_id_for(libelle) + def primary_id_for(libelle) find(:xpath, ".//label[contains(text()[normalize-space()], '#{libelle}')]")[:for] end - def slave_id_for(libelle) - master_id = master_id_for(libelle) - link = find("\##{master_id}")['data-master-id'] - find("[data-slave-id=\"#{link}\"]")['id'] + def secondary_id_for(libelle) + primary_id = primary_id_for(libelle) + link = find("\##{primary_id}")['data-primary-id'] + find("[data-secondary-id=\"#{link}\"]")['id'] end end diff --git a/spec/models/champs/linked_drop_down_list_champ_spec.rb b/spec/models/champs/linked_drop_down_list_champ_spec.rb index 0b9586203..95327e5cb 100644 --- a/spec/models/champs/linked_drop_down_list_champ_spec.rb +++ b/spec/models/champs/linked_drop_down_list_champ_spec.rb @@ -4,12 +4,12 @@ describe Champs::LinkedDropDownListChamp do describe '#unpack_value' do let(:champ) { described_class.new(value: '["tata", "tutu"]') } - it { expect(champ.master_value).to eq('tata') } - it { expect(champ.slave_value).to eq('tutu') } + it { expect(champ.primary_value).to eq('tata') } + it { expect(champ.secondary_value).to eq('tutu') } end describe '#pack_value' do - let(:champ) { described_class.new(master_value: 'tata', slave_value: 'tutu') } + let(:champ) { described_class.new(primary_value: 'tata', secondary_value: 'tutu') } before { champ.save } diff --git a/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb b/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb index 7bbe5a3e5..ab0fcf203 100644 --- a/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb +++ b/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb @@ -7,34 +7,34 @@ describe TypesDeChamp::LinkedDropDownListTypeDeChamp do context 'with no options' do let(:menu_options) { '' } - it { expect(type_de_champ.slave_options).to eq({}) } - it { expect(type_de_champ.master_options).to eq([]) } + it { expect(type_de_champ.secondary_options).to eq({}) } + it { expect(type_de_champ.primary_options).to eq([]) } end - context 'with two master options' do + context 'with two primary options' do let(:menu_options) do <<~END_OPTIONS - --Master 1-- - slave 1.1 - slave 1.2 - --Master 2-- - slave 2.1 - slave 2.2 - slave 2.3 + --Primary 1-- + secondary 1.1 + secondary 1.2 + --Primary 2-- + secondary 2.1 + secondary 2.2 + secondary 2.3 END_OPTIONS end it do - expect(type_de_champ.slave_options).to eq( + expect(type_de_champ.secondary_options).to eq( { '' => [], - 'Master 1' => [ '', 'slave 1.1', 'slave 1.2'], - 'Master 2' => [ '', 'slave 2.1', 'slave 2.2', 'slave 2.3'] + 'Primary 1' => [ '', 'secondary 1.1', 'secondary 1.2'], + 'Primary 2' => [ '', 'secondary 2.1', 'secondary 2.2', 'secondary 2.3'] } ) end - it { expect(type_de_champ.master_options).to eq([ '', 'Master 1', 'Master 2' ]) } + it { expect(type_de_champ.primary_options).to eq([ '', 'Primary 1', 'Primary 2' ]) } end end end From a429a38a38ca01bf308d9c038f3c0d9562275042 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 27 Jun 2018 12:38:38 +0200 Subject: [PATCH 09/11] Support task to delete a user account --- lib/tasks/support.rake | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/tasks/support.rake b/lib/tasks/support.rake index 2f70a7816..f4bbb82cc 100644 --- a/lib/tasks/support.rake +++ b/lib/tasks/support.rake @@ -31,4 +31,21 @@ namespace :support do pp.update(administrateur: new_owner) end end + + desc <<~EOD + Delete the user account for a given USER_MAIL. + Only works if the user has no dossier where the instruction has started. + EOD + task delete_user_account: :environment do + user_mail = ENV['USER_MAIL'] + if user_mail.nil? + fail "Must specify a USER_MAIL" + end + user = User.find_by(email: user_mail) + if user.dossiers.state_instruction_commencee.any? + fail "Cannot delete this user because instruction has started for some dossiers" + end + user.dossiers.each { |d| d.delete_and_keep_track } + user.destroy + end end From 44d9f72da4fec2ee9a332412a0bb3a7326cae7b9 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 28 Jun 2018 10:09:12 +0200 Subject: [PATCH 10/11] [Fix #2147] Link to better France Connect about page --- app/views/users/sessions/new.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/sessions/new.html.haml b/app/views/users/sessions/new.html.haml index 3412a0439..943afd7a3 100644 --- a/app/views/users/sessions/new.html.haml +++ b/app/views/users/sessions/new.html.haml @@ -50,7 +50,7 @@ = link_to "", france_connect_particulier_path, class: "login-with-fc" .center - = link_to "Qu’est-ce que FranceConnect ?", "https://franceconnect.gouv.fr/", target: "_blank", class: "link" + = link_to "Qu’est-ce que FranceConnect ?", "https://app.franceconnect.gouv.fr/en-savoir-plus", target: "_blank", class: "link" - if resource_name == :user %hr From 7fdb523b1aa11e2f3aee6adda48b59e7eb1fecc7 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Tue, 26 Jun 2018 17:27:00 +0200 Subject: [PATCH 11/11] We can use the shorter syntax fort ordered_champs(_private) now that the old preview is gone --- app/models/champ.rb | 1 + app/models/dossier.rb | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/models/champ.rb b/app/models/champ.rb index 67601b599..dc8007442 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -10,6 +10,7 @@ class Champ < ApplicationRecord scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) } scope :public_only, -> { where(private: false) } scope :private_only, -> { where(private: true) } + scope :ordered, -> { includes(:type_de_champ).order('types_de_champ.order_place') } def public? !private? diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 646aee849..c02facd83 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -104,15 +104,11 @@ class Dossier < ApplicationRecord end def ordered_champs - # TODO: use the line below when the procedure preview does not leak champ with dossier_id == 0 - # champs.joins(:type_de_champ).order('types_de_champ.order_place') - champs.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place') + champs.ordered end def ordered_champs_private - # TODO: use the line below when the procedure preview does not leak champ with dossier_id == 0 - # champs_private.includes(:type_de_champ).order('types_de_champ.order_place') - champs_private.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place') + champs_private.ordered end def ordered_pieces_justificatives