Merge pull request #8538 from mfo/US/fix-transfert-with-uppercase

correctif(dossiers.transfert): ne fonctionne pas quand on saisi un mail avec une majuscule
This commit is contained in:
mfo 2023-01-31 16:14:10 +01:00 committed by GitHub
commit 42f93e241f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 5 deletions

View file

@ -26,11 +26,7 @@ module Users
@dossiers_invites = current_user.dossiers_invites.merge(dossiers_visibles)
@dossiers_supprimes_recemment = current_user.dossiers.hidden_by_user.merge(dossiers)
@dossiers_supprimes_definitivement = current_user.deleted_dossiers.order_by_updated_at.page(page)
@dossier_transfers = DossierTransfer
.includes(dossiers: :user)
.with_dossiers
.where(email: current_user.email)
.page(page)
@dossier_transfers = DossierTransfer.for_email(current_user.email).page(page)
@statut = statut(@user_dossiers, @dossiers_traites, @dossiers_invites, @dossiers_supprimes_recemment, @dossiers_supprimes_definitivement, @dossier_transfers, @dossiers_close_to_expiration, params[:statut])
end

View file

@ -8,15 +8,18 @@
# updated_at :datetime not null
#
class DossierTransfer < ApplicationRecord
include EmailSanitizableConcern
has_many :dossiers, dependent: :nullify
EXPIRATION_LIMIT = 2.weeks
validates :email, format: { with: Devise.email_regexp }
before_validation -> { sanitize_email(:email) }
scope :pending, -> { where('created_at > ?', (Time.zone.now - EXPIRATION_LIMIT)) }
scope :stale, -> { where('created_at < ?', (Time.zone.now - EXPIRATION_LIMIT)) }
scope :with_dossiers, -> { joins(:dossiers).merge(Dossier.visible_by_user) }
scope :for_email, -> (email) { includes(dossiers: :user).with_dossiers.where(email: email) }
after_create_commit :send_notification

View file

@ -0,0 +1,20 @@
namespace :after_party do
desc 'Deployment task: fix_dossier_transfer_with_uppercase'
task fix_dossier_transfer_with_uppercase: :environment do
puts "Running deploy task 'fix_dossier_transfer_with_uppercase'"
# in production, about 1000, no need to track progress
DossierTransfer.all.find_each do |dt|
if /A-Z/.match?(dt.email)
dt.email = dt.email.downcase
dt.save
end
end
# Put your task implementation HERE.
# 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: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -26,6 +26,11 @@ describe Users::TransfersController, type: :controller do
it { expect(DossierTransfer.last.dossiers).to eq([dossier]) }
end
context 'with upper case email' do
let(:email) { "Test@rspec.net" }
it { expect(DossierTransfer.last.email).to eq(email.strip.downcase) }
end
shared_examples 'email error' do
it { expect { subject }.not_to change { DossierTransfer.count } }
it { expect(flash.alert).to match([/invalide/]) }