From df7e0a98810eeff294e4c6d20c3ab8ef42b8cdc8 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 18 Dec 2018 22:48:56 +0100 Subject: [PATCH 01/21] Remove dead code --- .../stylesheets/new_design/landing.scss | 13 ----- app/decorators/champ_decorator.rb | 16 ------- app/helpers/application_helper.rb | 7 --- app/models/champs/datetime_champ.rb | 12 ----- app/models/dossier.rb | 12 ----- app/models/gestionnaire.rb | 9 ---- app/models/procedure.rb | 4 -- app/models/user.rb | 15 ------ app/services/champs_service.rb | 48 ------------------- app/services/pieces_justificatives_service.rb | 17 ------- .../users/sessions_controller_spec.rb | 4 +- spec/decorators/champ_decorator_spec.rb | 32 ------------- spec/helpers/application_helper_spec.rb | 14 ------ spec/models/dossier_spec.rb | 23 --------- spec/models/gestionnaire_spec.rb | 23 --------- spec/models/user_spec.rb | 30 ------------ spec/services/champs_service_spec.rb | 40 ---------------- 17 files changed, 2 insertions(+), 317 deletions(-) delete mode 100644 app/services/champs_service.rb delete mode 100644 spec/services/champs_service_spec.rb diff --git a/app/assets/stylesheets/new_design/landing.scss b/app/assets/stylesheets/new_design/landing.scss index 7cfaa8839..f6bec1754 100644 --- a/app/assets/stylesheets/new_design/landing.scss +++ b/app/assets/stylesheets/new_design/landing.scss @@ -439,19 +439,6 @@ $cta-panel-button-border-size: 2px; } } -.tour-de-france-banner { - padding-top: 15px; - padding-bottom: 15px; - background-color: $blue; - color: #FFFFFF; - text-align: center; - - a { - color: #FFFFFF; - text-decoration: underline; - } -} - .half { width: 45%; float: left; diff --git a/app/decorators/champ_decorator.rb b/app/decorators/champ_decorator.rb index 151eef64d..ef50412f2 100644 --- a/app/decorators/champ_decorator.rb +++ b/app/decorators/champ_decorator.rb @@ -18,20 +18,4 @@ class ChampDecorator < Draper::Decorator object.value end end - - def date_for_input - if object.value.present? - if type_champ == TypeDeChamp.type_champs.fetch(:date) - object.value - elsif type_champ == TypeDeChamp.type_champs.fetch(:datetime) && object.value != ' 00:00' - Time.zone.strptime(object.value, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d") - end - end - end - - def description_with_links - if description - description.gsub(URI.regexp, '\0') - end - end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e6d7cf6d9..873036f21 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -90,13 +90,6 @@ module ApplicationHelper end end - def ensure_safe_json(json) - json.present? ? JSON.parse(json).to_json : '[]' - rescue Exception => e - Raven.capture_exception(e) - {} - end - def sentry_config sentry = Rails.application.secrets.sentry if sentry diff --git a/app/models/champs/datetime_champ.rb b/app/models/champs/datetime_champ.rb index a38aa151f..43d59e26f 100644 --- a/app/models/champs/datetime_champ.rb +++ b/app/models/champs/datetime_champ.rb @@ -1,24 +1,12 @@ class Champs::DatetimeChamp < Champ before_save :format_before_save - def same_hour?(num) - same_date?(num, '%H') - end - - def same_minute?(num) - same_date?(num, '%M') - end - def search_terms # Text search is pretty useless for datetimes so we’re not including these champs end private - def same_date?(num, compare) - return value.present? && value.to_datetime.strftime(compare) == num - end - def format_before_save if (value =~ /=>/).present? self.value = diff --git a/app/models/dossier.rb b/app/models/dossier.rb index fd97c3c59..436c8c707 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -152,22 +152,10 @@ class Dossier < ApplicationRecord update_columns(autorisation_donnees: false) end - def total_follow - follows.size - end - def read_only? en_instruction? || accepte? || refuse? || sans_suite? end - def invite_for_user(user) - invites.find_by(user_id: user.id) - end - - def can_be_en_construction? - !(procedure.archivee? && brouillon?) - end - def can_transition_to_en_construction? !procedure.archivee? && brouillon? end diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 8008cb46b..589cc7f27 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -22,11 +22,6 @@ class Gestionnaire < ApplicationRecord procedures.merge(Procedure.avec_lien.or(Procedure.archivees)) end - def can_view_dossier?(dossier_id) - avis.where(dossier_id: dossier_id).any? || - dossiers.where(id: dossier_id).any? - end - def follow(dossier) if follow?(dossier) return @@ -43,10 +38,6 @@ class Gestionnaire < ApplicationRecord followed_dossiers.include?(dossier) end - def assigned_on_procedure?(procedure_id) - procedures.find_by(id: procedure_id).present? - end - def assign_to_procedure(procedure) begin procedures << procedure diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 225156e9b..9d5577db3 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -164,10 +164,6 @@ class Procedure < ApplicationRecord types_de_champ_private.order(:order_place) end - def all_types_de_champ - types_de_champ + types_de_champ_private - end - def self.active(id) publiees.find(id) end diff --git a/app/models/user.rb b/app/models/user.rb index 7945bf875..c676fb159 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -28,21 +28,6 @@ class User < ApplicationRecord link_invites! end - def self.find_for_france_connect(email, siret) - user = User.find_by(email: email) - - if user.nil? - User.create(email: email, password: Devise.friendly_token[0, 20], siret: siret) - else - user.update(siret: siret) - user - end - end - - def loged_in_with_france_connect? - loged_in_with_france_connect.present? - end - def owns?(dossier) dossier.user_id == id end diff --git a/app/services/champs_service.rb b/app/services/champs_service.rb deleted file mode 100644 index 888465efe..000000000 --- a/app/services/champs_service.rb +++ /dev/null @@ -1,48 +0,0 @@ -class ChampsService - class << self - def save_champs(champs, params) - fill_champs(champs, params) - - champs.select(&:changed?).each(&:save) - end - - def build_error_messages(champs) - champs.select(&:mandatory_and_blank?) - .map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." } - end - - def check_piece_justificative_files(champs) - champs.select do |champ| - champ.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) - end.map(&:piece_justificative_file_errors).flatten - end - - private - - def fill_champs(champs, h) - datetimes, not_datetimes = champs.partition { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } - - not_datetimes.each do |c| - if c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) && h["champs"]["'#{c.id}'"].present? - c.piece_justificative_file.attach(h["champs"]["'#{c.id}'"]) - else - c.value = h[:champs]["'#{c.id}'"] - end - end - - datetimes.each { |c| c.value = parse_datetime(c.id, h) } - end - - def parse_datetime(champ_id, h) - "#{h[:champs]["'#{champ_id}'"]} #{extract_hour(champ_id, h)}:#{extract_minute(champ_id, h)}" - end - - def extract_hour(champ_id, h) - h[:time_hour]["'#{champ_id}'"] - end - - def extract_minute(champ_id, h) - h[:time_minute]["'#{champ_id}'"] - end - end -end diff --git a/app/services/pieces_justificatives_service.rb b/app/services/pieces_justificatives_service.rb index 521dd5873..b9ef0f767 100644 --- a/app/services/pieces_justificatives_service.rb +++ b/app/services/pieces_justificatives_service.rb @@ -15,23 +15,6 @@ class PiecesJustificativesService .compact() end - def self.upload_one!(dossier, user, params) - content = params[:piece_justificative][:content] - if ClamavService.safe_file?(content.path) - pj = PieceJustificative.new(content: content, - dossier: dossier, - type_de_piece_justificative: nil, - user: user) - - pj.save - else - pj = PieceJustificative.new - pj.errors.add(:content, "#{content.original_filename} : Virus détecté !!") - end - - pj - end - def self.save_pj(content, dossier, tpj, user) pj = PieceJustificative.new(content: content, dossier: dossier, diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index 608791878..b6601b4b9 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -17,7 +17,7 @@ describe Users::SessionsController, type: :controller do user.reload end - subject { user.loged_in_with_france_connect? } + subject { user.loged_in_with_france_connect.present? } it { is_expected.to be_falsey } end @@ -141,7 +141,7 @@ describe Users::SessionsController, type: :controller do it 'loged_in_with_france_connect current_user attribut is nil' do user.reload - expect(user.loged_in_with_france_connect?).to be_falsey + expect(user.loged_in_with_france_connect.present?).to be_falsey end context 'when user is connect with france connect particulier' do diff --git a/spec/decorators/champ_decorator_spec.rb b/spec/decorators/champ_decorator_spec.rb index cc4a00757..9d9fde006 100644 --- a/spec/decorators/champ_decorator_spec.rb +++ b/spec/decorators/champ_decorator_spec.rb @@ -62,36 +62,4 @@ describe ChampDecorator do end end end - - describe '#date_for_input' do - subject { decorator.date_for_input } - - describe "for a date" do - let(:type_de_champ) { create(:type_de_champ_date) } - - context "when value is an ISO date" do - before { champ.update value: "2017-12-31" } - it { is_expected.to eq "2017-12-31" } - end - - context "when value is empty" do - before { champ.update value: nil } - it { is_expected.to eq nil } - end - end - - describe "for a datetime" do - let(:type_de_champ) { create(:type_de_champ_date) } - - context "when value is an formatted datetime" do - before { champ.update value: "2017-12-30 23:17" } - it { is_expected.to eq "2017-12-30" } - end - - context "when value is empty" do - before { champ.update value: nil } - it { is_expected.to eq nil } - end - end - end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 22c2f9b06..30a7becef 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -17,18 +17,4 @@ describe ApplicationHelper do it { is_expected.to be_nil } end end - - describe "#ensure_safe_json" do - subject { ensure_safe_json(json) } - - context "with a dirty json" do - let(:json) { "alert('haha');" } - it { is_expected.to eq({}) } - end - - context 'with a correct json' do - let(:json) { '[[{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}], [{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}]]' } - it { is_expected.to eq("[[{\"lat\":2.0,\"lng\":102.0},{\"lat\":3.0,\"lng\":103.0},{\"lat\":2.0,\"lng\":102.0}],[{\"lat\":2.0,\"lng\":102.0},{\"lat\":3.0,\"lng\":103.0},{\"lat\":2.0,\"lng\":102.0}]]") } - end - end end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 36b9d2e95..91732b0a5 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -235,29 +235,6 @@ describe Dossier do it { expect(dossier.champs_private.pluck(:libelle)).to match(['l1', 'l2', 'l3']) } end - describe '#total_follow' do - let(:dossier) { create(:dossier, :with_entreprise, user: user) } - let(:dossier2) { create(:dossier, :with_entreprise, user: user) } - - subject { dossier.total_follow } - - context 'when no body follow dossier' do - it { expect(subject).to eq 0 } - end - - context 'when 2 people follow dossier' do - before do - create :follow, dossier_id: dossier.id, gestionnaire_id: (create :gestionnaire).id - create :follow, dossier_id: dossier.id, gestionnaire_id: (create :gestionnaire).id - - create :follow, dossier_id: dossier2.id, gestionnaire_id: (create :gestionnaire).id - create :follow, dossier_id: dossier2.id, gestionnaire_id: (create :gestionnaire).id - end - - it { expect(subject).to eq 2 } - end - end - describe "#text_summary" do let(:procedure) { create(:procedure, libelle: "Démarche", organisation: "Organisme") } diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index e860c3231..e24b6d353 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -199,29 +199,6 @@ describe Gestionnaire, type: :model do end end - describe '#can_view_dossier?' do - subject{ gestionnaire.can_view_dossier?(dossier.id) } - - context 'when gestionnaire is assigned on dossier' do - let!(:dossier){ create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) } - - it { expect(subject).to be true } - end - - context 'when gestionnaire is invited on dossier' do - let(:dossier){ create(:dossier) } - let!(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire) } - - it { expect(subject).to be true } - end - - context 'when gestionnaire is neither assigned nor invited on dossier' do - let(:dossier){ create(:dossier) } - - it { expect(subject).to be false } - end - end - describe "procedure_presentation_and_errors_for_procedure_id" do let(:procedure_presentation_and_errors) { gestionnaire.procedure_presentation_and_errors_for_procedure_id(procedure_id) } let(:procedure_presentation) { procedure_presentation_and_errors.first } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 942283c16..9564d4623 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -20,36 +20,6 @@ describe User, type: :model do end end - describe '#find_for_france_connect' do - let(:siret) { '00000000000000' } - context 'when user exist' do - let!(:user) { create(:user) } - subject { described_class.find_for_france_connect(user.email, siret) } - it 'retrieves user' do - expect(subject).to eq(user) - end - it 'saves siret in user' do - expect(subject.siret).to eq(siret) - end - it 'does not create new user' do - expect { subject }.not_to change(User, :count) - end - end - context 'when user does not exist' do - let(:email) { 'super-m@n.com' } - subject { described_class.find_for_france_connect(email, siret) } - it 'returns user' do - expect(subject).to be_an_instance_of(User) - end - it 'creates new user' do - expect { subject }.to change(User, :count).by(1) - end - it 'saves siret' do - expect(subject.siret).to eq(siret) - end - end - end - describe '#owns?' do let(:owner) { create(:user) } let(:dossier) { create(:dossier, user: owner) } diff --git a/spec/services/champs_service_spec.rb b/spec/services/champs_service_spec.rb deleted file mode 100644 index 3d7703348..000000000 --- a/spec/services/champs_service_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'spec_helper' - -describe ChampsService do - let(:type_de_champ) { create(:type_de_champ) } - let(:type_de_champ_mandatory) { create(:type_de_champ, libelle: 'mandatory', mandatory: true) } - let(:type_de_champ_datetime) { create(:type_de_champ_datetime) } - let!(:champ) { type_de_champ.champ.create(value: 'toto') } - let!(:champ_mandatory_empty) { type_de_champ_mandatory.champ.create } - let!(:champ_datetime) { type_de_champ_datetime.champ.create } - let!(:champs) { [champ, champ_mandatory_empty, champ_datetime] } - - describe 'save_champs' do - before :each do - params_hash = { - champs: { - "'#{champ.id}'" => 'yop', - "'#{champ_datetime.id}'" => 'd' - }, - time_hour: { "'#{champ_datetime.id}'" => '12' }, - time_minute: { "'#{champ_datetime.id}'" => '24' } - } - ChampsService.save_champs(champs, params_hash) - champs.each(&:reload) - end - - it 'saves the changed champ' do - expect(champ.value).to eq('yop') - end - - it 'parses and save the date' do - expect(champ_datetime.value).to eq(nil) - end - end - - describe 'build_error_message' do - it 'adds error for the missing mandatory champ' do - expect(ChampsService.build_error_messages(champs)).to match(['Le champ mandatory doit être rempli.']) - end - end -end From 5d1c24f3d801765a476222140ad20a59d5cab1a0 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 18 Dec 2018 11:17:52 +0100 Subject: [PATCH 02/21] Add type de champ repetition models (with row) --- app/models/champ.rb | 5 ++-- app/models/champs/repetition_champ.rb | 13 ++++++++++ app/models/dossier.rb | 4 +-- app/models/type_de_champ.rb | 26 +++++++++++++++++-- .../repetition_type_de_champ.rb | 2 ++ app/services/procedure_export_service.rb | 8 +++--- app/services/types_de_champ_service.rb | 3 ++- app/views/shared/dossiers/_champs.html.haml | 2 +- .../editable_champs/_repetition.html.haml | 1 + config/features.rb | 2 ++ config/locales/models/type_de_champ/fr.yml | 1 + .../20181217125100_create_champ_groups.rb | 15 +++++++++++ db/schema.rb | 8 ++++++ spec/factories/champ.rb | 4 +++ spec/factories/type_de_champ.rb | 3 +++ spec/models/champ_spec.rb | 26 +++++++++++++++++++ spec/models/type_de_champ_shared_example.rb | 16 ++++++++++++ .../services/procedure_export_service_spec.rb | 12 ++++----- 18 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 app/models/champs/repetition_champ.rb create mode 100644 app/models/types_de_champ/repetition_type_de_champ.rb create mode 100644 app/views/shared/dossiers/editable_champs/_repetition.html.haml create mode 100644 db/migrate/20181217125100_create_champ_groups.rb diff --git a/app/models/champ.rb b/app/models/champ.rb index 1f0741e3f..7771007c6 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -10,12 +10,13 @@ class Champ < ApplicationRecord has_many :geo_areas, dependent: :destroy belongs_to :etablissement, dependent: :destroy - delegate :libelle, :type_champ, :order_place, :mandatory?, :description, :drop_down_list, to: :type_de_champ + delegate :libelle, :type_champ, :order_place, :mandatory?, :description, :drop_down_list, :exclude_from_export?, :exclude_from_view?, to: :type_de_champ 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') } + scope :ordered, -> { includes(:type_de_champ).order(:row, 'types_de_champ.order_place') } + scope :root, -> { where(parent_id: nil) } def public? !private? diff --git a/app/models/champs/repetition_champ.rb b/app/models/champs/repetition_champ.rb new file mode 100644 index 000000000..3ad10bd7f --- /dev/null +++ b/app/models/champs/repetition_champ.rb @@ -0,0 +1,13 @@ +class Champs::RepetitionChamp < Champ + has_many :champs, -> { ordered }, foreign_key: :parent_id, dependent: :destroy + + accepts_nested_attributes_for :champs, allow_destroy: true + + def rows + champs.group_by(&:row).values + end + + def search_terms + # The user cannot enter any information here so it doesn’t make much sense to search + end +end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 436c8c707..f0849579c 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -18,8 +18,8 @@ class Dossier < ApplicationRecord has_one :attestation, dependent: :destroy has_many :pieces_justificatives, dependent: :destroy - has_many :champs, -> { public_only.ordered }, dependent: :destroy - has_many :champs_private, -> { private_only.ordered }, class_name: 'Champ', dependent: :destroy + has_many :champs, -> { root.public_only.ordered }, dependent: :destroy + has_many :champs_private, -> { root.private_only.ordered }, class_name: 'Champ', dependent: :destroy has_many :commentaires, dependent: :destroy has_many :invites, dependent: :destroy has_many :follows diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 61bf18695..10b0af8bc 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -28,11 +28,15 @@ class TypeDeChamp < ApplicationRecord dossier_link: 'dossier_link', piece_justificative: 'piece_justificative', siret: 'siret', - carte: 'carte' + carte: 'carte', + repetition: 'repetition' } belongs_to :procedure + belongs_to :parent, class_name: 'TypeDeChamp' + has_many :types_de_champ, foreign_key: :parent_id, class_name: 'TypeDeChamp', dependent: :destroy + store :options, accessors: [:cadastres, :quartiers_prioritaires, :parcelles_agricoles] after_initialize :set_dynamic_type @@ -105,7 +109,25 @@ class TypeDeChamp < ApplicationRecord end def non_fillable? - type_champ.in?([TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)]) + type_champ.in?([ + TypeDeChamp.type_champs.fetch(:header_section), + TypeDeChamp.type_champs.fetch(:explication) + ]) + end + + def exclude_from_export? + type_champ.in?([ + TypeDeChamp.type_champs.fetch(:header_section), + TypeDeChamp.type_champs.fetch(:explication), + TypeDeChamp.type_champs.fetch(:repetition) + ]) + end + + def exclude_from_view? + type_champ.in?([ + TypeDeChamp.type_champs.fetch(:explication), + TypeDeChamp.type_champs.fetch(:repetition) + ]) end def public? diff --git a/app/models/types_de_champ/repetition_type_de_champ.rb b/app/models/types_de_champ/repetition_type_de_champ.rb new file mode 100644 index 000000000..5abf8efd3 --- /dev/null +++ b/app/models/types_de_champ/repetition_type_de_champ.rb @@ -0,0 +1,2 @@ +class TypesDeChamp::RepetitionTypeDeChamp < TypesDeChamp::TypeDeChampBase +end diff --git a/app/services/procedure_export_service.rb b/app/services/procedure_export_service.rb index f550ad81d..b50c6c6f2 100644 --- a/app/services/procedure_export_service.rb +++ b/app/services/procedure_export_service.rb @@ -142,10 +142,10 @@ class ProcedureExportService headers = ATTRIBUTES.map do |key| label_for_export(key.to_s) end - headers += @procedure.types_de_champ.ordered.map do |champ| + headers += @procedure.types_de_champ.ordered.reject(&:exclude_from_export?).map do |champ| label_for_export(champ.libelle) end - headers += @procedure.types_de_champ_private.ordered.map do |champ| + headers += @procedure.types_de_champ_private.ordered.reject(&:exclude_from_export?).map do |champ| label_for_export(champ.libelle) end headers += ETABLISSEMENT_ATTRIBUTES.map do |key| @@ -184,10 +184,10 @@ class ProcedureExportService end end values = normalize_values(values) - values += dossier.champs.map do |champ| + values += dossier.champs.reject(&:exclude_from_export?).map do |champ| value_for_export(champ) end - values += dossier.champs_private.map do |champ| + values += dossier.champs_private.reject(&:exclude_from_export?).map do |champ| value_for_export(champ) end values += etablissement_data(dossier.etablissement) diff --git a/app/services/types_de_champ_service.rb b/app/services/types_de_champ_service.rb index 43a28b5ed..794a13afa 100644 --- a/app/services/types_de_champ_service.rb +++ b/app/services/types_de_champ_service.rb @@ -3,7 +3,8 @@ class TypesDeChampService TOGGLES = { TypeDeChamp.type_champs.fetch(:siret) => :champ_siret?, - TypeDeChamp.type_champs.fetch(:integer_number) => :champ_integer_number? + TypeDeChamp.type_champs.fetch(:integer_number) => :champ_integer_number?, + TypeDeChamp.type_champs.fetch(:repetition) => :champ_repetition? } def options diff --git a/app/views/shared/dossiers/_champs.html.haml b/app/views/shared/dossiers/_champs.html.haml index b7feb25a9..928efe27c 100644 --- a/app/views/shared/dossiers/_champs.html.haml +++ b/app/views/shared/dossiers/_champs.html.haml @@ -1,6 +1,6 @@ %table.table.vertical.dossier-champs %tbody - - champs.reject { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:explication) }.each do |c| + - champs.reject(&:exclude_from_view?).each do |c| %tr - case c.type_champ - when TypeDeChamp.type_champs.fetch(:header_section) diff --git a/app/views/shared/dossiers/editable_champs/_repetition.html.haml b/app/views/shared/dossiers/editable_champs/_repetition.html.haml new file mode 100644 index 000000000..b9fcfa711 --- /dev/null +++ b/app/views/shared/dossiers/editable_champs/_repetition.html.haml @@ -0,0 +1 @@ +%h2.repetition-libelle= champ.libelle diff --git a/config/features.rb b/config/features.rb index 48cc54e1d..d998c2ee0 100644 --- a/config/features.rb +++ b/config/features.rb @@ -11,6 +11,8 @@ Flipflop.configure do title: "Champ SIRET" feature :champ_integer_number, title: "Champ nombre entier" + feature :champ_repetition, + title: "Bloc répétable (NE MARCHE PAS – NE PAS ACTIVER)" end feature :web_hook diff --git a/config/locales/models/type_de_champ/fr.yml b/config/locales/models/type_de_champ/fr.yml index 642e43579..a76f1ad6b 100644 --- a/config/locales/models/type_de_champ/fr.yml +++ b/config/locales/models/type_de_champ/fr.yml @@ -31,3 +31,4 @@ fr: piece_justificative: 'Pièce justificative' siret: 'SIRET' carte: 'Carte' + repetition: 'Bloc répétable' diff --git a/db/migrate/20181217125100_create_champ_groups.rb b/db/migrate/20181217125100_create_champ_groups.rb new file mode 100644 index 000000000..ac55a12e8 --- /dev/null +++ b/db/migrate/20181217125100_create_champ_groups.rb @@ -0,0 +1,15 @@ +class CreateChampGroups < ActiveRecord::Migration[5.2] + def change + add_column :types_de_champ, :parent_id, :bigint + add_index :types_de_champ, :parent_id + + add_column :champs, :parent_id, :bigint + add_index :champs, :parent_id + + add_column :champs, :row, :integer + add_index :champs, :row + + add_foreign_key :types_de_champ, :types_de_champ, column: :parent_id + add_foreign_key :champs, :champs, column: :parent_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 626f70db6..2a8ec1ccc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -153,8 +153,12 @@ ActiveRecord::Schema.define(version: 2018_12_18_204707) do t.datetime "updated_at" t.boolean "private", default: false, null: false t.integer "etablissement_id" + t.bigint "parent_id" + t.integer "row" t.index ["dossier_id"], name: "index_champs_on_dossier_id" + t.index ["parent_id"], name: "index_champs_on_parent_id" t.index ["private"], name: "index_champs_on_private" + t.index ["row"], name: "index_champs_on_row" t.index ["type_de_champ_id"], name: "index_champs_on_type_de_champ_id" end @@ -539,6 +543,8 @@ ActiveRecord::Schema.define(version: 2018_12_18_204707) do t.datetime "updated_at" t.jsonb "options" t.bigint "stable_id" + t.bigint "parent_id" + t.index ["parent_id"], name: "index_types_de_champ_on_parent_id" t.index ["private"], name: "index_types_de_champ_on_private" t.index ["stable_id"], name: "index_types_de_champ_on_stable_id" end @@ -600,6 +606,7 @@ ActiveRecord::Schema.define(version: 2018_12_18_204707) do add_foreign_key "attestation_templates", "procedures" add_foreign_key "attestations", "dossiers" add_foreign_key "avis", "gestionnaires", column: "claimant_id" + add_foreign_key "champs", "champs", column: "parent_id" add_foreign_key "closed_mails", "procedures" add_foreign_key "commentaires", "dossiers" add_foreign_key "dossier_operation_logs", "dossiers" @@ -613,5 +620,6 @@ ActiveRecord::Schema.define(version: 2018_12_18_204707) do add_foreign_key "received_mails", "procedures" add_foreign_key "refused_mails", "procedures" add_foreign_key "services", "administrateurs" + add_foreign_key "types_de_champ", "types_de_champ", column: "parent_id" add_foreign_key "without_continuation_mails", "procedures" end diff --git a/spec/factories/champ.rb b/spec/factories/champ.rb index f9c345837..20d04628d 100644 --- a/spec/factories/champ.rb +++ b/spec/factories/champ.rb @@ -165,4 +165,8 @@ FactoryBot.define do champ.etablissement.signature = champ.etablissement.sign end end + + factory :champ_repetition, class: 'Champs::RepetitionChamp' do + type_de_champ { create(:type_de_champ_repetition) } + end end diff --git a/spec/factories/type_de_champ.rb b/spec/factories/type_de_champ.rb index caf15f043..26df602b2 100644 --- a/spec/factories/type_de_champ.rb +++ b/spec/factories/type_de_champ.rb @@ -93,6 +93,9 @@ FactoryBot.define do factory :type_de_champ_carte do type_champ { TypeDeChamp.type_champs.fetch(:carte) } end + factory :type_de_champ_repetition do + type_champ { TypeDeChamp.type_champs.fetch(:repetition) } + end trait :private do private { true } diff --git a/spec/models/champ_spec.rb b/spec/models/champ_spec.rb index 9056d7d40..a47d82206 100644 --- a/spec/models/champ_spec.rb +++ b/spec/models/champ_spec.rb @@ -399,4 +399,30 @@ describe Champ do it { expect{ champ.save }.to_not change(VirusScan, :count) } end end + + describe "repetition" do + let(:champ) { create(:champ_repetition) } + let(:champ_text) { create(:champ_text, row: 0) } + let(:champ_integer_number) { create(:champ_integer_number, row: 0) } + let(:champ_text2) { create(:champ_text, row: 1) } + + it { + expect(champ.rows.size).to eq(0) + + champ.champs << champ_text2 + expect(champ.rows.size).to eq(1) + + champ.champs << champ_integer_number + row = champ.reload.rows.first + expect(row.size).to eq(1) + expect(row.first).to eq(champ_integer_number) + + champ.champs << champ_text + row = champ.reload.rows.first + expect(row.size).to eq(2) + expect(row.second).to eq(champ_text) + + expect(champ.rows.size).to eq(2) + } + end end diff --git a/spec/models/type_de_champ_shared_example.rb b/spec/models/type_de_champ_shared_example.rb index 5fbceb3bd..a1cde8dfd 100644 --- a/spec/models/type_de_champ_shared_example.rb +++ b/spec/models/type_de_champ_shared_example.rb @@ -110,4 +110,20 @@ shared_examples 'type_de_champ_spec' do end end end + + describe "repetition" do + let(:type_de_champ) { create(:type_de_champ_repetition) } + let(:type_de_champ_text) { create(:type_de_champ_text) } + let(:type_de_champ_integer_number) { create(:type_de_champ_integer_number) } + + it { + expect(type_de_champ.types_de_champ.size).to eq(0) + type_de_champ.types_de_champ << type_de_champ_integer_number + expect(type_de_champ.types_de_champ.size).to eq(1) + type_de_champ.types_de_champ << type_de_champ_text + expect(type_de_champ.types_de_champ.size).to eq(2) + expect(type_de_champ_integer_number.parent).to eq(type_de_champ) + expect(type_de_champ_text.parent).to eq(type_de_champ) + } + end end diff --git a/spec/services/procedure_export_service_spec.rb b/spec/services/procedure_export_service_spec.rb index 67e50a4b7..5dcad08be 100644 --- a/spec/services/procedure_export_service_spec.rb +++ b/spec/services/procedure_export_service_spec.rb @@ -55,8 +55,6 @@ describe ProcedureExportService do :regions, :departements, :engagement, - :header_section, - :explication, :dossier_link, :piece_justificative, :siret, @@ -123,7 +121,7 @@ describe ProcedureExportService do } let(:champs_data) { - dossier.champs.ordered.map(&:for_export) + dossier.reload.champs.reject(&:exclude_from_export?).map(&:for_export) } let(:etablissement_data) { @@ -132,8 +130,8 @@ describe ProcedureExportService do it 'should have values' do expect(data.first[0..14]).to eq(dossier_data) - expect(data.first[15..40]).to eq(champs_data) - expect(data.first[41..64]).to eq(etablissement_data) + expect(data.first[15..38]).to eq(champs_data) + expect(data.first[39..62]).to eq(etablissement_data) expect(data).to eq([ dossier_data + champs_data + etablissement_data @@ -178,8 +176,8 @@ describe ProcedureExportService do it 'should have values' do expect(data.first[0..14]).to eq(dossier_data) - expect(data.first[15..40]).to eq(champs_data) - expect(data.first[41..64]).to eq(etablissement_data) + expect(data.first[15..38]).to eq(champs_data) + expect(data.first[39..62]).to eq(etablissement_data) expect(data).to eq([ dossier_data + champs_data + etablissement_data From 36d6a43084d444ce5c66344b67845fc1f29d2249 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 19 Dec 2018 18:43:56 +0100 Subject: [PATCH 03/21] [#3196] Make TypeDeChamp#options compatible with raw JSON instead of YAML inside a JSON string. We still need to support the YAML form until the data has been migrated --- app/models/type_de_champ.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 10b0af8bc..1ae51e734 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -37,7 +37,25 @@ class TypeDeChamp < ApplicationRecord belongs_to :parent, class_name: 'TypeDeChamp' has_many :types_de_champ, foreign_key: :parent_id, class_name: 'TypeDeChamp', dependent: :destroy - store :options, accessors: [:cadastres, :quartiers_prioritaires, :parcelles_agricoles] + store_accessor :options, :cadastres, :quartiers_prioritaires, :parcelles_agricoles + + # TODO start: remove after migrating `options` column to (non YAML encoded) JSON + class MaybeYaml + def load(options) + if options.is_a?(String) + YAML.safe_load(options, [ActiveSupport::HashWithIndifferentAccess]) + else + options + end + end + + def dump(options) + options + end + end + + serialize :options, MaybeYaml.new + # TODO stop: remove after migrating `options` column to (non YAML encoded) JSON after_initialize :set_dynamic_type after_create :populate_stable_id From 2a758d0759fb4ac91a0f214ae72577537e8ff328 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 19 Dec 2018 19:19:59 +0100 Subject: [PATCH 04/21] [Fix #3196] Convert YAML to JSON --- app/models/type_de_champ.rb | 8 +++++--- ..._migrate_types_de_champ_options_to_json.rake | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 lib/tasks/deployment/20181219175043_migrate_types_de_champ_options_to_json.rake diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 1ae51e734..3c775e26c 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -39,11 +39,14 @@ class TypeDeChamp < ApplicationRecord store_accessor :options, :cadastres, :quartiers_prioritaires, :parcelles_agricoles - # TODO start: remove after migrating `options` column to (non YAML encoded) JSON + # TODO simplify after migrating `options` column to (non YAML encoded) JSON class MaybeYaml def load(options) - if options.is_a?(String) + case options + when String YAML.safe_load(options, [ActiveSupport::HashWithIndifferentAccess]) + when Hash + options.with_indifferent_access else options end @@ -55,7 +58,6 @@ class TypeDeChamp < ApplicationRecord end serialize :options, MaybeYaml.new - # TODO stop: remove after migrating `options` column to (non YAML encoded) JSON after_initialize :set_dynamic_type after_create :populate_stable_id diff --git a/lib/tasks/deployment/20181219175043_migrate_types_de_champ_options_to_json.rake b/lib/tasks/deployment/20181219175043_migrate_types_de_champ_options_to_json.rake new file mode 100644 index 000000000..c27d5d3b5 --- /dev/null +++ b/lib/tasks/deployment/20181219175043_migrate_types_de_champ_options_to_json.rake @@ -0,0 +1,17 @@ +namespace :after_party do + desc 'Deployment task: migrate_types_de_champ_options_to_json' + task migrate_types_de_champ_options_to_json: :environment do + puts "Running deploy task 'migrate_types_de_champ_options_to_json'" + + dirty_tdcs = TypeDeChamp.where.not(options: nil) + progress = ProgressReport.new(dirty_tdcs.count) + dirty_tdcs.find_each do |tdc| + tdc.options_will_change! + tdc.save + progress.inc + end + progress.finish + + AfterParty::TaskRecord.create version: '20181219175043' + end +end From f51cdd0e4833aabe23d526f6ed14b4da47b4a795 Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Thu, 20 Dec 2018 09:35:55 +0100 Subject: [PATCH 05/21] Add a partial for the emails' signature --- app/views/administration_mailer/new_admin_email.html.haml | 6 +----- app/views/administration_mailer/refuse_admin.html.haml | 6 +----- app/views/avis_mailer/avis_invitation.html.haml | 6 +----- app/views/devise_mailer/confirmation_instructions.html.haml | 6 +----- app/views/devise_mailer/email_changed.html.haml | 6 +----- app/views/devise_mailer/password_change.html.haml | 6 +----- .../devise_mailer/reset_password_instructions.html.haml | 6 +----- app/views/devise_mailer/unlock_instructions.html.haml | 6 +----- .../notify_deletion_to_administration.html.haml | 6 +----- app/views/dossier_mailer/notify_deletion_to_user.html.haml | 6 +----- app/views/dossier_mailer/notify_new_answer.html.haml | 6 +----- app/views/dossier_mailer/notify_new_draft.html.haml | 6 +----- app/views/dossier_mailer/notify_undelete_to_user.html.haml | 5 +---- app/views/dossier_mailer/notify_unhide_to_user.html.haml | 6 +----- .../dossier_mailer/notify_unmigrated_to_user.html.haml | 6 +----- app/views/gestionnaire_mailer/invite_gestionnaire.html.haml | 6 +----- app/views/gestionnaire_mailer/last_week_overview.html.haml | 2 ++ app/views/gestionnaire_mailer/send_dossier.html.haml | 6 +----- app/views/gestionnaire_mailer/send_login_token.html.haml | 6 +----- .../gestionnaire_mailer/user_to_gestionnaire.html.haml | 6 +----- app/views/invite_mailer/invite_guest.html.haml | 6 +----- app/views/invite_mailer/invite_user.html.haml | 6 +----- app/views/layouts/mailers/_signature.html.haml | 5 +++++ app/views/notification_mailer/closed_mail.html.haml | 6 +----- .../closed_mail_with_attestation.html.haml | 6 +----- app/views/notification_mailer/initiated_mail.html.haml | 6 +----- app/views/notification_mailer/received_mail.html.haml | 6 +----- app/views/notification_mailer/refused_mail.html.haml | 6 +----- .../notification_mailer/without_continuation_mail.html.haml | 6 +----- app/views/user_mailer/new_account_warning.html.haml | 5 +---- 30 files changed, 35 insertions(+), 138 deletions(-) create mode 100644 app/views/layouts/mailers/_signature.html.haml diff --git a/app/views/administration_mailer/new_admin_email.html.haml b/app/views/administration_mailer/new_admin_email.html.haml index e3203d8e0..9a775f303 100644 --- a/app/views/administration_mailer/new_admin_email.html.haml +++ b/app/views/administration_mailer/new_admin_email.html.haml @@ -14,8 +14,4 @@ Créateur : = @administration.email -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/administration_mailer/refuse_admin.html.haml b/app/views/administration_mailer/refuse_admin.html.haml index 654afd798..014875d10 100644 --- a/app/views/administration_mailer/refuse_admin.html.haml +++ b/app/views/administration_mailer/refuse_admin.html.haml @@ -14,8 +14,4 @@ = link_to("formulaire de contact", contact_url) \. -%p - Cordialement, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/avis_mailer/avis_invitation.html.haml b/app/views/avis_mailer/avis_invitation.html.haml index e339c9a88..dccc8fe4a 100644 --- a/app/views/avis_mailer/avis_invitation.html.haml +++ b/app/views/avis_mailer/avis_invitation.html.haml @@ -24,11 +24,7 @@ %p = link_to "Inscrivez-vous pour donner votre avis", avis_link -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" %hr diff --git a/app/views/devise_mailer/confirmation_instructions.html.haml b/app/views/devise_mailer/confirmation_instructions.html.haml index b3d5a08e3..9412d94b0 100644 --- a/app/views/devise_mailer/confirmation_instructions.html.haml +++ b/app/views/devise_mailer/confirmation_instructions.html.haml @@ -7,8 +7,4 @@ Pour activer votre compte sur demarches-simplifiees.fr, veuillez cliquer sur le lien suivant : = link_to(confirmation_url(@user, confirmation_token: @token), confirmation_url(@user, confirmation_token: @token)) -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/devise_mailer/email_changed.html.haml b/app/views/devise_mailer/email_changed.html.haml index cfc75241f..10b3c617d 100644 --- a/app/views/devise_mailer/email_changed.html.haml +++ b/app/views/devise_mailer/email_changed.html.haml @@ -16,8 +16,4 @@ demarches-simplifiees.fr a bien été pris en compte. Vous pouvez désormais vous connecter avec l’adresse #{@resource.email}. -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/devise_mailer/password_change.html.haml b/app/views/devise_mailer/password_change.html.haml index 6e0de4026..23ec7037d 100644 --- a/app/views/devise_mailer/password_change.html.haml +++ b/app/views/devise_mailer/password_change.html.haml @@ -7,8 +7,4 @@ La demande de changement de mot de passe pour votre compte #{@resource.email} sur demarches-simplifiees.fr a bien été prise en compte. -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/devise_mailer/reset_password_instructions.html.haml b/app/views/devise_mailer/reset_password_instructions.html.haml index 9aaf2ad9d..9338f639a 100644 --- a/app/views/devise_mailer/reset_password_instructions.html.haml +++ b/app/views/devise_mailer/reset_password_instructions.html.haml @@ -9,8 +9,4 @@ %p Si vous n'avez pas effectué une telle demande, merci d'ignorer cet email. Votre mot de passe ne sera pas changé. -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/devise_mailer/unlock_instructions.html.haml b/app/views/devise_mailer/unlock_instructions.html.haml index d0b8dba91..6258b63eb 100644 --- a/app/views/devise_mailer/unlock_instructions.html.haml +++ b/app/views/devise_mailer/unlock_instructions.html.haml @@ -13,8 +13,4 @@ %p= link_to 'Déverrouiller mon compte', unlock_url(@resource, unlock_token: @token) -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/dossier_mailer/notify_deletion_to_administration.html.haml b/app/views/dossier_mailer/notify_deletion_to_administration.html.haml index e2a5fd25f..d75326dda 100644 --- a/app/views/dossier_mailer/notify_deletion_to_administration.html.haml +++ b/app/views/dossier_mailer/notify_deletion_to_administration.html.haml @@ -7,8 +7,4 @@ (sur la démarche « #{@deleted_dossier.procedure.libelle} ») a été supprimé. -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/dossier_mailer/notify_deletion_to_user.html.haml b/app/views/dossier_mailer/notify_deletion_to_user.html.haml index d8031aca6..0ee6b76c5 100644 --- a/app/views/dossier_mailer/notify_deletion_to_user.html.haml +++ b/app/views/dossier_mailer/notify_deletion_to_user.html.haml @@ -7,8 +7,4 @@ (« #{@deleted_dossier.procedure.libelle} ») a bien été supprimé. Une trace anonyme de ce traitement sera conservée pour l’administration. -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/dossier_mailer/notify_new_answer.html.haml b/app/views/dossier_mailer/notify_new_answer.html.haml index b584460b8..a3b37438c 100644 --- a/app/views/dossier_mailer/notify_new_answer.html.haml +++ b/app/views/dossier_mailer/notify_new_answer.html.haml @@ -8,8 +8,4 @@ Pour le consulter, merci de vous rendre sur = link_to messagerie_dossier_url(@dossier), messagerie_dossier_url(@dossier), target: '_blank' -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/dossier_mailer/notify_new_draft.html.haml b/app/views/dossier_mailer/notify_new_draft.html.haml index 0ac60722c..4fa3d175c 100644 --- a/app/views/dossier_mailer/notify_new_draft.html.haml +++ b/app/views/dossier_mailer/notify_new_draft.html.haml @@ -7,8 +7,4 @@ à l'adresse suivante : = link_to dossier_url(@dossier), dossier_url(@dossier), target: '_blank' -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/dossier_mailer/notify_undelete_to_user.html.haml b/app/views/dossier_mailer/notify_undelete_to_user.html.haml index e61846dda..a3b2c58e8 100644 --- a/app/views/dossier_mailer/notify_undelete_to_user.html.haml +++ b/app/views/dossier_mailer/notify_undelete_to_user.html.haml @@ -8,8 +8,5 @@ sur la procédure « #{@dossier.procedure.libelle} » a été inaccessible pendant quelques jours. L’accès est à présent à nouveau possible. Nous vous présentons nos excuses pour toute gène occasionnée. -%p - Bonne journée, -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/dossier_mailer/notify_unhide_to_user.html.haml b/app/views/dossier_mailer/notify_unhide_to_user.html.haml index e95e976e2..b3ea4eef5 100644 --- a/app/views/dossier_mailer/notify_unhide_to_user.html.haml +++ b/app/views/dossier_mailer/notify_unhide_to_user.html.haml @@ -7,8 +7,4 @@ ayant commencé, il n'a pas pu être supprimé. Le dossier a été rétabli dans votre tableau de bord. -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/dossier_mailer/notify_unmigrated_to_user.html.haml b/app/views/dossier_mailer/notify_unmigrated_to_user.html.haml index 0bf06540c..438f68252 100644 --- a/app/views/dossier_mailer/notify_unmigrated_to_user.html.haml +++ b/app/views/dossier_mailer/notify_unmigrated_to_user.html.haml @@ -19,8 +19,4 @@ Nous avons pris des mesures pour nous assurer qu’un tel désagrément ne se reproduise pas, et vous présentons nos excuses pour la gène occasionnée. -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/gestionnaire_mailer/invite_gestionnaire.html.haml b/app/views/gestionnaire_mailer/invite_gestionnaire.html.haml index 65bcd8bfb..ef19563db 100644 --- a/app/views/gestionnaire_mailer/invite_gestionnaire.html.haml +++ b/app/views/gestionnaire_mailer/invite_gestionnaire.html.haml @@ -14,8 +14,4 @@ Par ailleurs, nous vous invitons à prendre quelques minutes pour consulter notre tutoriel à destination des nouveaux instructeurs : = link_to(INSTRUCTEUR_TUTORIAL_URL, INSTRUCTEUR_TUTORIAL_URL) -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/gestionnaire_mailer/last_week_overview.html.haml b/app/views/gestionnaire_mailer/last_week_overview.html.haml index b564beb86..6486b6807 100644 --- a/app/views/gestionnaire_mailer/last_week_overview.html.haml +++ b/app/views/gestionnaire_mailer/last_week_overview.html.haml @@ -44,3 +44,5 @@ - if index != (@overview[:procedure_overviews].count - 1) .spacer{ style: 'border-bottom: 1px solid #CCC; margin: 25px 0 30px;' } + += render partial: "layouts/mailers/signature" diff --git a/app/views/gestionnaire_mailer/send_dossier.html.haml b/app/views/gestionnaire_mailer/send_dossier.html.haml index bb428ecbd..7b43b79fc 100644 --- a/app/views/gestionnaire_mailer/send_dossier.html.haml +++ b/app/views/gestionnaire_mailer/send_dossier.html.haml @@ -5,8 +5,4 @@ = "#{@sender.email} vous a envoyé le dossier nº #{@dossier.id}, cliquez sur le lien ci-dessous pour y accéder :" = link_to(gestionnaire_dossier_url(@dossier.procedure, @dossier), gestionnaire_dossier_url(@dossier.procedure, @dossier)) -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/gestionnaire_mailer/send_login_token.html.haml b/app/views/gestionnaire_mailer/send_login_token.html.haml index c2c2374f4..df3b5f553 100644 --- a/app/views/gestionnaire_mailer/send_login_token.html.haml +++ b/app/views/gestionnaire_mailer/send_login_token.html.haml @@ -5,8 +5,4 @@ Veuillez cliquer sur le lien suivant pour vous connecter sur le site demarches-simplifiees.fr :  = link_to(sign_in_by_link_url(@gestionnaire_id, jeton: @login_token), sign_in_by_link_url(@gestionnaire_id, jeton: @login_token)) -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/gestionnaire_mailer/user_to_gestionnaire.html.haml b/app/views/gestionnaire_mailer/user_to_gestionnaire.html.haml index fdc0a3925..b2809e2e9 100644 --- a/app/views/gestionnaire_mailer/user_to_gestionnaire.html.haml +++ b/app/views/gestionnaire_mailer/user_to_gestionnaire.html.haml @@ -5,8 +5,4 @@ Vous venez d'être nommé instructeur sur demarches-simplifiees.fr. = "Votre compte (#{@email}) vous donnera désormais aussi accès à l’espace instructeur." -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/invite_mailer/invite_guest.html.haml b/app/views/invite_mailer/invite_guest.html.haml index d117639c9..6b4b4c284 100644 --- a/app/views/invite_mailer/invite_guest.html.haml +++ b/app/views/invite_mailer/invite_guest.html.haml @@ -15,8 +15,4 @@ sur = invite_url(@invite, params: { email: @invite.email }) -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/invite_mailer/invite_user.html.haml b/app/views/invite_mailer/invite_user.html.haml index 4fd1a47b2..30c05ae58 100644 --- a/app/views/invite_mailer/invite_user.html.haml +++ b/app/views/invite_mailer/invite_user.html.haml @@ -10,8 +10,4 @@ Pour le consulter, merci de suivre ce lien : = invite_url(@invite) -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/layouts/mailers/_signature.html.haml b/app/views/layouts/mailers/_signature.html.haml new file mode 100644 index 000000000..ea217a250 --- /dev/null +++ b/app/views/layouts/mailers/_signature.html.haml @@ -0,0 +1,5 @@ +%p + Bonne journée, + +%p + L'équipe demarches-simplifiees.fr diff --git a/app/views/notification_mailer/closed_mail.html.haml b/app/views/notification_mailer/closed_mail.html.haml index 33d4866d2..080b1071a 100644 --- a/app/views/notification_mailer/closed_mail.html.haml +++ b/app/views/notification_mailer/closed_mail.html.haml @@ -7,8 +7,4 @@ %p À tout moment, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/notification_mailer/closed_mail_with_attestation.html.haml b/app/views/notification_mailer/closed_mail_with_attestation.html.haml index 7d5d34495..d8b646f57 100644 --- a/app/views/notification_mailer/closed_mail_with_attestation.html.haml +++ b/app/views/notification_mailer/closed_mail_with_attestation.html.haml @@ -10,8 +10,4 @@ %p À tout moment, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/notification_mailer/initiated_mail.html.haml b/app/views/notification_mailer/initiated_mail.html.haml index f8fda2710..796695603 100644 --- a/app/views/notification_mailer/initiated_mail.html.haml +++ b/app/views/notification_mailer/initiated_mail.html.haml @@ -7,8 +7,4 @@ %p À tout moment, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/notification_mailer/received_mail.html.haml b/app/views/notification_mailer/received_mail.html.haml index d85b4d3ba..a774789c1 100644 --- a/app/views/notification_mailer/received_mail.html.haml +++ b/app/views/notification_mailer/received_mail.html.haml @@ -4,8 +4,4 @@ %p Votre administration vous confirme la bonne réception de votre dossier nº --numéro du dossier--. Celui-ci sera instruit dans le délai légal déclaré par votre interlocuteur. -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/notification_mailer/refused_mail.html.haml b/app/views/notification_mailer/refused_mail.html.haml index 9d7f90cd2..1ed19b296 100644 --- a/app/views/notification_mailer/refused_mail.html.haml +++ b/app/views/notification_mailer/refused_mail.html.haml @@ -10,8 +10,4 @@ %p Pour en savoir plus sur le motif du refus, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/notification_mailer/without_continuation_mail.html.haml b/app/views/notification_mailer/without_continuation_mail.html.haml index ea57a3e90..3033f61cc 100644 --- a/app/views/notification_mailer/without_continuation_mail.html.haml +++ b/app/views/notification_mailer/without_continuation_mail.html.haml @@ -10,8 +10,4 @@ %p Pour en savoir plus sur les raisons de ce classement sans suite, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- -%p - Bonne journée, - -%p - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" diff --git a/app/views/user_mailer/new_account_warning.html.haml b/app/views/user_mailer/new_account_warning.html.haml index 7efe59ab1..29e243c83 100644 --- a/app/views/user_mailer/new_account_warning.html.haml +++ b/app/views/user_mailer/new_account_warning.html.haml @@ -12,7 +12,4 @@ %p Si vous n'êtes pas à l'origine de cette demande, vous pouvez ignorer ce mail. -%p - Cordialement, - %br - L'équipe demarches-simplifiees.fr += render partial: "layouts/mailers/signature" From 2de328da641372eb265a6c054e65e1aa768a8f7a Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Thu, 20 Dec 2018 09:36:14 +0100 Subject: [PATCH 06/21] Unify the emails' intro sentence --- app/views/devise_mailer/confirmation_instructions.html.haml | 2 +- app/views/user_mailer/new_account_warning.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/devise_mailer/confirmation_instructions.html.haml b/app/views/devise_mailer/confirmation_instructions.html.haml index 9412d94b0..a18dda332 100644 --- a/app/views/devise_mailer/confirmation_instructions.html.haml +++ b/app/views/devise_mailer/confirmation_instructions.html.haml @@ -1,7 +1,7 @@ - content_for(:title, 'Activez votre compte') %p - Bonjour #{@user.email}, + Bonjour, %p Pour activer votre compte sur demarches-simplifiees.fr, veuillez cliquer sur le lien suivant : diff --git a/app/views/user_mailer/new_account_warning.html.haml b/app/views/user_mailer/new_account_warning.html.haml index 29e243c83..fe4abd172 100644 --- a/app/views/user_mailer/new_account_warning.html.haml +++ b/app/views/user_mailer/new_account_warning.html.haml @@ -1,6 +1,6 @@ - content_for(:title, @subject) -%h1 Bonjour +%h1 Bonjour, %p Une demande de création de compte a été réalisée sur le site demarches-simplifiees.fr pour l'email #{@user.email}. From e554cc3644834a7a83907900da9aeac3da8b4f60 Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Thu, 20 Dec 2018 10:35:52 +0100 Subject: [PATCH 07/21] Unify the emails' intro tag --- .../dossier_mailer/notify_deletion_to_administration.html.haml | 3 ++- app/views/dossier_mailer/notify_deletion_to_user.html.haml | 3 ++- app/views/user_mailer/new_account_warning.html.haml | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/views/dossier_mailer/notify_deletion_to_administration.html.haml b/app/views/dossier_mailer/notify_deletion_to_administration.html.haml index d75326dda..d53e295e5 100644 --- a/app/views/dossier_mailer/notify_deletion_to_administration.html.haml +++ b/app/views/dossier_mailer/notify_deletion_to_administration.html.haml @@ -1,6 +1,7 @@ - content_for(:title, "Suppression du dossier n° #{@deleted_dossier.dossier_id}") -%h1 Bonjour, +%p + Bonjour, %p À la demande de l'usager, le dossier n° #{@deleted_dossier.dossier_id} diff --git a/app/views/dossier_mailer/notify_deletion_to_user.html.haml b/app/views/dossier_mailer/notify_deletion_to_user.html.haml index 0ee6b76c5..293994ca1 100644 --- a/app/views/dossier_mailer/notify_deletion_to_user.html.haml +++ b/app/views/dossier_mailer/notify_deletion_to_user.html.haml @@ -1,6 +1,7 @@ - content_for(:title, "Suppression du dossier n° #{@deleted_dossier.dossier_id}") -%h1 Bonjour, +%p + Bonjour, %p Votre dossier n° #{@deleted_dossier.dossier_id} diff --git a/app/views/user_mailer/new_account_warning.html.haml b/app/views/user_mailer/new_account_warning.html.haml index fe4abd172..52cac6db7 100644 --- a/app/views/user_mailer/new_account_warning.html.haml +++ b/app/views/user_mailer/new_account_warning.html.haml @@ -1,6 +1,7 @@ - content_for(:title, @subject) -%h1 Bonjour, +%p + Bonjour, %p Une demande de création de compte a été réalisée sur le site demarches-simplifiees.fr pour l'email #{@user.email}. From b72fd330b5b760b928c6ff85cd579109283ab41b Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Thu, 20 Dec 2018 10:33:18 +0100 Subject: [PATCH 08/21] Use the layout's footer for the avis invitation email --- app/views/avis_mailer/avis_invitation.html.haml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/views/avis_mailer/avis_invitation.html.haml b/app/views/avis_mailer/avis_invitation.html.haml index dccc8fe4a..6b5195a2c 100644 --- a/app/views/avis_mailer/avis_invitation.html.haml +++ b/app/views/avis_mailer/avis_invitation.html.haml @@ -2,6 +2,13 @@ - avis_link = @avis.gestionnaire.present? ? gestionnaire_avis_url(@avis) : sign_up_gestionnaire_avis_url(@avis.id, @avis.email) +- content_for(:footer) do + Merci de ne pas répondre à cet email. Donnez votre avis + = link_to("sur notre site", avis_link) + ou + = succeed '.' do + = mail_to(@avis.claimant.email, "contactez la personne qui vous a invité") + %p Bonjour, @@ -25,12 +32,3 @@ = link_to "Inscrivez-vous pour donner votre avis", avis_link = render partial: "layouts/mailers/signature" - -%hr - -%p - Merci de ne pas répondre à cet email. Donnez votre avis - = link_to "sur notre site", avis_link - ou - = succeed '.' do - = mail_to @avis.claimant.email, "contactez la personne qui vous a invité" From af21618652c9124b3a2eaae9b227970a3b78b2d0 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 20 Dec 2018 11:57:07 +0100 Subject: [PATCH 09/21] Improve the avis invitation email footer --- app/views/avis_mailer/avis_invitation.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/avis_mailer/avis_invitation.html.haml b/app/views/avis_mailer/avis_invitation.html.haml index 6b5195a2c..bf39822b7 100644 --- a/app/views/avis_mailer/avis_invitation.html.haml +++ b/app/views/avis_mailer/avis_invitation.html.haml @@ -4,7 +4,7 @@ - content_for(:footer) do Merci de ne pas répondre à cet email. Donnez votre avis - = link_to("sur notre site", avis_link) + = link_to("sur demarches-simplifiees.fr", avis_link) ou = succeed '.' do = mail_to(@avis.claimant.email, "contactez la personne qui vous a invité") From eb9edc1cee70e7e36c4ccb936eb03d48fe7777df Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 20 Dec 2018 12:00:27 +0100 Subject: [PATCH 10/21] Order types de champ in scope --- app/models/procedure.rb | 27 +++++-------------- app/models/type_de_piece_justificative.rb | 1 + app/services/procedure_export_service.rb | 4 +-- app/services/types_de_champ_service.rb | 2 +- spec/models/procedure_spec.rb | 8 +++--- .../services/procedure_export_service_spec.rb | 5 ++-- 6 files changed, 18 insertions(+), 29 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 9d5577db3..394061fce 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -3,9 +3,9 @@ require Rails.root.join('lib', 'percentile') class Procedure < ApplicationRecord MAX_DUREE_CONSERVATION = 36 - has_many :types_de_piece_justificative, -> { order "order_place ASC" }, dependent: :destroy - has_many :types_de_champ, -> { public_only }, dependent: :destroy - has_many :types_de_champ_private, -> { private_only }, class_name: 'TypeDeChamp', dependent: :destroy + has_many :types_de_piece_justificative, -> { ordered }, dependent: :destroy + has_many :types_de_champ, -> { public_only.ordered }, dependent: :destroy + has_many :types_de_champ_private, -> { private_only.ordered }, class_name: 'TypeDeChamp', dependent: :destroy has_many :dossiers has_many :deleted_dossiers, dependent: :destroy @@ -137,13 +137,8 @@ class Procedure < ApplicationRecord # Warning: dossier after_save build_default_champs must be removed # to save a dossier created from this method def new_dossier - champs = types_de_champ - .ordered - .map { |tdc| tdc.champ.build } - - champs_private = types_de_champ_private - .ordered - .map { |tdc| tdc.champ.build } + champs = types_de_champ.map { |tdc| tdc.champ.build } + champs_private = types_de_champ_private.map { |tdc| tdc.champ.build } Dossier.new(procedure: self, champs: champs, champs_private: champs_private) end @@ -156,24 +151,16 @@ class Procedure < ApplicationRecord service&.nom || organisation end - def types_de_champ_ordered - types_de_champ.order(:order_place) - end - - def types_de_champ_private_ordered - types_de_champ_private.order(:order_place) - end - def self.active(id) publiees.find(id) end def switch_types_de_champ(index_of_first_element) - switch_list_order(types_de_champ_ordered, index_of_first_element) + switch_list_order(types_de_champ, index_of_first_element) end def switch_types_de_champ_private(index_of_first_element) - switch_list_order(types_de_champ_private_ordered, index_of_first_element) + switch_list_order(types_de_champ_private, index_of_first_element) end def switch_types_de_piece_justificative(index_of_first_element) diff --git a/app/models/type_de_piece_justificative.rb b/app/models/type_de_piece_justificative.rb index 8b675a9fd..2bd50bd8a 100644 --- a/app/models/type_de_piece_justificative.rb +++ b/app/models/type_de_piece_justificative.rb @@ -6,4 +6,5 @@ class TypeDePieceJustificative < ApplicationRecord validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :lien_demarche, format: { with: URI.regexp }, allow_blank: true, allow_nil: true + scope :ordered, -> { order(order_place: :asc) } end diff --git a/app/services/procedure_export_service.rb b/app/services/procedure_export_service.rb index b50c6c6f2..a025c4ee4 100644 --- a/app/services/procedure_export_service.rb +++ b/app/services/procedure_export_service.rb @@ -142,10 +142,10 @@ class ProcedureExportService headers = ATTRIBUTES.map do |key| label_for_export(key.to_s) end - headers += @procedure.types_de_champ.ordered.reject(&:exclude_from_export?).map do |champ| + headers += @procedure.types_de_champ.reject(&:exclude_from_export?).map do |champ| label_for_export(champ.libelle) end - headers += @procedure.types_de_champ_private.ordered.reject(&:exclude_from_export?).map do |champ| + headers += @procedure.types_de_champ_private.reject(&:exclude_from_export?).map do |champ| label_for_export(champ.libelle) end headers += ETABLISSEMENT_ATTRIBUTES.map do |key| diff --git a/app/services/types_de_champ_service.rb b/app/services/types_de_champ_service.rb index 794a13afa..afc531349 100644 --- a/app/services/types_de_champ_service.rb +++ b/app/services/types_de_champ_service.rb @@ -36,7 +36,7 @@ class TypesDeChampService end def types_de_champ - private? ? @procedure.types_de_champ_private_ordered.decorate : @procedure.types_de_champ_ordered.decorate + private? ? @procedure.types_de_champ_private.decorate : @procedure.types_de_champ.decorate end def new_type_de_champ diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 21c3dd9d1..44498c17e 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -252,11 +252,11 @@ describe Procedure do end end - describe '#types_de_champ_ordered' do + describe '#types_de_champ (ordered)' do let(:procedure) { create(:procedure) } let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 1) } let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 0) } - subject { procedure.types_de_champ_ordered } + subject { procedure.types_de_champ } it { expect(subject.first).to eq(type_de_champ_1) } it { expect(subject.last).to eq(type_de_champ_0) } end @@ -432,8 +432,8 @@ describe Procedure do end it 'should keep types_de_champ ids stable' do - expect(subject.types_de_champ_ordered.first.id).not_to eq(procedure.types_de_champ_ordered.first.id) - expect(subject.types_de_champ_ordered.first.stable_id).to eq(procedure.types_de_champ_ordered.first.id) + expect(subject.types_de_champ.first.id).not_to eq(procedure.types_de_champ.first.id) + expect(subject.types_de_champ.first.stable_id).to eq(procedure.types_de_champ.first.id) end end diff --git a/spec/services/procedure_export_service_spec.rb b/spec/services/procedure_export_service_spec.rb index 5dcad08be..ecdf1e332 100644 --- a/spec/services/procedure_export_service_spec.rb +++ b/spec/services/procedure_export_service_spec.rb @@ -11,10 +11,11 @@ describe ProcedureExportService do before do # change one tdc place to check if the header is ordered - tdc_first = procedure.types_de_champ.ordered.first - tdc_last = procedure.types_de_champ.ordered.last + tdc_first = procedure.types_de_champ.first + tdc_last = procedure.types_de_champ.last tdc_first.update(order_place: tdc_last.order_place + 1) + procedure.reload end context 'dossiers' do From 1dcc8303a6f2bae468c2ff65f8adb8b2a3b130bb Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 20 Dec 2018 15:01:04 +0100 Subject: [PATCH 11/21] Add html links in invitation mail templates --- app/views/invite_mailer/invite_guest.html.haml | 3 ++- app/views/invite_mailer/invite_user.html.haml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/invite_mailer/invite_guest.html.haml b/app/views/invite_mailer/invite_guest.html.haml index 6b4b4c284..27fe008dd 100644 --- a/app/views/invite_mailer/invite_guest.html.haml +++ b/app/views/invite_mailer/invite_guest.html.haml @@ -13,6 +13,7 @@ Afin de répondre à cette invitation, merci de vous inscrire avec l'adresse email = @invite.email sur - = invite_url(@invite, params: { email: @invite.email }) + - url_for_link = invite_url(@invite, params: { email: @invite.email }) + = link_to url_for_link, url_for_link = render partial: "layouts/mailers/signature" diff --git a/app/views/invite_mailer/invite_user.html.haml b/app/views/invite_mailer/invite_user.html.haml index 30c05ae58..4497d69f7 100644 --- a/app/views/invite_mailer/invite_user.html.haml +++ b/app/views/invite_mailer/invite_user.html.haml @@ -8,6 +8,7 @@ %p Pour le consulter, merci de suivre ce lien : - = invite_url(@invite) + - url_for_link = invite_url(@invite) + = link_to url_for_link, url_for_link = render partial: "layouts/mailers/signature" From 206f17be90cbd03df980cc426a226881db469bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chai=CC=88b=20Martinez?= Date: Thu, 20 Dec 2018 14:17:12 +0100 Subject: [PATCH 12/21] Add warning text in email field --- app/views/demandes/new.html.haml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/demandes/new.html.haml b/app/views/demandes/new.html.haml index 0d3d129fb..40de202b1 100644 --- a/app/views/demandes/new.html.haml +++ b/app/views/demandes/new.html.haml @@ -30,9 +30,13 @@ = text_field_tag :name, nil, required: true = label_tag :email do - Quelle est l'adresse email pour laquelle vous souhaitez un compte ? + Quelle est l'adresse email professionnelle pour laquelle vous souhaitez un compte ? %span.mandatory * - = email_field_tag :email, nil, required: true + %p.intro{ :style => "font-weight: normal" } + Vous utilisez un email orange, wanadoo, free, gmail etc. ? Merci de nous + %a{ href: contact_admin_path, target:'_blank' } + contacter préalablement. + = email_field_tag :email, nil, placeholder: 'jean.martin@developpement-durable.gouv.fr', required: true = label_tag :phone do Quel est votre numéro de téléphone (ligne directe) ? From 0fe473b84ec96114f43a89d26f27dec12cd4a1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chai=CC=88b=20Martinez?= Date: Thu, 20 Dec 2018 14:18:42 +0100 Subject: [PATCH 13/21] Add 2 new categories in admin contact form --- app/lib/helpscout/form_adapter.rb | 4 ++++ config/locales/fr.yml | 2 ++ 2 files changed, 6 insertions(+) diff --git a/app/lib/helpscout/form_adapter.rb b/app/lib/helpscout/form_adapter.rb index de777c026..2d56db5db 100644 --- a/app/lib/helpscout/form_adapter.rb +++ b/app/lib/helpscout/form_adapter.rb @@ -23,12 +23,16 @@ class Helpscout::FormAdapter ADMIN_TYPE_RDV = 'admin demande rdv' ADMIN_TYPE_QUESTION = 'admin question' ADMIN_TYPE_SOUCIS = 'admin soucis' + ADMIN_TYPE_PRODUIT = 'admin suggestion produit' + ADMIN_TYPE_DEMANDE_COMPTE = 'admin demande compte' ADMIN_TYPE_AUTRE = 'admin autre' ADMIN_OPTIONS = [ [I18n.t(ADMIN_TYPE_QUESTION, scope: [:supportadmin]), ADMIN_TYPE_QUESTION], [I18n.t(ADMIN_TYPE_RDV, scope: [:supportadmin]), ADMIN_TYPE_RDV], [I18n.t(ADMIN_TYPE_SOUCIS, scope: [:supportadmin]), ADMIN_TYPE_SOUCIS], + [I18n.t(ADMIN_TYPE_PRODUIT, scope: [:supportadmin]), ADMIN_TYPE_PRODUIT], + [I18n.t(ADMIN_TYPE_DEMANDE_COMPTE, scope: [:supportadmin]), ADMIN_TYPE_DEMANDE_COMPTE], [I18n.t(ADMIN_TYPE_AUTRE, scope: [:supportadmin]), ADMIN_TYPE_AUTRE] ] diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 3a3fccfa7..bcf7db077 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -65,6 +65,8 @@ fr: admin demande rdv: Demande de RDV pour une présentation à distance de demarches-simplifiees.fr admin question: J'ai une question sur demarches-simplifiees.fr admin soucis: J'ai un problème technique avec demarches-simplifiees.fr + admin suggestion produit: J'ai une proposition d'évolution + admin demande compte: Je souhaite ouvrir un compte administrateur avec un email Orange, Wanadoo, etc. admin autre: Autre sujet number: From b40c706d984acd410eaf564ff5e80cc4d0a8df46 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 19 Dec 2018 15:35:07 +0100 Subject: [PATCH 14/21] [Fix #3192] Clone service if procedure is transferred --- app/models/procedure.rb | 2 ++ app/models/service.rb | 6 ++++++ .../admin/procedures_controller_spec.rb | 9 +++++++-- spec/models/procedure_spec.rb | 19 +++++++++++++++++-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 394061fce..d1458181f 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -213,6 +213,8 @@ class Procedure < ApplicationRecord if from_library procedure.service = nil + elsif self.service.present? && (self.administrateur_id != admin.id) + procedure.service = self.service.clone_and_assign_to_administrateur(admin) end procedure diff --git a/app/models/service.rb b/app/models/service.rb index 363190aa8..5305c2989 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -25,4 +25,10 @@ class Service < ApplicationRecord validates :horaires, presence: { message: 'doivent être renseignés' }, allow_nil: false validates :adresse, presence: { message: 'doit être renseignée' }, allow_nil: false validates :administrateur, presence: { message: 'doit être renseigné' }, allow_nil: false + + def clone_and_assign_to_administrateur(administrateur) + service_cloned = self.dup + service_cloned.administrateur = administrateur + service_cloned + end end diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index fc0a1f429..6db8cde08 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -580,7 +580,7 @@ describe Admin::ProceduresController, type: :controller do end describe 'POST #transfer' do - let!(:procedure) { create :procedure, administrateur: admin } + let!(:procedure) { create :procedure, :with_service, administrateur: admin } subject { post :transfer, params: { email_admin: email_admin, procedure_id: procedure.id } } @@ -597,7 +597,12 @@ describe Admin::ProceduresController, type: :controller do let(:email_admin) { 'new_admin@admin.com' } it { expect(subject.status).to eq 200 } - it { expect { subject }.to change(Procedure, :count).by(1) } + it { expect { subject }.to change(new_admin.procedures, :count).by(1) } + + it "should create a new service" do + subject + expect(new_admin.procedures.last.service_id).not_to eq(procedure.service_id) + end end context 'when admin is know but its email was not downcased' do diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 44498c17e..f4c2df6d7 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -335,14 +335,15 @@ describe Procedure do let!(:type_de_champ_private_2) { create(:type_de_champ_drop_down_list, :private, procedure: procedure, order_place: 2) } let!(:piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) } let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) } - let(:received_mail){ create(:received_mail) } + let(:received_mail) { create(:received_mail) } let(:from_library) { false } + let(:administrateur) { procedure.administrateur } before do @logo = File.open('spec/fixtures/files/white.png') @signature = File.open('spec/fixtures/files/black.png') @attestation_template = create(:attestation_template, procedure: procedure, logo: @logo, signature: @signature) - @procedure = procedure.clone(procedure.administrateur, from_library) + @procedure = procedure.clone(administrateur, from_library) @procedure.save end @@ -389,12 +390,26 @@ describe Procedure do let(:from_library) { true } it { expect(subject.cloned_from_library).to be(true) } + + it 'should set service_id to nil' do + expect(subject.service).to eq(nil) + end end it 'should keep service_id' do expect(subject.service).to eq(service) end + context 'when the procedure is cloned to another administrateur' do + let(:administrateur) { create(:administrateur) } + + it 'should clone service' do + expect(subject.service.id).not_to eq(service.id) + expect(subject.service.administrateur_id).not_to eq(service.administrateur_id) + expect(subject.service.attributes.except("id", "administrateur_id", "created_at", "updated_at")).to eq(service.attributes.except("id", "administrateur_id", "created_at", "updated_at")) + end + end + it 'should duplicate existing mail_templates' do expect(subject.received_mail.attributes.except("id", "procedure_id", "created_at", "updated_at")).to eq procedure.received_mail.attributes.except("id", "procedure_id", "created_at", "updated_at") expect(subject.received_mail.id).not_to eq procedure.received_mail.id From 904d8d208bc4f0b64e3671e1deed2649036288a0 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 20 Dec 2018 11:13:58 +0100 Subject: [PATCH 15/21] [Fix #3192] Fix data --- ...ne_service_for_transferred_procedures.rake | 32 +++++++++++++++++++ ...ce_for_transferred_procedures.rake_spec.rb | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 lib/tasks/deployment/20181219164523_clone_service_for_transferred_procedures.rake create mode 100644 spec/lib/tasks/deployment/20181219164523_clone_service_for_transferred_procedures.rake_spec.rb diff --git a/lib/tasks/deployment/20181219164523_clone_service_for_transferred_procedures.rake b/lib/tasks/deployment/20181219164523_clone_service_for_transferred_procedures.rake new file mode 100644 index 000000000..99c7452b8 --- /dev/null +++ b/lib/tasks/deployment/20181219164523_clone_service_for_transferred_procedures.rake @@ -0,0 +1,32 @@ +namespace :after_party do + desc 'Deployment task: clone_service_for_transferred_procedures' + task clone_service_for_transferred_procedures: :environment do + puts "Running deploy task 'clone_service_for_transferred_procedures'" + + procedures = Procedure.includes(:service).where.not(service_id: nil) + procedures_to_fix_in_array = procedures.select do |p| + p.administrateur_id != p.service.administrateur_id + end + procedures_to_fix = Procedure.where(id: procedures_to_fix_in_array.map(&:id)) + + service_and_admin_list = procedures_to_fix.group(:service_id, :administrateur_id).count.keys + progress = ProgressReport.new(service_and_admin_list.count) + + service_and_admin_list.each do |service_id, administrateur_id| + cloned_service = Service.find(service_id).clone_and_assign_to_administrateur(Administrateur.find(administrateur_id)) + cloned_service.save! + + procedures_to_fix + .where(service_id: service_id, administrateur_id: administrateur_id) + .update_all(service_id: cloned_service.id) + + progress.inc + end + + progress.finish + + # Update task as completed. If you remove the line below, the task will + # run with every deploy (or every time you call after_party:run). + AfterParty::TaskRecord.create version: '20181219164523' + end # task :clone_service_for_transferred_procedures +end # namespace :after_party diff --git a/spec/lib/tasks/deployment/20181219164523_clone_service_for_transferred_procedures.rake_spec.rb b/spec/lib/tasks/deployment/20181219164523_clone_service_for_transferred_procedures.rake_spec.rb new file mode 100644 index 000000000..a3995ddc9 --- /dev/null +++ b/spec/lib/tasks/deployment/20181219164523_clone_service_for_transferred_procedures.rake_spec.rb @@ -0,0 +1,32 @@ +describe '20181219164523_clone_service_for_transferred_procedures.rake' do + let(:rake_task) { Rake::Task['after_party:clone_service_for_transferred_procedures'] } + + subject do + rake_task.invoke + end + + after do + rake_task.reenable + end + + context 'procedures from different admins share the same service' do + let(:admin1) { create(:administrateur) } + let(:admin2) { create(:administrateur) } + let(:service) { create(:service, administrateur: admin1) } + let!(:procedure1) { create(:procedure, service: service, administrateur: admin1) } + let!(:procedure2) { create(:procedure, service: service, administrateur: admin2) } + let!(:procedure3) { create(:procedure, service: service, administrateur: admin2) } + + it 'clones service for procedure2 & procedure3' do + subject + expect(procedure1.reload.service).not_to eq(procedure2.reload.service) + expect(procedure1.reload.service).not_to eq(procedure3.reload.service) + expect(procedure2.reload.service).to eq(procedure3.reload.service) + end + + it 'does nothing for procedure1' do + subject + expect(procedure1.reload.service).to eq(service) + end + end +end From d80bf601e13619fd70930b658287cd7e7ce66b73 Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Thu, 20 Dec 2018 09:50:10 +0100 Subject: [PATCH 16/21] [#325] Add support for a footer in layout.html.erb --- app/views/layouts/mailers/layout.html.erb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/views/layouts/mailers/layout.html.erb b/app/views/layouts/mailers/layout.html.erb index 7f387ece8..61f42cf22 100644 --- a/app/views/layouts/mailers/layout.html.erb +++ b/app/views/layouts/mailers/layout.html.erb @@ -116,6 +116,18 @@ + <% if content_for?(:footer) %> + + +

+ — +

+

+ <%= yield(:footer) %> +

+ + + <% end %> From a1a11adb83171c1715bf33682efd79d7b9db0597 Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Thu, 20 Dec 2018 09:49:14 +0100 Subject: [PATCH 17/21] [#325] Make the notification layout inherit from the general layout --- app/views/layouts/mailers/notification.html.haml | 15 ++++++--------- spec/mailers/notification_mailer_spec.rb | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/views/layouts/mailers/notification.html.haml b/app/views/layouts/mailers/notification.html.haml index 65200ed40..b2fb59b7c 100644 --- a/app/views/layouts/mailers/notification.html.haml +++ b/app/views/layouts/mailers/notification.html.haml @@ -1,10 +1,7 @@ -= yield +- content_for :footer do + %strong + Merci de ne pas répondre à cet email. Pour vous adresser à votre administration, passez directement par votre + = succeed '.' do + = link_to 'messagerie', messagerie_dossier_url(@dossier), target: '_blank' -%footer - %p - — - %br - %strong - Merci de ne pas répondre à cet email. Pour vous adresser à votre administration, passez directement par votre - = succeed '.' do - = link_to 'messagerie', messagerie_dossier_url(@dossier), target: '_blank' += render template: 'layouts/mailers/layout' diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index 1be85a653..89a1c9333 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -34,7 +34,7 @@ RSpec.describe NotificationMailer, type: :mailer do it { expect(mail.subject).to eq(email_template.subject_for_dossier) } it { expect(mail.body).to include(email_template.body_for_dossier) } - it { expect(mail.body).to have_selector('footer') } + it { expect(mail.body).to have_link('messagerie') } it_behaves_like "create a commentaire not notified" end @@ -50,7 +50,7 @@ RSpec.describe NotificationMailer, type: :mailer do it do expect(mail.subject).to eq(email_template.subject) expect(mail.body).to include(email_template.body) - expect(mail.body).to have_selector('footer') + expect(mail.body).to have_link('messagerie') end it_behaves_like "create a commentaire not notified" From e4883aa1527a7144348be4d8176d4e2d3f72c5ec Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Thu, 20 Dec 2018 09:49:41 +0100 Subject: [PATCH 18/21] =?UTF-8?q?[Fix=20#325]=20Set=20InviteMailer?= =?UTF-8?q?=E2=80=99s=20layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/mailers/invite_mailer.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/mailers/invite_mailer.rb b/app/mailers/invite_mailer.rb index 7d0be51e6..826a18100 100644 --- a/app/mailers/invite_mailer.rb +++ b/app/mailers/invite_mailer.rb @@ -1,5 +1,7 @@ # Preview all emails at http://localhost:3000/rails/mailers/invite_mailer class InviteMailer < ApplicationMailer + layout 'mailers/layout' + def invite_user(invite) subject = "Participez à l'élaboration d'un dossier" From 9842142a9a7a8ca9c0cc96304a56c32fc58eb448 Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Thu, 20 Dec 2018 09:50:20 +0100 Subject: [PATCH 19/21] Add InviteMailerPreview --- .../mailers/previews/invite_mailer_preview.rb | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 spec/mailers/previews/invite_mailer_preview.rb diff --git a/spec/mailers/previews/invite_mailer_preview.rb b/spec/mailers/previews/invite_mailer_preview.rb new file mode 100644 index 000000000..f594f2ae8 --- /dev/null +++ b/spec/mailers/previews/invite_mailer_preview.rb @@ -0,0 +1,33 @@ +class InviteMailerPreview < ActionMailer::Preview + def invite_user + InviteMailer.invite_user(invite) + end + + def invite_guest + InviteMailer.invite_guest(invite) + end + + private + + def invite + Invite.new( + id: 10, + dossier: dossier, + user: invited_user, + email: invited_user.email, + email_sender: 'sender@gouv.fr' + ) + end + + def dossier + Dossier.new(procedure: procedure) + end + + def procedure + Procedure.new(libelle: 'Permis de construire en zone inondable') + end + + def invited_user + User.new(email: 'Invité@gouv.fr') + end +end From e37372d261d4da095c4470526c877a8be1d34cd4 Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Thu, 20 Dec 2018 09:40:05 +0100 Subject: [PATCH 20/21] Fix a typo --- spec/mailers/notification_mailer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index 89a1c9333..1d6702ffb 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -23,7 +23,7 @@ RSpec.describe NotificationMailer, type: :mailer do # We’re testing the (private) method `NotificationMailer#send_notification`. # # The standard trick to test a private method would be to `send(:send_notification)`, but doesn’t work here, - # because ActionMailer does some magic to expose public instace methods as class methods. + # because ActionMailer does some magic to expose public instance methods as class methods. # So, we use inheritance instead to make the private method public for testing purposes. def send_notification(dossier, template) super From 908b1b71aa3b7ba361676788940ae0415baa102f Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 20 Dec 2018 16:24:26 +0100 Subject: [PATCH 21/21] Task should not fail if service already exists --- ...23_clone_service_for_transferred_procedures.rake | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/tasks/deployment/20181219164523_clone_service_for_transferred_procedures.rake b/lib/tasks/deployment/20181219164523_clone_service_for_transferred_procedures.rake index 99c7452b8..85ebda24e 100644 --- a/lib/tasks/deployment/20181219164523_clone_service_for_transferred_procedures.rake +++ b/lib/tasks/deployment/20181219164523_clone_service_for_transferred_procedures.rake @@ -14,12 +14,15 @@ namespace :after_party do service_and_admin_list.each do |service_id, administrateur_id| cloned_service = Service.find(service_id).clone_and_assign_to_administrateur(Administrateur.find(administrateur_id)) - cloned_service.save! - - procedures_to_fix - .where(service_id: service_id, administrateur_id: administrateur_id) - .update_all(service_id: cloned_service.id) + if cloned_service.save + puts "Fixing Service #{service_id} for Administrateur #{administrateur_id}" + procedures_to_fix + .where(service_id: service_id, administrateur_id: administrateur_id) + .update_all(service_id: cloned_service.id) + else + puts "Cannot fix Service #{service_id} for Administrateur #{administrateur_id}, it should be fixed manually. Errors : #{cloned_service.errors.full_messages}" + end progress.inc end