feat: suggest recently added user even if its not confirmed
This commit is contained in:
parent
8d95df2250
commit
d95ce505a8
2 changed files with 16 additions and 9 deletions
|
@ -30,17 +30,22 @@ class Expert < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.autocomplete_mails(procedure)
|
||||
experts = Expert
|
||||
procedure_experts = Expert
|
||||
.joins(:experts_procedures, :user)
|
||||
.where(experts_procedures: { procedure: procedure })
|
||||
.where.not(users: { confirmed_at: nil })
|
||||
|
||||
if procedure.experts_require_administrateur_invitation?
|
||||
experts = experts
|
||||
new_or_confirmed_experts = procedure_experts
|
||||
.where.not(users: { confirmed_at: nil })
|
||||
.or(procedure_experts.where(users: { created_at: 1.day.ago.. }))
|
||||
|
||||
suggested_expert = if procedure.experts_require_administrateur_invitation?
|
||||
new_or_confirmed_experts
|
||||
.where(experts_procedures: { revoked_at: nil })
|
||||
else
|
||||
new_or_confirmed_experts
|
||||
end
|
||||
|
||||
experts
|
||||
suggested_expert
|
||||
.pluck('users.email')
|
||||
.sort
|
||||
end
|
||||
|
|
|
@ -102,17 +102,19 @@ RSpec.describe Expert, type: :model do
|
|||
let(:expert) { create(:expert) }
|
||||
let(:revoked_expert) { create(:expert) }
|
||||
let(:unconfirmed_expert) { create(:expert) }
|
||||
let(:new_unconfirmed_expert) { create(:expert) }
|
||||
|
||||
before do
|
||||
procedure.experts << expert << revoked_expert << unconfirmed_expert
|
||||
procedure.experts << expert << revoked_expert << unconfirmed_expert << new_unconfirmed_expert
|
||||
ExpertsProcedure.find_by(expert: revoked_expert, procedure: procedure)
|
||||
.update!(revoked_at: 1.day.ago)
|
||||
unconfirmed_expert.user.update!(confirmed_at: nil)
|
||||
unconfirmed_expert.user.update!(confirmed_at: nil, created_at: 2.days.ago)
|
||||
new_unconfirmed_expert.user.update!(confirmed_at: nil)
|
||||
end
|
||||
|
||||
context 'when procedure experts need administrateur invitation' do
|
||||
it 'returns only confirmed not revoked experts' do
|
||||
expect(subject).to eq([expert.user.email])
|
||||
expect(subject).to eq([expert.user.email, new_unconfirmed_expert.user.email])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -120,7 +122,7 @@ RSpec.describe Expert, type: :model do
|
|||
let(:procedure) { create(:procedure, experts_require_administrateur_invitation: false) }
|
||||
|
||||
it 'prefill autocomplete with all confirmed experts in the procedure' do
|
||||
expect(subject).to eq([expert.user.email, revoked_expert.user.email])
|
||||
expect(subject).to eq([expert.user.email, revoked_expert.user.email, new_unconfirmed_expert.user.email])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue