Merge pull request #4634 from betagouv/dev

2019-12-12-01
This commit is contained in:
LeSim 2019-12-12 16:23:05 +01:00 committed by GitHub
commit f2e1a7f18f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 49 additions and 25 deletions

View file

@ -1,5 +1,9 @@
module Users
class ProfilController < UserController
before_action :redirect_if_instructeur,
only: :update_email,
if: -> { instructeur_signed_in? }
def show
end
@ -10,14 +14,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
@ -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

View file

@ -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

View file

@ -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) }

View file

@ -18,9 +18,10 @@
%p
Pour finaliser votre changement dadresse, 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

View file

@ -0,0 +1,5 @@
class RemoveAdministrationIdFromDossierOperationLogs < ActiveRecord::Migration[5.2]
def change
remove_column :dossier_operation_logs, :administration_id, :bigint
end
end

View file

@ -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"

View file

@ -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
@ -62,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

View file

@ -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 }

View file

@ -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

View file

@ -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