Merge pull request #5376 from betagouv/dev
This commit is contained in:
commit
7f49359b88
13 changed files with 123 additions and 23 deletions
|
@ -1,4 +1,6 @@
|
|||
class VirusScannerJob < ApplicationJob
|
||||
discard_on ActiveRecord::RecordNotFound
|
||||
|
||||
def perform(blob)
|
||||
metadata = extract_metadata_via_virus_scanner(blob)
|
||||
blob.update!(metadata: blob.metadata.merge(metadata))
|
||||
|
|
|
@ -8,6 +8,12 @@ class ApplicationMailer < ActionMailer::Base
|
|||
message.perform_deliveries = false
|
||||
end
|
||||
|
||||
rescue_from Net::SMTPServerBusy do |error|
|
||||
if error.message =~ /unexpected recipients/
|
||||
message.perform_deliveries = false
|
||||
end
|
||||
end
|
||||
|
||||
# Attach the procedure logo to the email (if any).
|
||||
# Returns the attachment url.
|
||||
def attach_logo(procedure)
|
||||
|
|
|
@ -9,6 +9,12 @@ class DeviseUserMailer < Devise::Mailer
|
|||
message.perform_deliveries = false
|
||||
end
|
||||
|
||||
rescue_from Net::SMTPServerBusy do |error|
|
||||
if error.message =~ /unexpected recipients/
|
||||
message.perform_deliveries = false
|
||||
end
|
||||
end
|
||||
|
||||
def template_paths
|
||||
['devise_mailer']
|
||||
end
|
||||
|
|
|
@ -24,6 +24,8 @@ class Champs::PieceJustificativeChamp < Champ
|
|||
# content_type: ACCEPTED_FORMATS,
|
||||
# size: { less_than: MAX_SIZE }
|
||||
|
||||
before_save :update_skip_pj_validation
|
||||
|
||||
def main_value_name
|
||||
:piece_justificative_file
|
||||
end
|
||||
|
@ -45,4 +47,8 @@ class Champs::PieceJustificativeChamp < Champ
|
|||
piece_justificative_file.service_url
|
||||
end
|
||||
end
|
||||
|
||||
def update_skip_pj_validation
|
||||
type_de_champ.update(skip_pj_validation: true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -440,17 +440,16 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
|
||||
def usual_traitement_time
|
||||
# times = Traitement.includes(:dossier)
|
||||
# .where(state: Dossier::TERMINE)
|
||||
# .where(processed_at: 1.month.ago..Time.zone.now)
|
||||
# .pluck('dossiers.en_construction_at', :processed_at)
|
||||
# .map { |(en_construction_at, processed_at)| processed_at - en_construction_at }
|
||||
times = Traitement.includes(:dossier)
|
||||
.where(dossier: self.dossiers)
|
||||
.where.not('dossiers.en_construction_at' => nil, :processed_at => nil)
|
||||
.where(processed_at: 1.month.ago..Time.zone.now)
|
||||
.pluck('dossiers.en_construction_at', :processed_at)
|
||||
.map { |(en_construction_at, processed_at)| processed_at - en_construction_at }
|
||||
|
||||
# if times.present?
|
||||
# times.percentile(90).ceil
|
||||
# end
|
||||
|
||||
false
|
||||
if times.present?
|
||||
times.percentile(90).ceil
|
||||
end
|
||||
end
|
||||
|
||||
def populate_champ_stable_ids
|
||||
|
|
|
@ -35,7 +35,7 @@ class TypeDeChamp < ApplicationRecord
|
|||
belongs_to :parent, class_name: 'TypeDeChamp'
|
||||
has_many :types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'TypeDeChamp', inverse_of: :parent, dependent: :destroy
|
||||
|
||||
store_accessor :options, :cadastres, :quartiers_prioritaires, :parcelles_agricoles, :old_pj, :drop_down_options
|
||||
store_accessor :options, :cadastres, :quartiers_prioritaires, :parcelles_agricoles, :old_pj, :drop_down_options, :skip_pj_validation
|
||||
delegate :tags_for_template, to: :dynamic_type
|
||||
|
||||
class WithIndifferentAccess
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: add_default_skip_validation_to_piece_justificative'
|
||||
task add_default_skip_validation_to_piece_justificative: :environment do
|
||||
puts "Running deploy task 'add_default_skip_validation_to_piece_justificative'"
|
||||
|
||||
tdcs = TypeDeChamp.where(type_champ: TypeDeChamp.type_champs.fetch(:piece_justificative))
|
||||
progress = ProgressReport.new(tdcs.count)
|
||||
tdcs.find_each do |tdc|
|
||||
tdc.update(skip_pj_validation: true)
|
||||
progress.inc
|
||||
end
|
||||
progress.finish
|
||||
|
||||
# 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: '20200708101123'
|
||||
end
|
||||
end
|
|
@ -19,7 +19,7 @@ describe 'Dossier details:' do
|
|||
describe "the user can see the mean time they are expected to wait" do
|
||||
let(:other_dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure, en_construction_at: 10.days.ago, en_instruction_at: 9.days.ago, processed_at: Time.zone.now) }
|
||||
|
||||
context "when the dossier is in construction", pending: true do
|
||||
context "when the dossier is in construction" do
|
||||
it "displays the estimated wait duration" do
|
||||
other_dossier
|
||||
visit dossier_path(dossier)
|
||||
|
@ -27,7 +27,7 @@ describe 'Dossier details:' do
|
|||
end
|
||||
end
|
||||
|
||||
context "when the dossier is in instruction", pending: true do
|
||||
context "when the dossier is in instruction" do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_individual, :with_commentaires, user: user, procedure: procedure) }
|
||||
|
||||
it "displays the estimated wait duration" do
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
RSpec.describe VirusScannerJob, type: :job do
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
let(:champ) do
|
||||
champ = create(:champ, :piece_justificative)
|
||||
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
|
||||
champ.save
|
||||
champ
|
||||
end
|
||||
|
||||
subject { VirusScannerJob.new.perform(champ.piece_justificative_file.blob) }
|
||||
subject do
|
||||
perform_enqueued_jobs do
|
||||
VirusScannerJob.perform_later(champ.piece_justificative_file.blob)
|
||||
end
|
||||
end
|
||||
|
||||
context "when no virus is found" do
|
||||
let(:virus_found?) { true }
|
||||
|
@ -15,7 +22,7 @@ RSpec.describe VirusScannerJob, type: :job do
|
|||
subject
|
||||
end
|
||||
|
||||
it { expect(champ.piece_justificative_file.virus_scanner.safe?).to be_truthy }
|
||||
it { expect(champ.reload.piece_justificative_file.virus_scanner.safe?).to be_truthy }
|
||||
end
|
||||
|
||||
context "when a virus is found" do
|
||||
|
@ -26,6 +33,16 @@ RSpec.describe VirusScannerJob, type: :job do
|
|||
subject
|
||||
end
|
||||
|
||||
it { expect(champ.piece_justificative_file.virus_scanner.infected?).to be_truthy }
|
||||
it { expect(champ.reload.piece_justificative_file.virus_scanner.infected?).to be_truthy }
|
||||
end
|
||||
|
||||
context "when the blob has been deleted" do
|
||||
before do
|
||||
Champ.find(champ.id).piece_justificative_file.purge
|
||||
end
|
||||
|
||||
it "ignores the error" do
|
||||
expect { subject }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
describe '20200708101123_add_default_skip_validation_to_piece_justificative.rake' do
|
||||
let(:rake_task) { Rake::Task['after_party:add_default_skip_validation_to_piece_justificative'] }
|
||||
let!(:pj_type_de_champ) { create(:type_de_champ_piece_justificative) }
|
||||
let!(:text_type_de_champ) { create(:type_de_champ_text) }
|
||||
|
||||
before do
|
||||
rake_task.invoke
|
||||
text_type_de_champ.reload
|
||||
pj_type_de_champ.reload
|
||||
end
|
||||
|
||||
after { rake_task.reenable }
|
||||
|
||||
context 'on a piece_justificative type de champ' do
|
||||
it 'sets the skip_pj_validation option' do
|
||||
expect(pj_type_de_champ.skip_pj_validation).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
context 'on a non piece_justificative type de champ' do
|
||||
it 'does not set the skip_pj_validation option' do
|
||||
expect(text_type_de_champ.skip_pj_validation).to be_blank
|
||||
end
|
||||
end
|
||||
end
|
|
@ -7,10 +7,18 @@ RSpec.describe ApplicationMailer, type: :mailer do
|
|||
before do
|
||||
allow_any_instance_of(DossierMailer)
|
||||
.to receive(:notify_new_draft)
|
||||
.and_raise(Net::SMTPSyntaxError)
|
||||
.and_raise(smtp_error)
|
||||
end
|
||||
|
||||
it { expect(subject.message).to be_an_instance_of(ActionMailer::Base::NullMail) }
|
||||
context 'when the server handles invalid emails with Net::SMTPSyntaxError' do
|
||||
let(:smtp_error) { Net::SMTPSyntaxError.new }
|
||||
it { expect(subject.message).to be_an_instance_of(ActionMailer::Base::NullMail) }
|
||||
end
|
||||
|
||||
context 'when the server handles invalid emails with Net::SMTPServerBusy' do
|
||||
let(:smtp_error) { Net::SMTPServerBusy.new('400 unexpected recipients: want atleast 1, got 0') }
|
||||
it { expect(subject.message).to be_an_instance_of(ActionMailer::Base::NullMail) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'valid emails are sent' do
|
||||
|
|
|
@ -3,6 +3,19 @@ require 'active_storage_validations/matchers'
|
|||
describe Champs::PieceJustificativeChamp do
|
||||
include ActiveStorageValidations::Matchers
|
||||
|
||||
describe "update_skip_validation" do
|
||||
subject { champ_pj.type_de_champ.skip_pj_validation }
|
||||
|
||||
context 'before_save' do
|
||||
let(:champ_pj) { build (:champ_piece_justificative) }
|
||||
it { is_expected.to be_falsy }
|
||||
end
|
||||
context 'after_save' do
|
||||
let(:champ_pj) { create (:champ_piece_justificative) }
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: once we're running on Rails 6, re-enable the PieceJustificativeChamp validator,
|
||||
# and re-enable this spec.
|
||||
#
|
||||
|
|
|
@ -981,7 +981,7 @@ describe Procedure do
|
|||
context 'when there are several processed dossiers' do
|
||||
let(:delays) { [1.day, 2.days, 2.days, 2.days, 2.days, 3.days, 3.days, 3.days, 3.days, 12.days] }
|
||||
|
||||
it 'returns a time representative of the dossier instruction delay', pending: true do
|
||||
it 'returns a time representative of the dossier instruction delay' do
|
||||
expect(procedure.usual_traitement_time).to be_between(3.days, 4.days)
|
||||
end
|
||||
end
|
||||
|
@ -990,7 +990,7 @@ describe Procedure do
|
|||
let(:delays) { [2.days, 2.days] }
|
||||
let!(:old_dossier) { create_dossier(construction_date: 3.months.ago, instruction_date: 2.months.ago, processed_date: 2.months.ago) }
|
||||
|
||||
it 'ignores dossiers older than 1 month', pending: true do
|
||||
it 'ignores dossiers older than 1 month' do
|
||||
expect(procedure.usual_traitement_time).to be_within(1.hour).of(2.days)
|
||||
end
|
||||
end
|
||||
|
@ -999,17 +999,17 @@ describe Procedure do
|
|||
let(:delays) { [2.days, 2.days] }
|
||||
let!(:bad_dossier) { create_dossier(construction_date: nil, instruction_date: nil, processed_date: 10.days.ago) }
|
||||
|
||||
it 'ignores bad dossiers', pending: true do
|
||||
it 'ignores bad dossiers' do
|
||||
expect(procedure.usual_traitement_time).to be_within(1.hour).of(2.days)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there is only one processed dossier', pending: true do
|
||||
context 'when there is only one processed dossier' do
|
||||
let(:delays) { [1.day] }
|
||||
it { expect(procedure.usual_traitement_time).to be_within(1.hour).of(1.day) }
|
||||
end
|
||||
|
||||
context 'where there is no processed dossier', pending: true do
|
||||
context 'where there is no processed dossier' do
|
||||
let(:delays) { [] }
|
||||
it { expect(procedure.usual_traitement_time).to be_nil }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue