From 3afdf9e9ac4223c4869dfe1adac2795741dc6190 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 9 Dec 2019 15:26:45 +0100 Subject: [PATCH 1/8] Remove unused column --- ...1_remove_administration_id_from_dossier_operation_logs.rb | 5 +++++ db/schema.rb | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20191209141641_remove_administration_id_from_dossier_operation_logs.rb diff --git a/db/migrate/20191209141641_remove_administration_id_from_dossier_operation_logs.rb b/db/migrate/20191209141641_remove_administration_id_from_dossier_operation_logs.rb new file mode 100644 index 000000000..b25b2ff94 --- /dev/null +++ b/db/migrate/20191209141641_remove_administration_id_from_dossier_operation_logs.rb @@ -0,0 +1,5 @@ +class RemoveAdministrationIdFromDossierOperationLogs < ActiveRecord::Migration[5.2] + def change + remove_column :dossier_operation_logs, :administration_id, :bigint + end +end diff --git a/db/schema.rb b/db/schema.rb index 3ed58dc87..0ee1c2c04 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_11_28_081324) do +ActiveRecord::Schema.define(version: 2019_12_09_141641) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -224,12 +224,10 @@ ActiveRecord::Schema.define(version: 2019_11_28_081324) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "automatic_operation", default: false, null: false - t.bigint "administration_id" t.datetime "keep_until" t.datetime "executed_at" t.text "digest" t.bigint "bill_signature_id" - t.index ["administration_id"], name: "index_dossier_operation_logs_on_administration_id" t.index ["bill_signature_id"], name: "index_dossier_operation_logs_on_bill_signature_id" t.index ["dossier_id"], name: "index_dossier_operation_logs_on_dossier_id" t.index ["instructeur_id"], name: "index_dossier_operation_logs_on_instructeur_id" @@ -621,7 +619,6 @@ ActiveRecord::Schema.define(version: 2019_11_28_081324) do 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", "administrations" add_foreign_key "dossier_operation_logs", "bill_signatures" add_foreign_key "dossier_operation_logs", "dossiers" add_foreign_key "dossier_operation_logs", "instructeurs" From 301653bb89ce048eb9d7608c9648c4f61df883de Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 9 Dec 2019 16:09:01 +0100 Subject: [PATCH 2/8] Only display email form if the user is not instructeur --- app/views/users/profil/show.html.haml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/users/profil/show.html.haml b/app/views/users/profil/show.html.haml index 58187a6ed..837d963e8 100644 --- a/app/views/users/profil/show.html.haml +++ b/app/views/users/profil/show.html.haml @@ -18,9 +18,10 @@ %p Pour finaliser votre changement d’adresse, vérifiez vos emails et cliquez sur le lien de confirmation. - = 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 !instructeur_signed_in? + = 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 From e06733d01bb18155aee6994170f685a3b87da291 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 9 Dec 2019 16:44:31 +0100 Subject: [PATCH 3/8] Clean spec --- spec/controllers/users/profil_controller_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/controllers/users/profil_controller_spec.rb b/spec/controllers/users/profil_controller_spec.rb index aad9bc371..916935d3c 100644 --- a/spec/controllers/users/profil_controller_spec.rb +++ b/spec/controllers/users/profil_controller_spec.rb @@ -52,8 +52,6 @@ describe Users::ProfilController, type: :controller do end context 'when the mail is incorrect' do - let!(:user2) { create(:user) } - before do patch :update_email, params: { user: { email: 'incorrect' } } user.reload From 21910c959e707e1f285cf8843eb533ca8adfba05 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 9 Dec 2019 16:50:30 +0100 Subject: [PATCH 4/8] @current_user -> current_user --- app/controllers/users/profil_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/users/profil_controller.rb b/app/controllers/users/profil_controller.rb index 13c9c7f20..41cc5b6cf 100644 --- a/app/controllers/users/profil_controller.rb +++ b/app/controllers/users/profil_controller.rb @@ -10,14 +10,14 @@ module Users end def update_email - if @current_user.update(update_email_params) + if current_user.update(update_email_params) flash.notice = t('devise.registrations.update_needs_confirmation') - elsif @current_user.errors&.details&.dig(:email)&.any? { |e| e[:error] == :taken } - UserMailer.account_already_taken(@current_user, requested_email).deliver_later + elsif current_user.errors&.details&.dig(:email)&.any? { |e| e[:error] == :taken } + UserMailer.account_already_taken(current_user, requested_email).deliver_later # avoid leaking information about whether an account with this email exists or not flash.notice = t('devise.registrations.update_needs_confirmation') else - flash.alert = @current_user.errors.full_messages + flash.alert = current_user.errors.full_messages end redirect_to profil_path From 058442c84e751be0a930c825aef1361fd2e15a45 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 9 Dec 2019 17:11:12 +0100 Subject: [PATCH 5/8] [link to #4557] An instructeur cannot change its email on its own --- app/controllers/users/profil_controller.rb | 8 ++++++++ spec/controllers/users/profil_controller_spec.rb | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/controllers/users/profil_controller.rb b/app/controllers/users/profil_controller.rb index 41cc5b6cf..eb9c35409 100644 --- a/app/controllers/users/profil_controller.rb +++ b/app/controllers/users/profil_controller.rb @@ -1,5 +1,9 @@ module Users class ProfilController < UserController + before_action :redirect_if_instructeur, + only: :update_email, + if: -> { instructeur_signed_in? } + def show end @@ -32,5 +36,9 @@ module Users def requested_email update_email_params[:email] end + + def redirect_if_instructeur + redirect_to profil_path + end end end diff --git a/spec/controllers/users/profil_controller_spec.rb b/spec/controllers/users/profil_controller_spec.rb index 916935d3c..82fe1706e 100644 --- a/spec/controllers/users/profil_controller_spec.rb +++ b/spec/controllers/users/profil_controller_spec.rb @@ -60,5 +60,18 @@ describe Users::ProfilController, type: :controller do it { expect(response).to redirect_to(profil_path) } it { expect(flash.alert).to eq(['Email invalide']) } end + + context 'when the user has an instructeur role' do + let(:instructeur_email) { 'instructeur_email@a.com' } + let!(:user) { create(:instructeur, email: instructeur_email).user } + + before do + patch :update_email, params: { user: { email: 'loulou@lou.com' } } + user.reload + end + + it { expect(user.unconfirmed_email).to be_nil } + it { expect(response).to redirect_to(profil_path) } + end end end From 9672d892e934f9c060363ecfcd465a896cd20bb9 Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Mon, 2 Dec 2019 10:27:05 -1000 Subject: [PATCH 6/8] Bug with time zone: Time.zone.today looses time_zone and may breaks database comparisons --- app/services/bill_signature_service.rb | 2 +- spec/jobs/auto_archive_procedure_job_spec.rb | 4 ++-- spec/services/bill_signature_service_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/services/bill_signature_service.rb b/app/services/bill_signature_service.rb index f8640a4b1..7088456f9 100644 --- a/app/services/bill_signature_service.rb +++ b/app/services/bill_signature_service.rb @@ -1,9 +1,9 @@ class BillSignatureService def self.grouped_unsigned_operation_until(date) + date = date.in_time_zone unsigned_operations = DossierOperationLog .where(bill_signature: nil) .where('executed_at < ?', date) - unsigned_operations.group_by { |e| e.executed_at.to_date } end diff --git a/spec/jobs/auto_archive_procedure_job_spec.rb b/spec/jobs/auto_archive_procedure_job_spec.rb index a9cf6c161..52f97ed32 100644 --- a/spec/jobs/auto_archive_procedure_job_spec.rb +++ b/spec/jobs/auto_archive_procedure_job_spec.rb @@ -2,9 +2,9 @@ require 'rails_helper' RSpec.describe AutoArchiveProcedureJob, type: :job do let!(:procedure) { create(:procedure, :published, :with_instructeur, auto_archive_on: nil) } - let!(:procedure_hier) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.ago) } + let!(:procedure_hier) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.ago.to_date) } let!(:procedure_aujourdhui) { create(:procedure, :published, :with_instructeur, auto_archive_on: Time.zone.today) } - let!(:procedure_demain) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.from_now) } + let!(:procedure_demain) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.from_now.to_date) } subject { AutoArchiveProcedureJob.new.perform } diff --git a/spec/services/bill_signature_service_spec.rb b/spec/services/bill_signature_service_spec.rb index 209973c4c..a6192c913 100644 --- a/spec/services/bill_signature_service_spec.rb +++ b/spec/services/bill_signature_service_spec.rb @@ -4,7 +4,7 @@ describe BillSignatureService do describe ".grouped_unsigned_operation_until" do subject { BillSignatureService.grouped_unsigned_operation_until(date).length } - let(:date) { Time.zone.today } + let(:date) { Time.zone.now.beginning_of_day } context "when operations of several days need to be signed" do before do From a02a5edce364be0d9688cfcd4773bd204bb2f64b Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Tue, 10 Dec 2019 08:46:51 -1000 Subject: [PATCH 7/8] Bug with time zone when testing sending of brouillon expiration notices --- spec/models/dossier_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index e0e31b9b4..d885dc2e9 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1049,12 +1049,13 @@ describe Dossier do end describe '#send_brouillon_expiration_notices' do - let!(:procedure) { create(:procedure, duree_conservation_dossiers_dans_ds: 6) } - let!(:date_close_to_expiration) { Date.today - procedure.duree_conservation_dossiers_dans_ds.months + 1.month } - let!(:date_expired) { Date.today - procedure.duree_conservation_dossiers_dans_ds.months - 6.days } - let!(:date_not_expired) { Date.today - procedure.duree_conservation_dossiers_dans_ds.months + 2.months } + before { Timecop.freeze(Time.zone.parse('12/12/2012 15:00:00')) } + + let!(:procedure) { create(:procedure, duree_conservation_dossiers_dans_ds: 6) } + let!(:date_close_to_expiration) { Time.zone.now - procedure.duree_conservation_dossiers_dans_ds.months + 1.month } + let!(:date_expired) { Time.zone.now - procedure.duree_conservation_dossiers_dans_ds.months - 6.days } + let!(:date_not_expired) { Time.zone.now - procedure.duree_conservation_dossiers_dans_ds.months + 2.months } - before { Timecop.freeze(Time.zone.parse('12/12/2012').beginning_of_day) } after { Timecop.return } context "Envoi de message pour les dossiers expirant dans - d'un mois" do From 278659dcb33d52fb55ca6fcd92cd286f6ac6fe7c Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 12 Dec 2019 15:57:47 +0100 Subject: [PATCH 8/8] fix footer without tel --- app/views/layouts/mailers/_service_footer.html.haml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/layouts/mailers/_service_footer.html.haml b/app/views/layouts/mailers/_service_footer.html.haml index 8bfde7a01..0b5b6d90d 100644 --- a/app/views/layouts/mailers/_service_footer.html.haml +++ b/app/views/layouts/mailers/_service_footer.html.haml @@ -26,9 +26,10 @@ - else Par email : = link_to service.email, "mailto:#{service.email}" - %br - Par téléphone : - = link_to service.telephone, service.telephone_url + - if service.telephone_url.present? + %br + Par téléphone : + = link_to service.telephone, service.telephone_url %br Horaires : #{ formatted_horaires(service.horaires) }