From fee3ef8f4fb973154c74d1f1c7e4fc97a007d673 Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Wed, 6 Mar 2019 13:51:11 -1000 Subject: [PATCH 01/22] A4 output and allows large logos (headers) to take the whole width of the page --- .../attestation_templates/show.pdf.prawn | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/app/views/admin/attestation_templates/show.pdf.prawn b/app/views/admin/attestation_templates/show.pdf.prawn index 239ce7d00..f7a12cdbd 100644 --- a/app/views/admin/attestation_templates/show.pdf.prawn +++ b/app/views/admin/attestation_templates/show.pdf.prawn @@ -1,17 +1,36 @@ require 'prawn/measurement_extensions' -prawn_document(margin: [50, 100, 20, 100]) do |pdf| +#----- A4 page size +page_size = 'A4' +page_height = 842 +page_width = 595 + +#----- margins +body_width = 400 +top_margin = 50 +bottom_margin = 20 +footer_height = top_margin - bottom_margin + +right_margin = (page_width - body_width)/2 +left_margin = right_margin + +#----- size of images +max_logo_width = body_width +max_logo_height = 50.mm +max_signature_size = 50.mm + +prawn_document(margin: [top_margin, right_margin, bottom_margin, left_margin], page_size: page_size) do |pdf| pdf.font_families.update( 'liberation serif' => { normal: Rails.root.join('lib/prawn/fonts/liberation_serif/LiberationSerif-Regular.ttf' )}) pdf.font 'liberation serif' grey = '555555' black = '333333' - max_logo_size = 40.mm - max_signature_size = 40.mm - pdf.bounding_box([0, pdf.cursor], width: 400, height: 650) do + body_height = pdf.cursor - footer_height + + pdf.bounding_box([0, pdf.cursor], width: body_width, height: body_height) do if @logo.present? - pdf.image StringIO.new(@logo.read), fit: [max_logo_size , max_logo_size], position: :center + pdf.image StringIO.new(@logo.read), fit: [max_logo_width , max_logo_height], position: :center end pdf.fill_color grey @@ -31,7 +50,7 @@ prawn_document(margin: [50, 100, 20, 100]) do |pdf| end pdf.repeat(:all) do - pdf.move_cursor_to 20 + pdf.move_cursor_to footer_height - 10 pdf.fill_color grey pdf.text @footer, align: :center, size: 8 end From 4d73275bab30abe4ccd4aa9727525040dfcff61a Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Thu, 4 Jul 2019 16:52:03 +0200 Subject: [PATCH 02/22] Drop Procedure.administrateur_id --- app/models/procedure.rb | 2 -- db/migrate/20190704144304_drop_administrateur_id.rb | 5 +++++ db/schema.rb | 3 +-- 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20190704144304_drop_administrateur_id.rb diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 3372c32ec..dcddab930 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -1,8 +1,6 @@ require Rails.root.join('lib', 'percentile') class Procedure < ApplicationRecord - self.ignored_columns = [:administrateur_id] - MAX_DUREE_CONSERVATION = 36 has_many :types_de_piece_justificative, -> { ordered }, inverse_of: :procedure, dependent: :destroy diff --git a/db/migrate/20190704144304_drop_administrateur_id.rb b/db/migrate/20190704144304_drop_administrateur_id.rb new file mode 100644 index 000000000..abdb668c7 --- /dev/null +++ b/db/migrate/20190704144304_drop_administrateur_id.rb @@ -0,0 +1,5 @@ +class DropAdministrateurId < ActiveRecord::Migration[5.2] + def change + remove_reference :procedures, :administrateur + end +end diff --git a/db/schema.rb b/db/schema.rb index 703ebbd8e..ff7152c3a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_06_27_132911) do +ActiveRecord::Schema.define(version: 2019_07_04_144304) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -474,7 +474,6 @@ ActiveRecord::Schema.define(version: 2019_06_27_132911) do t.string "lien_demarche" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.integer "administrateur_id" t.boolean "euro_flag", default: false t.string "logo" t.boolean "cerfa_flag", default: false From 0fdae2456b22f7214f363e0856cca66c24c4c225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chai=CC=88b=20Martinez?= Date: Mon, 8 Jul 2019 14:20:49 +0200 Subject: [PATCH 03/22] We will not quibble MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chaïb Martinez --- app/services/administrateur_usage_statistics_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/administrateur_usage_statistics_service.rb b/app/services/administrateur_usage_statistics_service.rb index 5cefeaf68..6c98d954a 100644 --- a/app/services/administrateur_usage_statistics_service.rb +++ b/app/services/administrateur_usage_statistics_service.rb @@ -59,8 +59,8 @@ class AdministrateurUsageStatisticsService .max || 0, nb_dossiers_traite: nb_dossiers_by_synthetic_state['termine'], nb_dossiers_dossier_en_instruction: nb_dossiers_by_synthetic_state['en_instruction'], - admin_roi_low: nb_dossiers_roi * 7.04, - admin_roi_high: nb_dossiers_roi * 17.25 + admin_roi_low: nb_dossiers_roi * 7, + admin_roi_high: nb_dossiers_roi * 17 } if administrateur.current_sign_in_at.present? From 94d340d25c903359f17d6bdef17b093eaeae23b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chai=CC=88b=20Martinez?= Date: Mon, 8 Jul 2019 14:32:55 +0200 Subject: [PATCH 04/22] Remove phone number Add chat link MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chaïb Martinez --- app/views/layouts/_navbar.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_navbar.html.haml b/app/views/layouts/_navbar.html.haml index 2fe826508..6d4fa787f 100644 --- a/app/views/layouts/_navbar.html.haml +++ b/app/views/layouts/_navbar.html.haml @@ -10,7 +10,7 @@ #navbar-body .row %div{ style: "vertical-align: middle;float:left;position:absolute;line-height: 60px;z-index:2;" } - Besoin d'aide? #{CONTACT_PHONE} ou email ou prenez rendez-vous avec nous + 👉 Besoin d'aide? Contactez-nous par chat, email ou prenez rendez-vous avec nous. -# BEST WTF EVER -# this begin rescue hides potentials bugs by displaying another navbar - begin From c43b0c00db38326a2a435dba6f452039806ed053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chai=CC=88b=20Martinez?= Date: Mon, 8 Jul 2019 14:46:47 +0200 Subject: [PATCH 05/22] minor text change [fix #4050] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chaïb Martinez --- app/views/manager/demandes/index.html.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/manager/demandes/index.html.erb b/app/views/manager/demandes/index.html.erb index 173185b86..6d4fb534a 100644 --- a/app/views/manager/demandes/index.html.erb +++ b/app/views/manager/demandes/index.html.erb @@ -7,7 +7,9 @@ <%= content_for(:title) %> - +

