Merge pull request #5173 from betagouv/dev

2020-05-18-01
This commit is contained in:
Keirua 2020-05-18 17:03:50 +02:00 committed by GitHub
commit cc274b320d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 113 additions and 43 deletions

View file

@ -39,6 +39,13 @@ module Manager
redirect_to manager_procedure_path(procedure)
end
def export_mail_brouillons
dossiers = procedure.dossiers.state_brouillon.includes(:user)
emails = dossiers.map { |d| d.user.email }.sort.uniq
date = Time.zone.now.strftime('%d-%m-%Y')
send_data(emails.join("\n"), :filename => "brouillons-#{procedure.id}-au-#{date}.csv")
end
def add_administrateur
administrateur = Administrateur.by_email(params[:email])
if administrateur

View file

@ -34,7 +34,11 @@ class Commentaire < ApplicationRecord
def redacted_email
if instructeur.present?
instructeur.email.split('@').first
if Flipper.enabled?(:hide_instructeur_email, dossier.procedure)
"Instructeur n° #{instructeur.id}"
else
instructeur.email.split('@').first
end
else
email
end

View file

@ -626,9 +626,11 @@ class Dossier < ApplicationRecord
columns += [
['Civilité', individual&.gender],
['Nom', individual&.nom],
['Prénom', individual&.prenom],
['Date de naissance', individual&.birthdate]
['Prénom', individual&.prenom]
]
if procedure.ask_birthday
columns += [['Date de naissance', individual&.birthdate]]
end
elsif with_etablissement
columns += [
['Établissement SIRET', etablissement&.siret],

View file

@ -117,14 +117,14 @@ class ExpiredDossiersDeletionService
.group_by(&:user)
.each do |(user, dossiers)|
DossierMailer.notify_automatic_deletion_to_user(
DeletedDossier.where(dossier_id: dossiers.map(&:id)),
DeletedDossier.where(dossier_id: dossiers.map(&:id)).to_a,
user.email
).deliver_later
end
self.group_by_fonctionnaire_email(dossiers_to_remove).each do |(email, dossiers)|
DossierMailer.notify_automatic_deletion_to_administration(
DeletedDossier.where(dossier_id: dossiers.map(&:id)),
DeletedDossier.where(dossier_id: dossiers.map(&:id)).to_a,
email
).deliver_later

View file

@ -71,5 +71,8 @@ as well as a link to its edit page.
<% end %>
</dd>
<% end %>
<dd class="attribute-data">
<a class="button" href="<%= export_mail_brouillons_manager_procedure_url(procedure) %>">Télécharger un export CSV contenant les emails des demandeurs ayant effectué une demandes en brouillon</a>
</dd>
</dl>
</section>

View file

@ -67,26 +67,34 @@
- elsif etablissement.exercices.present?
= t('activemodel.models.exercices_summary', count: etablissement.exercices.count)
- if profile == 'instructeur'
- if etablissement.entreprise_attestation_sociale.attached?
%tr
%th.libelle Attestation sociale
- if etablissement.entreprise_attestation_sociale.attached?
%tr
%th.libelle Attestation sociale
- if profile == 'instructeur'
%td= link_to "Consulter l'attestation", url_for(etablissement.entreprise_attestation_sociale)
- else
%td Une attestation de vigilance délivrée par l'ACOSS a été jointe à votre dossier.
- if etablissement.entreprise_attestation_fiscale.attached?
%tr
%th.libelle Attestation fiscale
- if etablissement.entreprise_attestation_fiscale.attached?
%tr
%th.libelle Attestation fiscale
- if profile == 'instructeur'
%td= link_to "Consulter l'attestation", url_for(etablissement.entreprise_attestation_fiscale)
- else
%td Une attestation fiscale délivrée par l'URSSAF a été jointe à votre dossier.
- if etablissement.entreprise_bilans_bdf.present?
%tr
%th.libelle
Bilans Banque de France
= "en #{etablissement.entreprise_bilans_bdf_monnaie}"
- if etablissement.entreprise_bilans_bdf.present?
%tr
%th.libelle
Bilans Banque de France
= "en #{etablissement.entreprise_bilans_bdf_monnaie}"
- if profile == 'instructeur'
- if controller.is_a?(Instructeurs::AvisController)
%td= link_to "Consulter les bilans", bilans_bdf_instructeur_avis_path(@avis.id)
- else
%td= link_to "Consulter les bilans", bilans_bdf_instructeur_dossier_path(procedure_id: @dossier.procedure.id, dossier_id: @dossier.id)
- else
%td Les 3 derniers bilans connus de votre entreprise par la Banque de France ont été joints à votre dossier.
- if etablissement.association?
%tr

View file

@ -1,16 +1,14 @@
- more_infos_url = 'https://faq.demarches-simplifiees.fr/article/73-enregistrer-mon-dossier?preview=5dcbf0bb2c7d3a7e9ae3e33f'
.autosave.autosave-state-idle
%p.autosave-explanation
%span.autosave-explanation-text
Votre brouillon est automatiquement enregistré.
= link_to 'En savoir plus', more_infos_url, target: '_blank', rel: 'noopener', class: 'autosave-more-infos'
= link_to 'En savoir plus', FAQ_AUTOSAVE_URL, target: '_blank', rel: 'noopener', class: 'autosave-more-infos'
%p.autosave-status.succeeded
%span.autosave-icon.icon.accept
%span.autosave-label
Brouillon enregistré
= link_to 'En savoir plus', more_infos_url, target: '_blank', rel: 'noopener', class: 'autosave-more-infos'
= link_to 'En savoir plus', FAQ_AUTOSAVE_URL, target: '_blank', rel: 'noopener', class: 'autosave-more-infos'
%p.autosave-status.failed
%span.autosave-icon ⚠️

View file

@ -23,7 +23,8 @@ API_DOC_URL = [DOC_URL, "pour-aller-plus-loin", "api"].join("/")
WEBHOOK_DOC_URL = [DOC_URL, "pour-aller-plus-loin", "webhook"].join("/")
ARCHIVAGE_DOC_URL = [DOC_URL, "pour-aller-plus-loin", "archivage-longue-duree-des-demarches"].join("/")
FAQ_URL = "https://faq.demarches-simplifiees.fr"
FAQ_ADMIN_URL = "https://faq.demarches-simplifiees.fr/collection/1-administrateur"
FAQ_ADMIN_URL = [FAQ_URL, "collection", "1-administrateur-creation-dun-formulaire"].join("/")
FAQ_AUTOSAVE_URL = [FAQ_URL, "article", "77-enregistrer-mon-formulaire-pour-le-reprendre-plus-tard?preview=5ec28ca1042863474d1aee00"].join("/")
COMMENT_TROUVER_MA_DEMARCHE_URL = [FAQ_URL, "article", "59-comment-trouver-ma-demarche"].join("/")
STATUS_PAGE_URL = "https://status.demarches-simplifiees.fr"
MATOMO_IFRAME_URL = "https://stats.data.gouv.fr/index.php?module=CoreAdminHome&action=optOut&language=fr&&fontColor=333333&fontSize=16px&fontFamily=Muli"

View file

@ -13,6 +13,7 @@ Rails.application.routes.draw do
post 'restore', on: :member
post 'add_administrateur', on: :member
post 'change_piece_justificative_template', on: :member
get 'export_mail_brouillons', on: :member
end
resources :dossiers, only: [:index, :show] do

View file

@ -44,11 +44,22 @@ describe Commentaire do
describe "#redacted_email" do
subject { commentaire.redacted_email }
let(:procedure) { create(:procedure) }
let(:dossier) { create(:dossier, procedure: procedure) }
context 'with a commentaire created by a instructeur' do
let(:commentaire) { build :commentaire, instructeur: instructeur }
let(:commentaire) { build :commentaire, instructeur: instructeur, dossier: dossier }
let(:instructeur) { build :instructeur, email: 'some_user@exemple.fr' }
it { is_expected.to eq 'some_user' }
context 'when the procedure shows instructeurs email' do
before { Flipper.disable(:hide_instructeur_email, procedure) }
it { is_expected.to eq 'some_user' }
end
context 'when the procedure hides instructeurs email' do
before { Flipper.enable(:hide_instructeur_email, procedure) }
it { is_expected.to eq "Instructeur n° #{instructeur.id}" }
end
end
context 'with a commentaire created by a user' do

View file

@ -19,8 +19,8 @@ describe ExpiredDossiersDeletionService do
let!(:valid_brouillon) { create(:dossier, procedure: procedure, created_at: date_not_expired) }
before do
allow(DossierMailer).to receive(:notify_brouillon_near_deletion).and_return(double(deliver_later: nil))
allow(DossierMailer).to receive(:notify_brouillon_deletion).and_return(double(deliver_later: nil))
allow(DossierMailer).to receive(:notify_brouillon_near_deletion).and_call_original
allow(DossierMailer).to receive(:notify_brouillon_deletion).and_call_original
ExpiredDossiersDeletionService.process_expired_dossiers_brouillon
end
@ -207,8 +207,8 @@ describe ExpiredDossiersDeletionService do
after { Timecop.return }
before do
allow(DossierMailer).to receive(:notify_automatic_deletion_to_user).and_return(double(deliver_later: nil))
allow(DossierMailer).to receive(:notify_automatic_deletion_to_administration).and_return(double(deliver_later: nil))
allow(DossierMailer).to receive(:notify_automatic_deletion_to_user).and_call_original
allow(DossierMailer).to receive(:notify_automatic_deletion_to_administration).and_call_original
end
context 'with a single dossier' do
@ -275,8 +275,8 @@ describe ExpiredDossiersDeletionService do
after { Timecop.return }
before do
allow(DossierMailer).to receive(:notify_near_deletion_to_user).and_return(double(deliver_later: nil))
allow(DossierMailer).to receive(:notify_near_deletion_to_administration).and_return(double(deliver_later: nil))
allow(DossierMailer).to receive(:notify_near_deletion_to_user).and_call_original
allow(DossierMailer).to receive(:notify_near_deletion_to_administration).and_call_original
end
context 'with a single dossier' do
@ -344,8 +344,8 @@ describe ExpiredDossiersDeletionService do
after { Timecop.return }
before do
allow(DossierMailer).to receive(:notify_automatic_deletion_to_user).and_return(double(deliver_later: nil))
allow(DossierMailer).to receive(:notify_automatic_deletion_to_administration).and_return(double(deliver_later: nil))
allow(DossierMailer).to receive(:notify_automatic_deletion_to_user).and_call_original
allow(DossierMailer).to receive(:notify_automatic_deletion_to_administration).and_call_original
end
context 'with a single dossier' do

View file

@ -25,13 +25,13 @@ describe ProcedureExportService do
procedure.reload
end
context 'dossiers' do
it 'should have sheets' do
describe 'sheets' do
it 'should have a sheet for each record type' do
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis'])
end
end
context 'with dossier' do
describe 'Dossiers sheet' do
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure) }
let(:nominal_headers) do
@ -41,7 +41,6 @@ describe ProcedureExportService do
"Civilité",
"Nom",
"Prénom",
"Date de naissance",
"Archivé",
"État du dossier",
"Dernière mise à jour le",
@ -88,23 +87,32 @@ describe ProcedureExportService do
# SimpleXlsxReader is transforming datetimes in utc... It is only used in test so we just hack around.
offset = dossier.en_construction_at.utc_offset
en_construction_at = Time.zone.at(dossiers_sheet.data[0][9] - offset.seconds)
en_instruction_at = Time.zone.at(dossiers_sheet.data[0][10] - offset.seconds)
en_construction_at = Time.zone.at(dossiers_sheet.data[0][8] - offset.seconds)
en_instruction_at = Time.zone.at(dossiers_sheet.data[0][9] - offset.seconds)
expect(en_construction_at).to eq(dossier.en_construction_at.round)
expect(en_instruction_at).to eq(dossier.en_instruction_at.round)
end
context 'with a birthdate' do
before { procedure.update(ask_birthday: true) }
let(:birthdate_headers) { nominal_headers.insert(nominal_headers.index('Archivé'), 'Date de naissance') }
it { expect(dossiers_sheet.headers).to match(birthdate_headers) }
it { expect(dossiers_sheet.data[0][dossiers_sheet.headers.index('Date de naissance')]).to be_a(Date) }
end
context 'with a procedure routee' do
before { procedure.groupe_instructeurs.create(label: '2') }
let(:routee_header) { nominal_headers.insert(nominal_headers.index('textarea'), 'Groupe instructeur') }
let(:routee_headers) { nominal_headers.insert(nominal_headers.index('textarea'), 'Groupe instructeur') }
it { expect(dossiers_sheet.headers).to match(routee_header) }
it { expect(dossiers_sheet.headers).to match(routee_headers) }
it { expect(dossiers_sheet.data[0][dossiers_sheet.headers.index('Groupe instructeur')]).to eq('défaut') }
end
end
context 'with etablissement' do
describe 'Etablissement sheet' do
let(:procedure) { create(:procedure, :published, :with_all_champs) }
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_entreprise, procedure: procedure) }
@ -284,7 +292,7 @@ describe ProcedureExportService do
end
end
context 'with avis' do
describe 'Avis sheet' do
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure) }
let!(:avis) { create(:avis, :with_answer, dossier: dossier) }
@ -305,7 +313,7 @@ describe ProcedureExportService do
end
end
context 'with repetitions' do
describe 'Repetitions sheet' do
let!(:dossiers) do
[
create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure),

View file

@ -20,4 +20,31 @@ describe 'shared/dossiers/messages/message.html.haml', type: :view do
it { is_expected.to have_css(".highlighted") }
end
context 'with an instructeur message' do
let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure) }
let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message') }
let(:dossier) { create(:dossier, :en_construction, commentaires: [commentaire], procedure: procedure) }
context 'on a procedure with anonymous instructeurs' do
before { Flipper.enable_actor(:hide_instructeur_email, procedure) }
context 'redacts the instructeur email' do
it { is_expected.to have_text(commentaire.body) }
it { is_expected.to have_text("Instructeur n° #{instructeur.id}") }
it { is_expected.not_to have_text(instructeur.email) }
end
end
context 'on a procedure where instructeurs names are not redacted' do
before { Flipper.disable_actor(:hide_instructeur_email, procedure) }
context 'redacts the instructeur email but keeps the name' do
it { is_expected.to have_text(commentaire.body) }
it { is_expected.to have_text(instructeur.email.split('@').first) }
it { is_expected.not_to have_text(instructeur.email) }
end
end
end
end