+Plus de 1000 dossiers et "le plus vite possible" 👉 c'est un VIP ❤️. Appelez-le 📞 pour répondre à ses questions. +

<% if @pending_demandes.present? %>
From 39a2eb77e8e68b759c101370a91ae834545e5bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chai=CC=88b=20Martinez?= Date: Mon, 8 Jul 2019 14:58:32 +0200 Subject: [PATCH 06/22] test fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chaïb Martinez --- .../administrateur_usage_statistics_service_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/services/administrateur_usage_statistics_service_spec.rb b/spec/services/administrateur_usage_statistics_service_spec.rb index a582c1281..be9b4ce2a 100644 --- a/spec/services/administrateur_usage_statistics_service_spec.rb +++ b/spec/services/administrateur_usage_statistics_service_spec.rb @@ -113,8 +113,8 @@ describe AdministrateurUsageStatisticsService do nb_dossiers_max: 21, nb_dossiers_traite: 7, nb_dossiers_dossier_en_instruction: 7, - admin_roi_low: 147.84, - admin_roi_high: 362.25 + admin_roi_low: 147, + admin_roi_high: 357 ) end end @@ -192,8 +192,8 @@ describe AdministrateurUsageStatisticsService do nb_dossiers_max: 3, nb_dossiers_traite: 1, nb_dossiers_dossier_en_instruction: 1, - admin_roi_low: 21.12, - admin_roi_high: 51.75 + admin_roi_low: 21, + admin_roi_high: 51 ) end end @@ -222,8 +222,8 @@ describe AdministrateurUsageStatisticsService do nb_dossiers_max: 21, nb_dossiers_traite: 7, nb_dossiers_dossier_en_instruction: 7, - admin_roi_low: 147.84, - admin_roi_high: 362.25 + admin_roi_low: 147, + admin_roi_high: 357 ) end end From 12008728d2c9473894d17f2d265b199349e36c63 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Mon, 1 Jul 2019 18:14:02 +0200 Subject: [PATCH 07/22] Actually respect dossier.messagerie_available? in _messagerie.html.haml instead of dossier.archived? (fixup after #3979) --- app/views/shared/dossiers/_messagerie.html.haml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/shared/dossiers/_messagerie.html.haml b/app/views/shared/dossiers/_messagerie.html.haml index c50c17eaa..de7c34713 100644 --- a/app/views/shared/dossiers/_messagerie.html.haml +++ b/app/views/shared/dossiers/_messagerie.html.haml @@ -4,7 +4,7 @@ %li.message{ class: commentaire_is_from_me_class(commentaire, connected_user) } = render partial: "shared/dossiers/messages/message", locals: { commentaire: commentaire, connected_user: connected_user, messagerie_seen_at: messagerie_seen_at } - - if dossier.archived? - = render partial: "shared/dossiers/messages/messagerie_disabled", locals: { service: dossier.procedure.service } - - else + - if dossier.messagerie_available? = render partial: "shared/dossiers/messages/form", locals: { commentaire: new_commentaire, form_url: form_url } + - else + = render partial: "shared/dossiers/messages/messagerie_disabled", locals: { service: dossier.procedure.service } From 72fd5d250f7a8af6820fe4906a82139797c6fd6d Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Mon, 1 Jul 2019 18:14:02 +0200 Subject: [PATCH 08/22] Respect dossier.messagerie_available? in SupportController (/contact) --- app/controllers/support_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/support_controller.rb b/app/controllers/support_controller.rb index b907e20a5..47423cddd 100644 --- a/app/controllers/support_controller.rb +++ b/app/controllers/support_controller.rb @@ -82,7 +82,7 @@ class SupportController < ApplicationController end def direct_message? - user_signed_in? && params[:type] == Helpscout::FormAdapter::TYPE_INSTRUCTION && dossier.present? && !dossier.brouillon? + user_signed_in? && params[:type] == Helpscout::FormAdapter::TYPE_INSTRUCTION && dossier.present? && dossier.messagerie_available? end def dossier From 7e982138298144f36cc56d1c29fe3e954bebcc5e Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Mon, 1 Jul 2019 18:14:02 +0200 Subject: [PATCH 09/22] Pass the signed-in user as the commentaire author from /contact --- app/controllers/support_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/support_controller.rb b/app/controllers/support_controller.rb index 47423cddd..307407a79 100644 --- a/app/controllers/support_controller.rb +++ b/app/controllers/support_controller.rb @@ -64,7 +64,7 @@ class SupportController < ApplicationController file: params[:file], body: "[#{params[:subject]}]

#{params[:text]}" } - commentaire = CommentaireService.build_with_email(email, dossier, attributes) + commentaire = CommentaireService.build(current_user, dossier, attributes) commentaire.save! end From 3bf19de1248fca04c15be36bb3319fc4ea8e8797 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Mon, 1 Jul 2019 18:14:02 +0200 Subject: [PATCH 10/22] Remove Commentaire::columns override It was used for a cleanup migration a long time ago (see #233, #3033, #3043) --- app/models/commentaire.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 866593071..56bbd2abc 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -14,10 +14,6 @@ class Commentaire < ApplicationRecord after_create :notify - def self.columns - super.reject { |c| c.name == "champ" } - end - def email if user user.email From 2abd93d360010cd6145ed99074f4774168238c32 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Mon, 1 Jul 2019 18:14:02 +0200 Subject: [PATCH 11/22] Display the full `User` email in Commentaires MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Only redact gestionnaires’ emails * Also, rename Commentaire.sender to Commentaire.redacted_email --- app/models/commentaire.rb | 10 ++++++---- .../messages/_message_issuer.html.haml | 2 +- spec/models/commentaire_spec.rb | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 56bbd2abc..72ed5f388 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -25,12 +25,14 @@ class Commentaire < ApplicationRecord end def header - "#{sender}, #{I18n.l(created_at, format: '%d %b %Y %H:%M')}" + "#{redacted_email}, #{I18n.l(created_at, format: '%d %b %Y %H:%M')}" end - def sender - if email.present? - email.split('@').first + def redacted_email + if gestionnaire.present? + gestionnaire.email.split('@').first + else + email end end diff --git a/app/views/shared/dossiers/messages/_message_issuer.html.haml b/app/views/shared/dossiers/messages/_message_issuer.html.haml index 23cb7dbfc..9cd754130 100644 --- a/app/views/shared/dossiers/messages/_message_issuer.html.haml +++ b/app/views/shared/dossiers/messages/_message_issuer.html.haml @@ -5,4 +5,4 @@ - when CONTACT_EMAIL Email automatique - else - = commentaire.sender + = commentaire.redacted_email diff --git a/spec/models/commentaire_spec.rb b/spec/models/commentaire_spec.rb index 9822f15db..00807d503 100644 --- a/spec/models/commentaire_spec.rb +++ b/spec/models/commentaire_spec.rb @@ -7,6 +7,24 @@ describe Commentaire do it { is_expected.to have_db_column(:updated_at) } it { is_expected.to belong_to(:dossier) } + describe "#redacted_email" do + subject { commentaire.redacted_email } + + context 'with a commentaire created by a gestionnaire' do + let(:commentaire) { build :commentaire, gestionnaire: gestionnaire } + let(:gestionnaire) { build :gestionnaire, email: 'some_user@exemple.fr' } + + it { is_expected.to eq 'some_user' } + end + + context 'with a commentaire created by a user' do + let(:commentaire) { build :commentaire, user: user } + let(:user) { build :user, email: 'some_user@exemple.fr' } + + it { is_expected.to eq 'some_user@exemple.fr' } + end + end + describe "#notify" do let(:procedure) { create(:procedure) } let(:gestionnaire) { create(:gestionnaire) } From 3f439ac07add450b99f4f5f856baf8de0be5631a Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Mon, 1 Jul 2019 18:14:02 +0200 Subject: [PATCH 12/22] Add Commentaire.is_sent_by_system? and .is_sent_by(someone) And use it in CommentaireHelper and in the _message_icon and _message_issuer partials --- app/helpers/commentaire_helper.rb | 10 ++-------- app/models/commentaire.rb | 9 +++++++++ .../shared/dossiers/messages/_message_icon.html.haml | 9 ++++----- .../dossiers/messages/_message_issuer.html.haml | 8 +++----- spec/models/commentaire_spec.rb | 12 ++++++++++++ 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/app/helpers/commentaire_helper.rb b/app/helpers/commentaire_helper.rb index 684ff2356..a92b48b3c 100644 --- a/app/helpers/commentaire_helper.rb +++ b/app/helpers/commentaire_helper.rb @@ -1,12 +1,12 @@ module CommentaireHelper def commentaire_is_from_me_class(commentaire, connected_user) - if commentaire_is_from_me(commentaire, connected_user) + if commentaire.sent_by?(connected_user) "from-me" end end def commentaire_answer_action(commentaire, connected_user) - if commentaire_is_from_me(commentaire, connected_user) + if commentaire.sent_by?(connected_user) "Envoyer un message à l’instructeur" else "Répondre dans la messagerie" @@ -22,10 +22,4 @@ module CommentaireHelper template = is_current_year ? :message_date : :message_date_with_year I18n.l(commentaire.created_at, format: template) end - - private - - def commentaire_is_from_me(commentaire, connected_user) - commentaire.email == connected_user.email - end end diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 72ed5f388..0c01921fb 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -36,6 +36,15 @@ class Commentaire < ApplicationRecord end end + def sent_by_system? + [CONTACT_EMAIL, OLD_CONTACT_EMAIL].include?(email) && + user.nil? && gestionnaire.nil? + end + + def sent_by?(someone) + email == someone.email + end + def file_url if Flipflop.remote_storage? RemoteDownloader.new(file.path).url diff --git a/app/views/shared/dossiers/messages/_message_icon.html.haml b/app/views/shared/dossiers/messages/_message_icon.html.haml index cca3f3568..0d8eb2db1 100644 --- a/app/views/shared/dossiers/messages/_message_icon.html.haml +++ b/app/views/shared/dossiers/messages/_message_icon.html.haml @@ -1,8 +1,7 @@ -- case commentaire.email -- when connected_user.email - = image_tag('icons/account-circle.svg', class: 'person-icon') -- when OLD_CONTACT_EMAIL -- when CONTACT_EMAIL +- if commentaire.sent_by_system? = image_tag('icons/mail.svg', class: 'person-icon') +- elsif commentaire.sent_by?(connected_user) + = image_tag('icons/account-circle.svg', class: 'person-icon') - else = image_tag('icons/blue-person.svg', class: 'person-icon') + diff --git a/app/views/shared/dossiers/messages/_message_issuer.html.haml b/app/views/shared/dossiers/messages/_message_issuer.html.haml index 9cd754130..899a76683 100644 --- a/app/views/shared/dossiers/messages/_message_issuer.html.haml +++ b/app/views/shared/dossiers/messages/_message_issuer.html.haml @@ -1,8 +1,6 @@ -- case commentaire.email -- when connected_user.email - Vous -- when OLD_CONTACT_EMAIL -- when CONTACT_EMAIL +- if commentaire.sent_by_system? Email automatique +- elsif commentaire.sent_by?(connected_user) + Vous - else = commentaire.redacted_email diff --git a/spec/models/commentaire_spec.rb b/spec/models/commentaire_spec.rb index 00807d503..16ed77c83 100644 --- a/spec/models/commentaire_spec.rb +++ b/spec/models/commentaire_spec.rb @@ -7,6 +7,18 @@ describe Commentaire do it { is_expected.to have_db_column(:updated_at) } it { is_expected.to belong_to(:dossier) } + describe "#is_sent_by_system?" do + subject { commentaire.is_sent_by_system? } + + let(:commentaire) { build :commentaire, email: email } + + context 'with a commentaire created by the DS system' do + let(:email) { CONTACT_EMAIL } + + it { is_expected.to be_truthy } + end + end + describe "#redacted_email" do subject { commentaire.redacted_email } From 930fd345de16ddddb1114b5b802e76277d9cb56e Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Mon, 1 Jul 2019 18:14:02 +0200 Subject: [PATCH 13/22] Validate messagerie_available? when creating a new Commentaire Commentaires bu Users and Gestionnaire need the messagerie to be available; Automatic system Commentaires can be created anytime. This reintroduces Commentaire validation that was introduced in #3979 and disabled in #4018 --- app/models/commentaire.rb | 8 ++++++++ spec/models/commentaire_spec.rb | 30 +++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 0c01921fb..0bf5356df 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -7,6 +7,7 @@ class Commentaire < ApplicationRecord mount_uploader :file, CommentaireFileUploader validates :file, file_size: { maximum: 20.megabytes, message: "La taille du fichier doit être inférieure à 20 Mo" } validate :is_virus_free? + validate :messagerie_available?, on: :create validates :body, presence: { message: "Votre message ne peut être vide" } default_scope { order(created_at: :asc) } @@ -78,4 +79,11 @@ class Commentaire < ApplicationRecord errors.add(:file, "Virus détecté dans le fichier joint, merci de changer de fichier") end end + + def messagerie_available? + return if sent_by_system? + if dossier.present? && !dossier.messagerie_available? + errors.add(:dossier, "Il n’est pas possible d’envoyer un message sur un dossier archivé ou en brouillon") + end + end end diff --git a/spec/models/commentaire_spec.rb b/spec/models/commentaire_spec.rb index 16ed77c83..fe27728ea 100644 --- a/spec/models/commentaire_spec.rb +++ b/spec/models/commentaire_spec.rb @@ -7,8 +7,32 @@ describe Commentaire do it { is_expected.to have_db_column(:updated_at) } it { is_expected.to belong_to(:dossier) } - describe "#is_sent_by_system?" do - subject { commentaire.is_sent_by_system? } + describe 'messagerie_available validation' do + subject { commentaire.valid?(:create) } + + context 'with a commentaire created by the DS system' do + let(:commentaire) { build :commentaire, email: CONTACT_EMAIL } + + it { is_expected.to be_truthy } + end + + context 'on an archived dossier' do + let(:dossier) { create :dossier, :archived } + let(:commentaire) { build :commentaire, dossier: dossier } + + it { is_expected.to be_falsey } + end + + context 'on a dossier en_construction' do + let(:dossier) { create :dossier, :en_construction } + let(:commentaire) { build :commentaire, dossier: dossier } + + it { is_expected.to be_truthy } + end + end + + describe "#sent_by_system?" do + subject { commentaire.sent_by_system? } let(:commentaire) { build :commentaire, email: email } @@ -42,7 +66,7 @@ describe Commentaire do let(:gestionnaire) { create(:gestionnaire) } let(:assign_to) { create(:assign_to, gestionnaire: gestionnaire, procedure: procedure) } let(:user) { create(:user) } - let(:dossier) { create(:dossier, procedure: procedure, user: user) } + let(:dossier) { create(:dossier, :en_construction, procedure: procedure, user: user) } let(:commentaire) { Commentaire.new(dossier: dossier, body: "Mon commentaire") } context "with a commentaire created by a gestionnaire" do From fac20ed190a298f64d2210fe9e9ae5dc81b2f322 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Tue, 2 Jul 2019 15:21:49 +0200 Subject: [PATCH 14/22] Fix Commentaire factory so that the default case creates a valid object --- spec/factories/commentaire.rb | 2 +- spec/helpers/commentaire_helper_spec.rb | 2 +- spec/views/shared/dossiers/messages/message.html.haml_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/factories/commentaire.rb b/spec/factories/commentaire.rb index db2824699..811cf0501 100644 --- a/spec/factories/commentaire.rb +++ b/spec/factories/commentaire.rb @@ -4,7 +4,7 @@ FactoryBot.define do before(:create) do |commentaire, _evaluator| if !commentaire.dossier - commentaire.dossier = create :dossier + commentaire.dossier = create :dossier, :en_construction end end end diff --git a/spec/helpers/commentaire_helper_spec.rb b/spec/helpers/commentaire_helper_spec.rb index 80150e52b..c295535e7 100644 --- a/spec/helpers/commentaire_helper_spec.rb +++ b/spec/helpers/commentaire_helper_spec.rb @@ -32,7 +32,7 @@ RSpec.describe CommentaireHelper, type: :helper do end describe '.commentaire_is_from_guest' do - let(:dossier) { create(:dossier) } + let(:dossier) { create(:dossier, :en_instruction) } let!(:guest) { create(:invite, dossier: dossier) } subject { commentaire_is_from_guest(commentaire) } diff --git a/spec/views/shared/dossiers/messages/message.html.haml_spec.rb b/spec/views/shared/dossiers/messages/message.html.haml_spec.rb index 585e3507c..725fdf50c 100644 --- a/spec/views/shared/dossiers/messages/message.html.haml_spec.rb +++ b/spec/views/shared/dossiers/messages/message.html.haml_spec.rb @@ -3,7 +3,7 @@ describe 'shared/dossiers/messages/message.html.haml', type: :view do subject { render 'shared/dossiers/messages/message.html.haml', commentaire: commentaire, messagerie_seen_at: seen_at, connected_user: dossier.user } - let(:dossier) { create(:dossier) } + let(:dossier) { create(:dossier, :en_construction) } let(:commentaire) { create(:commentaire, dossier: dossier) } let(:seen_at) { commentaire.created_at + 1.hour } From 422f4b9cdb901a1c26b9905519d291c76a7dbcde Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 8 Jul 2019 17:58:45 +0200 Subject: [PATCH 15/22] dossiers_controller: warn properly when instructing a dossier twice Fix #4055 --- .../gestionnaires/dossiers_controller.rb | 8 ++++++-- .../gestionnaires/dossiers_controller_spec.rb | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/controllers/gestionnaires/dossiers_controller.rb b/app/controllers/gestionnaires/dossiers_controller.rb index af0f42b6f..685db3f81 100644 --- a/app/controllers/gestionnaires/dossiers_controller.rb +++ b/app/controllers/gestionnaires/dossiers_controller.rb @@ -80,8 +80,12 @@ module Gestionnaires end def passer_en_instruction - dossier.passer_en_instruction!(current_gestionnaire) - flash.notice = 'Dossier passé en instruction.' + if dossier.en_instruction? + flash.notice = 'Le dossier est déjà en instruction.' + else + dossier.passer_en_instruction!(current_gestionnaire) + flash.notice = 'Dossier passé en instruction.' + end render partial: 'state_button_refresh', locals: { dossier: dossier } end diff --git a/spec/controllers/gestionnaires/dossiers_controller_spec.rb b/spec/controllers/gestionnaires/dossiers_controller_spec.rb index 570f6b3c4..ca53d1210 100644 --- a/spec/controllers/gestionnaires/dossiers_controller_spec.rb +++ b/spec/controllers/gestionnaires/dossiers_controller_spec.rb @@ -105,16 +105,26 @@ describe Gestionnaires::DossiersController, type: :controller do end describe '#passer_en_instruction' do + let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } + before do - dossier.en_construction! sign_in gestionnaire post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' - dossier.reload end - it { expect(dossier.state).to eq(Dossier.states.fetch(:en_instruction)) } - it { expect(response.body).to include('.state-button') } + it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) } it { expect(gestionnaire.follow?(dossier)).to be true } + it { expect(response).to have_http_status(:ok) } + it { expect(response.body).to include('.state-button') } + + context 'when the dossier has already been put en_instruction' do + let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) } + + it 'warns about the error, but doesn’t raise' do + expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) + expect(response).to have_http_status(:ok) + end + end end describe '#repasser_en_construction' do From ad0a74ea7c08847f05e008118afd5aea72d0d084 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 4 Jul 2019 15:02:25 +0200 Subject: [PATCH 16/22] Fix dates in dossiers export --- app/models/dossier.rb | 4 ++-- spec/services/procedure_export_v2_service_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 021f750d9..df3133982 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -445,8 +445,8 @@ class Dossier < ApplicationRecord ['Archivé', :archived], ['État du dossier', I18n.t(state, scope: [:activerecord, :attributes, :dossier, :state])], ['Dernière mise à jour le', :updated_at], - ['Passé en construction le', :en_instruction_at], - ['Passé en instruction le', :en_construction_at], + ['Passé en construction le', :en_construction_at], + ['Passé en instruction le', :en_instruction_at], ['Traité le', :processed_at], ['Motivation de la décision', :motivation], ['Instructeurs', followers_gestionnaires.map(&:email).join(' ')] diff --git a/spec/services/procedure_export_v2_service_spec.rb b/spec/services/procedure_export_v2_service_spec.rb index 16b8a92c9..6c88afc94 100644 --- a/spec/services/procedure_export_v2_service_spec.rb +++ b/spec/services/procedure_export_v2_service_spec.rb @@ -80,6 +80,13 @@ describe ProcedureExportV2Service do it 'should have data' do expect(dossiers_sheet.data.size).to eq(1) expect(etablissements_sheet.data.size).to eq(1) + + # SimpleXlsxReader is transforming datetimes in utc... It is only used in test so we just hack around. + offset = dossier.en_construction_at.utc_offset + en_construction_at = Time.zone.at(dossiers_sheet.data[0][9] - offset.seconds) + en_instruction_at = Time.zone.at(dossiers_sheet.data[0][10] - offset.seconds) + expect(en_construction_at).to eq(dossier.en_construction_at.round) + expect(en_instruction_at).to eq(dossier.en_instruction_at.round) end end From 44fa210e34ce7fa039ebf6994fb94676aeb54c24 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Mon, 8 Jul 2019 18:12:32 +0200 Subject: [PATCH 17/22] changement du choix particulier/entreprise lors de creation d'une procedure --- .../admin/procedures/_informations.html.haml | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index 2bf4511e8..864b75887 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -97,14 +97,25 @@ - if !@procedure.locked? .row .col-md-6 - %h4 Particuliers + %h4 À qui s'adresse ma démarche ? .checkbox %label - = f.check_box :for_individual - Cette démarche s'adresse à un public qui - %b - ne possède pas (ou pas encore) de numéro SIRET, - qui doivent donc s'identifier en tant que personne physique. + = f.radio_button :for_individual, 1, :checked => true + %b Ma démarche s'adresse à un particulier + + %p + En choisissant cette option, l'usager devra renseigner son nom et prénom avant d'accéder au formulaire + + .checkbox + %label + = f.radio_button :for_individual, 0, :checked => false + %b Ma démarche s'adresse à une personne morale + + %p + En choisissant cette option, l'usager devra renseigner son n° SIRET. Grâce à l'API Entreprise, seront alors automatiquement remontées les informations sur la personne morale type raison social ou adresse du siège social. + + %b + Si votre démarche s'adresse indifféremment à une personne morale ou un particulier choisissez l'option "particuliers". Vous pourrez utilisez le champ SIRET directement dans le formulaire. %ul#individual-with-siret %li From 39f72a2be388caad91e2961803e678f238b4eba1 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Tue, 9 Jul 2019 09:56:25 +0200 Subject: [PATCH 18/22] courbage d'apostrophes --- app/views/admin/procedures/_informations.html.haml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index 864b75887..746305403 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -97,25 +97,25 @@ - if !@procedure.locked? .row .col-md-6 - %h4 À qui s'adresse ma démarche ? + %h4 À qui s’adresse ma démarche ? .checkbox %label = f.radio_button :for_individual, 1, :checked => true - %b Ma démarche s'adresse à un particulier + %b Ma démarche s’adresse à un particulier %p - En choisissant cette option, l'usager devra renseigner son nom et prénom avant d'accéder au formulaire + En choisissant cette option, l’usager devra renseigner son nom et prénom avant d’accéder au formulaire .checkbox %label = f.radio_button :for_individual, 0, :checked => false - %b Ma démarche s'adresse à une personne morale + %b Ma démarche s’adresse à une personne morale %p - En choisissant cette option, l'usager devra renseigner son n° SIRET. Grâce à l'API Entreprise, seront alors automatiquement remontées les informations sur la personne morale type raison social ou adresse du siège social. + En choisissant cette option, l’usager devra renseigner son n° SIRET. Grâce à l’API Entreprise, seront alors automatiquement remontées les informations sur la personne morale type raison sociale ou adresse du siège social. %b - Si votre démarche s'adresse indifféremment à une personne morale ou un particulier choisissez l'option "particuliers". Vous pourrez utilisez le champ SIRET directement dans le formulaire. + Si votre démarche s’adresse indifféremment à une personne morale ou un particulier choisissez l'option "particuliers". Vous pourrez utilisez le champ SIRET directement dans le formulaire. %ul#individual-with-siret %li From d68d2be798275a96c41b29306abdf30258d23b78 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 2 Jul 2019 18:15:03 +0200 Subject: [PATCH 19/22] Profil: accessible to all roles --- .../profil_controller.rb | 4 +-- app/helpers/tableau_de_bord_helper.rb | 11 ++++++++ app/views/layouts/_account_dropdown.haml | 4 +++ .../new_administrateur/profil/show.html.haml | 25 ------------------ app/views/users/profil/show.html.haml | 26 +++++++++++++++++++ config/routes.rb | 10 +++---- .../profil_controller_spec.rb | 10 +++---- 7 files changed, 53 insertions(+), 37 deletions(-) rename app/controllers/{new_administrateur => users}/profil_controller.rb (71%) create mode 100644 app/helpers/tableau_de_bord_helper.rb delete mode 100644 app/views/new_administrateur/profil/show.html.haml create mode 100644 app/views/users/profil/show.html.haml rename spec/controllers/{new_administrateur => users}/profil_controller_spec.rb (74%) diff --git a/app/controllers/new_administrateur/profil_controller.rb b/app/controllers/users/profil_controller.rb similarity index 71% rename from app/controllers/new_administrateur/profil_controller.rb rename to app/controllers/users/profil_controller.rb index 2414ad3e7..c3b587188 100644 --- a/app/controllers/new_administrateur/profil_controller.rb +++ b/app/controllers/users/profil_controller.rb @@ -1,5 +1,5 @@ -module NewAdministrateur - class ProfilController < AdministrateurController +module Users + class ProfilController < UserController def show end diff --git a/app/helpers/tableau_de_bord_helper.rb b/app/helpers/tableau_de_bord_helper.rb new file mode 100644 index 000000000..6487ecbdc --- /dev/null +++ b/app/helpers/tableau_de_bord_helper.rb @@ -0,0 +1,11 @@ +module TableauDeBordHelper + def tableau_de_bord_helper_path + if current_administrateur.present? + admin_procedures_path + elsif current_gestionnaire.present? + gestionnaire_procedures_path + else + dossiers_path + end + end +end diff --git a/app/views/layouts/_account_dropdown.haml b/app/views/layouts/_account_dropdown.haml index 4044885c4..03bd65201 100644 --- a/app/views/layouts/_account_dropdown.haml +++ b/app/views/layouts/_account_dropdown.haml @@ -26,6 +26,10 @@ = link_to admin_procedures_path, class: "menu-item menu-link" do = image_tag "icons/switch-profile.svg" Passer en administrateur + %li + = link_to profil_path, class: "menu-item menu-link" do + = image_tag "icons/switch-profile.svg" + Voir mon profil %li = link_to destroy_user_session_path, method: :delete, class: "menu-item menu-link" do diff --git a/app/views/new_administrateur/profil/show.html.haml b/app/views/new_administrateur/profil/show.html.haml deleted file mode 100644 index f9775305a..000000000 --- a/app/views/new_administrateur/profil/show.html.haml +++ /dev/null @@ -1,25 +0,0 @@ -= render partial: 'new_administrateur/breadcrumbs', - locals: { steps: [link_to('Tableau de bord', admin_procedures_path), - 'Profil'] } - -#profil-page.container - %h1 Profil - - .card - .card-title Jeton d'identification de l'API (token) - %p Ce jeton est nécessaire pour effectuer des appels vers l'API de demarches-simplifiees.fr. - - - if defined?(@token) - %p Jeton : #{@token} - %p Pour des raisons de sécurité, ce jeton ne sera plus ré-affiché, notez-le bien. - - - else - %p Pour des raisons de sécurité, nous ne pouvons vous l'afficher que lors de sa génération. - %p Attention, si vous avez déjà des applications qui utilisent votre jeton, le regénérer bloquera leurs accès à l'API. - - = link_to "Regénérer et afficher mon jeton", - renew_api_token_path, - method: :post, - class: "button primary", - data: { confirm: "Confirmez-vous la regénération de votre jeton ? Les applications qui l'utilisent actuellement seront bloquées.", - disable: true } diff --git a/app/views/users/profil/show.html.haml b/app/views/users/profil/show.html.haml new file mode 100644 index 000000000..fad4f91db --- /dev/null +++ b/app/views/users/profil/show.html.haml @@ -0,0 +1,26 @@ += render partial: 'new_administrateur/breadcrumbs', + locals: { steps: [link_to('Tableau de bord', tableau_de_bord_helper_path), + 'Profil'] } + +#profil-page.container + %h1 Profil + + - if current_administrateur.present? + .card + .card-title Jeton d'identification de l'API (token) + %p Ce jeton est nécessaire pour effectuer des appels vers l'API de demarches-simplifiees.fr. + + - if defined?(@token) + %p Jeton : #{@token} + %p Pour des raisons de sécurité, ce jeton ne sera plus ré-affiché, notez-le bien. + + - else + %p Pour des raisons de sécurité, nous ne pouvons vous l'afficher que lors de sa génération. + %p Attention, si vous avez déjà des applications qui utilisent votre jeton, le regénérer bloquera leurs accès à l'API. + + = link_to "Regénérer et afficher mon jeton", + renew_api_token_path, + method: :post, + class: "button primary", + data: { confirm: "Confirmez-vous la regénération de votre jeton ? Les applications qui l'utilisent actuellement seront bloquées.", + disable: true } diff --git a/config/routes.rb b/config/routes.rb index 7b454fa57..50517aa0f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -291,6 +291,11 @@ Rails.application.routes.draw do end resource :feedback, only: [:create] get 'demarches' => 'demarches#index' + + get 'profil' => 'profil#show' + post 'renew-api-token' => 'profil#renew_api_token' + # allow refresh 'renew api token' page + get 'renew-api-token' => redirect('/profil') end # @@ -377,11 +382,6 @@ Rails.application.routes.draw do patch 'add_to_procedure' end end - - get 'profil' => 'profil#show' - post 'renew-api-token' => 'profil#renew_api_token' - # allow refresh 'renew api token' page - get 'renew-api-token' => redirect('/profil') end # diff --git a/spec/controllers/new_administrateur/profil_controller_spec.rb b/spec/controllers/users/profil_controller_spec.rb similarity index 74% rename from spec/controllers/new_administrateur/profil_controller_spec.rb rename to spec/controllers/users/profil_controller_spec.rb index 416d70b83..69974ed51 100644 --- a/spec/controllers/new_administrateur/profil_controller_spec.rb +++ b/spec/controllers/users/profil_controller_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -describe NewAdministrateur::ProfilController, type: :controller do - let(:administrateur) { create(:administrateur) } - - before { sign_in(administrateur) } - +describe Users::ProfilController, type: :controller do describe 'POST #renew_api_token' do + let(:administrateur) { create(:administrateur) } + + before { sign_in(administrateur) } + before do allow(administrateur).to receive(:renew_api_token) allow(controller).to receive(:current_administrateur) { administrateur } From 0f9fdf3f756e4fed43c57d30093adf962ba60168 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 4 Jul 2019 16:49:33 +0200 Subject: [PATCH 20/22] Activate device email change confirmation --- config/initializers/devise.rb | 2 +- .../20190704133749_add_unconfirmed_email_column_to_users.rb | 5 +++++ db/schema.rb | 1 + spec/features/admin/connection_spec.rb | 1 + spec/models/user_spec.rb | 2 ++ 5 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190704133749_add_unconfirmed_email_column_to_users.rb diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 536fd745e..4b74c2e52 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -121,7 +121,7 @@ Devise.setup do |config| # initial account confirmation) to be applied. Requires additional unconfirmed_email # db field (see migrations). Until confirmed, new email is stored in # unconfirmed_email column, and copied to email column on successful confirmation. - config.reconfirmable = false + config.reconfirmable = true # Defines which key will be used when confirming an account # config.confirmation_keys = [ :email ] diff --git a/db/migrate/20190704133749_add_unconfirmed_email_column_to_users.rb b/db/migrate/20190704133749_add_unconfirmed_email_column_to_users.rb new file mode 100644 index 000000000..054edb9cf --- /dev/null +++ b/db/migrate/20190704133749_add_unconfirmed_email_column_to_users.rb @@ -0,0 +1,5 @@ +class AddUnconfirmedEmailColumnToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :unconfirmed_email, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index ff7152c3a..e2a264bc4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -605,6 +605,7 @@ ActiveRecord::Schema.define(version: 2019_07_04_144304) do t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" + t.text "unconfirmed_email" t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true diff --git a/spec/features/admin/connection_spec.rb b/spec/features/admin/connection_spec.rb index 14eec8816..6327ee8e1 100644 --- a/spec/features/admin/connection_spec.rb +++ b/spec/features/admin/connection_spec.rb @@ -6,6 +6,7 @@ feature 'Administrator connection' do let(:email) { 'admin1@admin.com' } let(:password) { 'mon chien aime les bananes' } let!(:admin) { create(:administrateur, :with_procedure, email: email, password: password) } + let!(:user) { create(:user, email: email, password: password) } before do Flipflop::FeatureSet.current.test!.switch!(:enable_email_login_token, true) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 9564d4623..34459c7f7 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -107,6 +107,7 @@ describe User, type: :model do gestionnaire = create(:gestionnaire, email: user.email) user.update(email: 'whoami@plop.com', password: 'super secret') + user.confirm gestionnaire.reload expect(gestionnaire.email).to eq('whoami@plop.com') @@ -118,6 +119,7 @@ describe User, type: :model do admin = create(:administrateur, email: user.email) user.update(email: 'whoami@plop.com', password: 'super secret') + user.confirm admin.reload expect(admin.email).to eq('whoami@plop.com') From d36f6ebcd7d7b8e9f87de14eb27f15dc7356a521 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 8 Jul 2019 10:40:50 +0200 Subject: [PATCH 21/22] [fix #1709] A user can change its email --- app/controllers/users/profil_controller.rb | 19 +++++++++ .../confirmation_instructions.html.haml | 24 ++++++++--- app/views/users/profil/show.html.haml | 13 ++++++ config/locales/devise.fr.yml | 2 +- config/routes.rb | 1 + .../users/profil_controller_spec.rb | 41 +++++++++++++++++++ spec/features/users/change_email_spec.rb | 32 +++++++++++++++ 7 files changed, 125 insertions(+), 7 deletions(-) create mode 100644 spec/features/users/change_email_spec.rb diff --git a/app/controllers/users/profil_controller.rb b/app/controllers/users/profil_controller.rb index c3b587188..f976a8775 100644 --- a/app/controllers/users/profil_controller.rb +++ b/app/controllers/users/profil_controller.rb @@ -8,5 +8,24 @@ module Users flash.now.notice = 'Votre jeton a été regénéré.' render :show end + + def update_email + if @current_user.update(update_email_params) + flash.notice = t('devise.registrations.update_needs_confirmation') + # to avoid leaking who has signed in + elsif @current_user.errors&.details&.dig(:email)&.any? { |e| e[:error] == :taken } + flash.notice = t('devise.registrations.update_needs_confirmation') + else + flash.alert = @current_user.errors.full_messages + end + + redirect_to profil_path + end + + private + + def update_email_params + params.require(:user).permit(:email) + end end end diff --git a/app/views/devise_mailer/confirmation_instructions.html.haml b/app/views/devise_mailer/confirmation_instructions.html.haml index a18dda332..a63b05978 100644 --- a/app/views/devise_mailer/confirmation_instructions.html.haml +++ b/app/views/devise_mailer/confirmation_instructions.html.haml @@ -1,10 +1,22 @@ -- content_for(:title, 'Activez votre compte') +-# ugly hack to know if the mail is creation confirmation or a password change confirmation +- if @user.unconfirmed_email.nil? + - content_for(:title, 'Activez votre compte') -%p - Bonjour, + %p + Bonjour, -%p - 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 + 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)) + +- else + - content_for(:title, "Changement d'adresse email") + + %p + Bonjour, + + %p + Pour confirmer votre changement d'adresse email, veuillez cliquer sur le lien suivant : + = link_to(confirmation_url(@user, confirmation_token: @token), confirmation_url(@user, confirmation_token: @token)) = render partial: "layouts/mailers/signature" diff --git a/app/views/users/profil/show.html.haml b/app/views/users/profil/show.html.haml index fad4f91db..b85b1ce90 100644 --- a/app/views/users/profil/show.html.haml +++ b/app/views/users/profil/show.html.haml @@ -5,6 +5,19 @@ #profil-page.container %h1 Profil + .card + .card-title Coordonnées + %p Votre email est actuellement #{current_user.email} + - if current_user.unconfirmed_email.present? + %p + Un email a été envoyé à #{current_user.unconfirmed_email}. + %br + Merci de vérifier vos emails et de cliquer sur le lien d'activation pour finaliser la validation de votre nouvelle adresse. + + = form_for @current_user, url: update_email_path, method: :patch, html: { class: 'form' } do |f| + = f.email_field :email, value: nil, placeholder: 'Nouvelle adresse email', required: true + = f.submit "Changer mon adresse", class: 'button primary' + - if current_administrateur.present? .card .card-title Jeton d'identification de l'API (token) diff --git a/config/locales/devise.fr.yml b/config/locales/devise.fr.yml index 92c4af92d..ebbf87000 100755 --- a/config/locales/devise.fr.yml +++ b/config/locales/devise.fr.yml @@ -42,7 +42,7 @@ fr: signed_up_but_inactive: "Vous êtes bien enregistré. Vous ne pouvez cependant pas vous connecter car votre compte n'est pas encore activé." signed_up_but_locked: "Vous êtes bien enregistré. Vous ne pouvez cependant pas vous connecter car votre compte est verrouillé." signed_up_but_unconfirmed: "Nous vous avons envoyé un email contenant un lien d'activation. Ouvrez ce lien pour activer votre compte." - update_needs_confirmation: "Votre compte a bien été mis à jour mais nous devons vérifier votre nouvelle adresse email. Merci de vérifier vos email et de cliquer sur le lien d'activation pour finaliser la validation de votre nouvelle adresse." + update_needs_confirmation: "Votre compte a bien été mis à jour mais nous devons vérifier votre nouvelle adresse email. Merci de vérifier vos emails et de cliquer sur le lien d'activation pour finaliser la validation de votre nouvelle adresse." updated: "Votre compte a été modifié avec succès." sessions: signed_in: "Connecté." diff --git a/config/routes.rb b/config/routes.rb index 50517aa0f..bb9785886 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -296,6 +296,7 @@ Rails.application.routes.draw do post 'renew-api-token' => 'profil#renew_api_token' # allow refresh 'renew api token' page get 'renew-api-token' => redirect('/profil') + patch 'update_email' => 'profil#update_email' end # diff --git a/spec/controllers/users/profil_controller_spec.rb b/spec/controllers/users/profil_controller_spec.rb index 69974ed51..e151e2f82 100644 --- a/spec/controllers/users/profil_controller_spec.rb +++ b/spec/controllers/users/profil_controller_spec.rb @@ -1,6 +1,10 @@ require 'spec_helper' describe Users::ProfilController, type: :controller do + let(:user) { create(:user) } + + before { sign_in(user) } + describe 'POST #renew_api_token' do let(:administrateur) { create(:administrateur) } @@ -16,4 +20,41 @@ describe Users::ProfilController, type: :controller do it { expect(response.status).to render_template(:show) } it { expect(flash.notice).to eq('Votre jeton a été regénéré.') } end + + describe 'PATCH #update_email' do + context 'when everything is fine' do + before do + patch :update_email, params: { user: { email: 'loulou@lou.com' } } + user.reload + end + + it { expect(user.unconfirmed_email).to eq('loulou@lou.com') } + it { expect(response).to redirect_to(profil_path) } + it { expect(flash.notice).to eq(I18n.t('devise.registrations.update_needs_confirmation')) } + end + + context 'when the mail is already taken' do + let!(:user2) { create(:user) } + + before do + patch :update_email, params: { user: { email: user2.email } } + user.reload + end + + it { expect(response).to redirect_to(profil_path) } + it { expect(flash.notice).to eq(I18n.t('devise.registrations.update_needs_confirmation')) } + end + + context 'when the mail is incorrect' do + let!(:user2) { create(:user) } + + before do + patch :update_email, params: { user: { email: 'incorrect' } } + user.reload + end + + it { expect(response).to redirect_to(profil_path) } + it { expect(flash.alert).to eq(['Email invalide']) } + end + end end diff --git a/spec/features/users/change_email_spec.rb b/spec/features/users/change_email_spec.rb new file mode 100644 index 000000000..a2267733c --- /dev/null +++ b/spec/features/users/change_email_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +feature 'Changing an email' do + let(:old_email) { 'old@email.com' } + let(:user) { create(:user, email: old_email) } + + before do + login_as user, scope: :user + end + + scenario 'is easy' do + new_email = 'new@email.com' + + visit '/profil' + + fill_in :user_email, with: new_email + + perform_enqueued_jobs do + click_button 'Changer mon adresse' + end + + user.reload + expect(user.email).to eq(old_email) + expect(user.unconfirmed_email).to eq(new_email) + + click_confirmation_link_for(new_email) + + user.reload + expect(user.email).to eq(new_email) + expect(user.unconfirmed_email).to be_nil + end +end From ea79b9a5953319982ed9d4623851db5f87d7d29c Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 8 Jul 2019 11:43:02 +0200 Subject: [PATCH 22/22] =?UTF-8?q?typo:=20use=20=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/profil/show.html.haml | 12 ++++++------ config/locales/devise.fr.yml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/users/profil/show.html.haml b/app/views/users/profil/show.html.haml index b85b1ce90..674992d1b 100644 --- a/app/views/users/profil/show.html.haml +++ b/app/views/users/profil/show.html.haml @@ -12,7 +12,7 @@ %p Un email a été envoyé à #{current_user.unconfirmed_email}. %br - Merci de vérifier vos emails et de cliquer sur le lien d'activation pour finaliser la validation de votre nouvelle adresse. + Merci de vérifier vos emails et de cliquer sur le lien d’activation pour finaliser la validation de votre nouvelle adresse. = form_for @current_user, url: update_email_path, method: :patch, html: { class: 'form' } do |f| = f.email_field :email, value: nil, placeholder: 'Nouvelle adresse email', required: true @@ -20,20 +20,20 @@ - if current_administrateur.present? .card - .card-title Jeton d'identification de l'API (token) - %p Ce jeton est nécessaire pour effectuer des appels vers l'API de demarches-simplifiees.fr. + .card-title Jeton d’identification de l’API (token) + %p Ce jeton est nécessaire pour effectuer des appels vers l’API de demarches-simplifiees.fr. - if defined?(@token) %p Jeton : #{@token} %p Pour des raisons de sécurité, ce jeton ne sera plus ré-affiché, notez-le bien. - else - %p Pour des raisons de sécurité, nous ne pouvons vous l'afficher que lors de sa génération. - %p Attention, si vous avez déjà des applications qui utilisent votre jeton, le regénérer bloquera leurs accès à l'API. + %p Pour des raisons de sécurité, nous ne pouvons vous l’afficher que lors de sa génération. + %p Attention, si vous avez déjà des applications qui utilisent votre jeton, le regénérer bloquera leurs accès à l’API. = link_to "Regénérer et afficher mon jeton", renew_api_token_path, method: :post, class: "button primary", - data: { confirm: "Confirmez-vous la regénération de votre jeton ? Les applications qui l'utilisent actuellement seront bloquées.", + data: { confirm: "Confirmez-vous la regénération de votre jeton ? Les applications qui l’utilisent actuellement seront bloquées.", disable: true } diff --git a/config/locales/devise.fr.yml b/config/locales/devise.fr.yml index ebbf87000..30f3ca558 100755 --- a/config/locales/devise.fr.yml +++ b/config/locales/devise.fr.yml @@ -42,7 +42,7 @@ fr: signed_up_but_inactive: "Vous êtes bien enregistré. Vous ne pouvez cependant pas vous connecter car votre compte n'est pas encore activé." signed_up_but_locked: "Vous êtes bien enregistré. Vous ne pouvez cependant pas vous connecter car votre compte est verrouillé." signed_up_but_unconfirmed: "Nous vous avons envoyé un email contenant un lien d'activation. Ouvrez ce lien pour activer votre compte." - update_needs_confirmation: "Votre compte a bien été mis à jour mais nous devons vérifier votre nouvelle adresse email. Merci de vérifier vos emails et de cliquer sur le lien d'activation pour finaliser la validation de votre nouvelle adresse." + update_needs_confirmation: "Votre compte a bien été mis à jour mais nous devons vérifier votre nouvelle adresse email. Merci de vérifier vos emails et de cliquer sur le lien d’activation pour finaliser la validation de votre nouvelle adresse." updated: "Votre compte a été modifié avec succès." sessions: signed_in: "Connecté."