Merge pull request #5321 from betagouv/dev

2020-07-01-01
This commit is contained in:
krichtof 2020-07-01 11:59:05 +02:00 committed by GitHub
commit b52a9879e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 228 additions and 154 deletions

View file

@ -11,7 +11,13 @@ module Instructeurs
DONNES_STATUS = 'donnes' DONNES_STATUS = 'donnes'
def index def index
instructeur_avis = current_instructeur.avis.includes(dossier: [:procedure, :user]) avis = current_instructeur.avis.includes(dossier: [groupe_instructeur: :procedure])
@avis_by_procedure = avis.to_a.group_by(&:procedure)
end
def procedure
@procedure = Procedure.find(params[:procedure_id])
instructeur_avis = current_instructeur.avis.includes(:dossier).where(dossiers: { groupe_instructeur: GroupeInstructeur.where(procedure: @procedure.id) })
@avis_a_donner = instructeur_avis.without_answer @avis_a_donner = instructeur_avis.without_answer
@avis_donnes = instructeur_avis.with_answer @avis_donnes = instructeur_avis.with_answer
@ -37,7 +43,7 @@ module Instructeurs
def update def update
if @avis.update(avis_params) if @avis.update(avis_params)
flash.notice = 'Votre réponse est enregistrée.' flash.notice = 'Votre réponse est enregistrée.'
redirect_to instruction_instructeur_avis_path(@avis) redirect_to instruction_instructeur_avis_path(@avis.procedure, @avis)
else else
flash.now.alert = @avis.errors.full_messages flash.now.alert = @avis.errors.full_messages
@new_avis = Avis.new @new_avis = Avis.new
@ -54,7 +60,7 @@ module Instructeurs
if @commentaire.save if @commentaire.save
flash.notice = "Message envoyé" flash.notice = "Message envoyé"
redirect_to messagerie_instructeur_avis_path(avis) redirect_to messagerie_instructeur_avis_path(avis.procedure, avis)
else else
flash.alert = @commentaire.errors.full_messages flash.alert = @commentaire.errors.full_messages
render :messagerie render :messagerie
@ -65,7 +71,7 @@ module Instructeurs
@new_avis = create_avis_from_params(avis.dossier, avis.confidentiel) @new_avis = create_avis_from_params(avis.dossier, avis.confidentiel)
if @new_avis.nil? if @new_avis.nil?
redirect_to instruction_instructeur_avis_path(avis) redirect_to instruction_instructeur_avis_path(avis.procedure, avis)
else else
set_avis_and_dossier set_avis_and_dossier
render :instruction render :instruction
@ -89,6 +95,8 @@ module Instructeurs
end end
def create_instructeur def create_instructeur
procedure_id = params[:procedure_id]
avis_id = params[:id]
email = params[:email] email = params[:email]
password = params[:user][:password] password = params[:user][:password]
@ -99,10 +107,10 @@ module Instructeurs
sign_in(user) sign_in(user)
Avis.link_avis_to_instructeur(user.instructeur) Avis.link_avis_to_instructeur(user.instructeur)
redirect_to url_for(instructeur_avis_index_path) redirect_to url_for(instructeur_all_avis_path)
else else
flash[:alert] = user.errors.full_messages flash[:alert] = user.errors.full_messages
redirect_to url_for(sign_up_instructeur_avis_path(params[:id], email)) redirect_to url_for(sign_up_instructeur_avis_path(procedure_id, avis_id, email))
end end
end end
@ -119,7 +127,7 @@ module Instructeurs
if current_instructeur.present? if current_instructeur.present?
# a instructeur is authenticated ... lets see if it can view the dossier # a instructeur is authenticated ... lets see if it can view the dossier
redirect_to instructeur_avis_url(avis) redirect_to instructeur_avis_url(avis.procedure, avis)
elsif avis.instructeur&.email == params[:email] elsif avis.instructeur&.email == params[:email]
# the avis instructeur has already signed up and it sould sign in # the avis instructeur has already signed up and it sould sign in

View file

@ -284,7 +284,7 @@ module Instructeurs
def redirect_to_avis_if_needed def redirect_to_avis_if_needed
if current_instructeur.procedures.count == 0 && current_instructeur.avis.count > 0 if current_instructeur.procedures.count == 0 && current_instructeur.avis.count > 0
redirect_to instructeur_avis_index_path redirect_to instructeur_all_avis_path
end end
end end

View file

@ -6,7 +6,7 @@ module DossierLinkHelper
else else
avis = dossier.avis.find_by(instructeur: user) avis = dossier.avis.find_by(instructeur: user)
if avis.present? if avis.present?
instructeur_avis_path(avis) instructeur_avis_path(avis.procedure, avis)
end end
end end
elsif user.owns_or_invite?(dossier) elsif user.owns_or_invite?(dossier)

View file

@ -1,6 +1,6 @@
module EtablissementHelper module EtablissementHelper
def pretty_currency(capital_social, unit: '€') def pretty_currency(capital_social, unit: '€')
number_to_currency(capital_social, locale: :fr, unit: unit) number_to_currency(capital_social, locale: :fr, unit: unit, precision: 0)
end end
def pretty_currency_unit(unit) def pretty_currency_unit(unit)

View file

@ -52,6 +52,10 @@ class Avis < ApplicationRecord
] ]
end end
def procedure
dossier.procedure
end
private private
def try_to_assign_instructeur def try_to_assign_instructeur

View file

@ -1,5 +1,5 @@
- content_for(:title, 'Invitation à donner votre avis') - content_for(:title, 'Invitation à donner votre avis')
- avis_link = @avis.instructeur.present? ? instructeur_avis_url(@avis) : sign_up_instructeur_avis_url(@avis.id, @avis.email) - avis_link = @avis.instructeur.present? ? instructeur_avis_url(@avis.procedure, @avis) : sign_up_instructeur_avis_url(@avis.procedure, @avis.id, @avis.email)
- content_for(:footer) do - content_for(:footer) do
Merci de ne pas répondre à cet email. Donnez votre avis Merci de ne pas répondre à cet email. Donnez votre avis
@ -15,7 +15,7 @@
Vous avez été invité par Vous avez été invité par
%strong= @avis.claimant.email %strong= @avis.claimant.email
= "à donner votre avis sur le dossier nº #{@avis.dossier.id} de la démarche :" = "à donner votre avis sur le dossier nº #{@avis.dossier.id} de la démarche :"
%strong= @avis.dossier.procedure.libelle %strong= @avis.procedure.libelle
%p %p
= "#{@avis.claimant.email} vous a écrit :" = "#{@avis.claimant.email} vous a écrit :"

View file

@ -8,11 +8,17 @@ def format_in_2_lines(pdf, label, text)
pdf.text "\n", size: 9 pdf.text "\n", size: 9
end end
def render_box(pdf, text, x, width)
box = ::Prawn::Text::Box.new(text, { document: pdf, width: width, overflow: :expand, at: [x, pdf.cursor] })
box.render
box.height
end
def format_in_2_columns(pdf, label, text) def format_in_2_columns(pdf, label, text)
pdf.text_box label, width: 200, height: 100, overflow: :expand, at: [0, pdf.cursor] h1 = render_box(pdf, label, 0, 100)
pdf.text_box ":", width: 10, height: 100, overflow: :expand, at: [100, pdf.cursor] h2 = render_box(pdf, ':', 100, 10)
pdf.text_box text, width: 420, height: 100, overflow: :expand, at: [110, pdf.cursor] h3 = render_box(pdf, text, 110, pdf.bounds.width - 110)
pdf.text "\n" pdf.move_down 5 + [h1,h2,h3].max
end end
def add_title(pdf, title) def add_title(pdf, title)
@ -47,33 +53,32 @@ def render_siret_info(pdf, etablissement)
end end
def render_identite_etablissement(pdf, etablissement) def render_identite_etablissement(pdf, etablissement)
pdf.text " - SIRET : #{etablissement.siret}" format_in_2_columns(pdf, "SIRET", etablissement.siret)
pdf.text " - SIRET du siège social: #{etablissement.entreprise.siret_siege_social}" format_in_2_columns(pdf, "SIRET du siège social", etablissement.entreprise.siret_siege_social) if etablissement.entreprise.siret_siege_social.present?
pdf.text " - Dénomination : #{raison_sociale_or_name(etablissement)}" format_in_2_columns(pdf, "Dénomination", raison_sociale_or_name(etablissement))
pdf.text " - Forme juridique : #{etablissement.entreprise_forme_juridique}" format_in_2_columns(pdf, "Forme juridique ", etablissement.entreprise_forme_juridique)
if etablissement.entreprise_capital_social.present? if etablissement.entreprise_capital_social.present?
pdf.text " - Capital social : #{pretty_currency(etablissement.entreprise_capital_social)}" format_in_2_columns(pdf, "Capital social ", pretty_currency(etablissement.entreprise_capital_social))
end end
pdf.text " - Libellé NAF : #{etablissement.libelle_naf}" format_in_2_columns(pdf, "Libellé NAF ", etablissement.libelle_naf)
pdf.text " - Code NAF : #{etablissement.naf}" format_in_2_columns(pdf, "Code NAF ", etablissement.naf)
pdf.text " - Date de création : #{try_format_date(etablissement.entreprise.date_creation)}" format_in_2_columns(pdf, "Date de création ", try_format_date(etablissement.entreprise.date_creation))
if @include_infos_administration if @include_infos_administration
pdf.text " - Effectif mensuel #{try_format_mois_effectif(etablissement)} (URSSAF) : #{etablissement.entreprise_effectif_mensuel}" format_in_2_columns(pdf, "Effectif mensuel #{try_format_mois_effectif(etablissement)} (URSSAF) ", etablissement.entreprise_effectif_mensuel)
pdf.text " - Effectif moyen annuel #{etablissement.entreprise_effectif_annuel_annee} (URSSAF) : #{etablissement.entreprise_effectif_annuel}" format_in_2_columns(pdf, "Effectif moyen annuel #{etablissement.entreprise_effectif_annuel_annee} (URSSAF) ", etablissement.entreprise_effectif_annuel)
end end
pdf.text " - Effectif de l'organisation (INSEE) : #{effectif(etablissement)}" format_in_2_columns(pdf, "Effectif (ISPF) ", effectif(etablissement))
pdf.text " - Code effectif : #{etablissement.entreprise.code_effectif_entreprise}" format_in_2_columns(pdf, "Code effectif ", etablissement.entreprise.code_effectif_entreprise)
pdf.text " - Numéro de TVA intracommunautaire : #{etablissement.entreprise.numero_tva_intracommunautaire}" format_in_2_columns(pdf, "Numéro de TVA intracommunautaire ", etablissement.entreprise.numero_tva_intracommunautaire) if etablissement.entreprise.numero_tva_intracommunautaire.present?
pdf.text " - Adresse : #{etablissement.adresse}" format_in_2_columns(pdf, "Adresse ", etablissement.adresse)
if etablissement.association? if etablissement.association?
pdf.text " - Numéro RNA : #{etablissement.association_rna}" format_in_2_columns(pdf, "Numéro RNA ", etablissement.association_rna)
pdf.text " - Titre : #{etablissement.association_titre}" format_in_2_columns(pdf, "Titre ", etablissement.association_titre)
pdf.text " - Objet : #{etablissement.association_objet}" format_in_2_columns(pdf, "Objet ", etablissement.association_objet)
pdf.text " - Date de création : #{try_format_date(etablissement.association_date_creation)}" format_in_2_columns(pdf, "Date de création ", try_format_date(etablissement.association_date_creation))
pdf.text " - Date de publication : #{try_format_date(etablissement.association_date_publication)}" format_in_2_columns(pdf, "Date de publication ", try_format_date(etablissement.association_date_publication))
pdf.text " - Date de déclaration : #{try_format_date(etablissement.association_date_declaration)}" format_in_2_columns(pdf, "Date de déclaration ", try_format_date(etablissement.association_date_declaration))
end end
pdf.text "\n"
end end
def render_single_champ(pdf, champ) def render_single_champ(pdf, champ)

View file

@ -1,10 +1,11 @@
.sub-header .sub-header
.container .container
%ul.breadcrumbs %ul.breadcrumbs
%li= link_to('Avis', instructeur_avis_index_path) %li= link_to('Avis', instructeur_all_avis_path)
%li= "#{dossier.procedure.libelle}, dossier nº #{dossier.id}" %li= link_to(dossier.procedure.libelle, procedure_instructeur_avis_index_path(avis.procedure))
%li= link_to("Dossier nº #{dossier.id}", instructeur_avis_path(avis.procedure, avis))
%ul.tabs %ul.tabs
= dynamic_tab_item('Demande', instructeur_avis_path(avis)) = dynamic_tab_item('Demande', instructeur_avis_path(avis.procedure, avis))
= dynamic_tab_item('Avis', instruction_instructeur_avis_path(avis), notification: avis.answer.blank?) = dynamic_tab_item('Avis', instruction_instructeur_avis_path(avis.procedure, avis), notification: avis.answer.blank?)
= dynamic_tab_item('Messagerie', messagerie_instructeur_avis_path(avis)) = dynamic_tab_item('Messagerie', messagerie_instructeur_avis_path(avis.procedure, avis))

View file

@ -1,39 +1,41 @@
- avis_statut = (@statut == Instructeurs::AvisController::A_DONNER_STATUS) ? 'à donner' : 'rendus' - content_for(:title, "Avis")
- content_for(:title, "Avis #{avis_statut}")
.sub-header
.container.flex
.width-100
%h1.tab-title Avis
%ul.tabs
= tab_item('avis à donner',
instructeur_avis_index_path(statut: Instructeurs::AvisController::A_DONNER_STATUS),
active: @statut == Instructeurs::AvisController::A_DONNER_STATUS,
badge: @avis_a_donner.count,
notification: @avis_a_donner.any?)
= tab_item("avis #{'donné'.pluralize(@avis_donnes.count)}",
instructeur_avis_index_path(statut: Instructeurs::AvisController::DONNES_STATUS),
active: @statut == Instructeurs::AvisController::DONNES_STATUS,
badge: @avis_donnes.count)
.container .container
- if @avis.present? %h1.page-title Avis
%table.table.dossiers-table.hoverable
%thead %ul.procedure-list
%tr - @avis_by_procedure.each do |p, procedure_avis|
%th.number-col Nº dossier %li.procedure-item.flex.align-start
%th Demandeur = link_to(procedure_instructeur_avis_index_path(p)) do
%th Démarche .flex
%tbody
- @avis.each do |avis| .procedure-logo{ style: "background-image: url(#{p.logo_url})" }
%tr
%td.number-col .procedure-details
= link_to(instructeur_avis_path(avis), class: 'cell-link') do %p.procedure-title
%span.icon.folder = procedure_libelle p
#{avis.dossier.id} %ul.procedure-stats.flex
%td= link_to(avis.dossier.user.email, instructeur_avis_path(avis), class: 'cell-link') %li
%td= link_to(avis.dossier.procedure.libelle, instructeur_avis_path(avis), class: 'cell-link') %object
= paginate(@avis) = link_to(procedure_instructeur_avis_index_path(p, statut: Instructeurs::AvisController::A_DONNER_STATUS)) do
- else - without_answer_count = procedure_avis.select { |a| a.answer.nil? }.size
%h2.empty-text Aucun avis - if without_answer_count > 0
%span.notifications{ 'aria-label': "notifications" }
.stats-number
= without_answer_count
.stats-legend
avis à donner
%li
%object
= link_to(procedure_instructeur_avis_index_path(p, statut: Instructeurs::AvisController::DONNES_STATUS)) do
- with_answer_count = procedure_avis.select { |a| a.answer.present? }.size
.stats-number= with_answer_count
.stats-legend
= pluralize(with_answer_count, "avis donné")
- if p.close?
.procedure-status
%span.label Close
- elsif p.depubliee?
.procedure-status
%span.label Dépubliée

View file

@ -15,7 +15,7 @@
= render partial: 'shared/attachment/show', locals: { attachment: @avis.introduction_file.attachment } = render partial: 'shared/attachment/show', locals: { attachment: @avis.introduction_file.attachment }
%br/ %br/
= form_for @avis, url: instructeur_avis_path(@avis), html: { class: 'form' } do |f| = form_for @avis, url: instructeur_avis_path(@avis.procedure, @avis), html: { class: 'form' } do |f|
= f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true = f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true
= render 'shared/attachment/edit', = render 'shared/attachment/edit',
{ form: f, { form: f,
@ -35,7 +35,7 @@
= f.submit 'Envoyer votre avis', class: 'button send' = f.submit 'Envoyer votre avis', class: 'button send'
- if !@dossier.termine? - if !@dossier.termine?
= render partial: "instructeurs/shared/avis/form", locals: { url: avis_instructeur_avis_path(@avis), linked_dossiers: @dossier.linked_dossiers_for(current_instructeur), must_be_confidentiel: @avis.confidentiel?, avis: @new_avis } = render partial: "instructeurs/shared/avis/form", locals: { url: avis_instructeur_avis_path(@avis.procedure, @avis), linked_dossiers: @dossier.linked_dossiers_for(current_instructeur), must_be_confidentiel: @avis.confidentiel?, avis: @new_avis }
- if @dossier.avis_for(current_instructeur).present? - if @dossier.avis_for(current_instructeur).present?
= render partial: 'instructeurs/shared/avis/list', locals: { avis: @dossier.avis_for(current_instructeur), avis_seen_at: nil } = render partial: 'instructeurs/shared/avis/list', locals: { avis: @dossier.avis_for(current_instructeur), avis_seen_at: nil }

View file

@ -0,0 +1,45 @@
- avis_statut = (@statut == Instructeurs::AvisController::A_DONNER_STATUS) ? 'à donner' : 'rendus'
- content_for(:title, "Avis #{avis_statut}")
#procedure-show
.sub-header
.container.flex
.procedure-logo{ style: "background-image: url(#{@procedure.logo_url})",
role: 'img', 'aria-label': "logo de la démarche #{@procedure.libelle}" }
.procedure-header
%h1= procedure_libelle @procedure
%ul.tabs
= tab_item('avis à donner',
procedure_instructeur_avis_index_path(statut: Instructeurs::AvisController::A_DONNER_STATUS),
active: @statut == Instructeurs::AvisController::A_DONNER_STATUS,
badge: @avis_a_donner.count,
notification: @avis_a_donner.any?)
= tab_item("avis #{'donné'.pluralize(@avis_donnes.count)}",
procedure_instructeur_avis_index_path(statut: Instructeurs::AvisController::DONNES_STATUS),
active: @statut == Instructeurs::AvisController::DONNES_STATUS,
badge: @avis_donnes.count)
.container
- if @avis.present?
%table.table.dossiers-table.hoverable
%thead
%tr
%th.number-col Nº dossier
%th Demandeur
%th Démarche
%tbody
- @avis.each do |avis|
%tr
%td.number-col
= link_to(instructeur_avis_path(avis.procedure, avis), class: 'cell-link') do
%span.icon.folder
#{avis.dossier.id}
%td= link_to(avis.dossier.user.email, instructeur_avis_path(avis.procedure, avis), class: 'cell-link')
%td= link_to(avis.procedure.libelle, instructeur_avis_path(avis.procedure, avis), class: 'cell-link')
= paginate(@avis)
- else
%h2.empty-text Aucun avis

View file

@ -29,10 +29,10 @@
%ul.header-tabs %ul.header-tabs
- if current_instructeur.procedures.count > 0 - if current_instructeur.procedures.count > 0
%li %li
= active_link_to "Démarches", instructeur_procedures_path, active: :inclusive, class: 'tab-link' = active_link_to "Démarches", instructeur_procedures_path, active: /^((?!avis).)*$/, class: 'tab-link'
- if current_instructeur.avis.count > 0 - if current_instructeur.avis.count > 0
%li %li
= active_link_to instructeur_avis_index_path, active: :inclusive, class: 'tab-link' do = active_link_to instructeur_all_avis_path, active: /avis/, class: 'tab-link' do
Avis Avis
- avis_counter = current_instructeur.avis.without_answer.count - avis_counter = current_instructeur.avis.without_answer.count
- if avis_counter > 0 - if avis_counter > 0

View file

@ -12,9 +12,9 @@
= link_to "beta.gouv.fr", "https://beta.gouv.fr", title: "le site de Beta.gouv.fr" = link_to "beta.gouv.fr", "https://beta.gouv.fr", title: "le site de Beta.gouv.fr"
%li %li
= link_to "https://numerique.gouv.fr/", title: "DINUM", 'aria-label': 'DINUM' do = link_to "https://numerique.gouv.fr/", title: "DINUM", 'aria-label': 'DINUM' do
%span.footer-logo.footer-logo-dinum{ role: 'img' } %span.footer-logo.footer-logo-dinum{ role: 'img', 'aria-label': 'Logo DINUM' }
= link_to "https://beta.gouv.fr", title: "le site de Beta.gouv.fr", 'aria-label': 'beta.gouv.fr' do = link_to "https://beta.gouv.fr", title: "le site de Beta.gouv.fr", 'aria-label': 'beta.gouv.fr' do
%span.footer-logo.footer-logo-beta-gouv-fr{ role: 'img' } %span.footer-logo.footer-logo-beta-gouv-fr{ role: 'img', 'aria-label': 'Logo beta.gouv.fr' }
%span.footer-logo.footer-logo-france{ role: 'img', 'aria-label': 'République Française' } %span.footer-logo.footer-logo-france{ role: 'img', 'aria-label': 'République Française' }
%li.footer-column %li.footer-column

View file

@ -300,6 +300,13 @@ Rails.application.routes.draw do
# #
scope module: 'instructeurs', as: 'instructeur' do scope module: 'instructeurs', as: 'instructeur' do
get 'avis', to: 'avis#index', as: 'all_avis'
# this redirections are ephemeral, to ensure that emails sent to experts before are still valid
# TODO : they will be removed in September, 2020
get 'avis/:id', to: redirect('/procedures/old/avis/%{id}')
get 'avis/:id/sign_up/email/:email', to: redirect("/procedures/old/avis/%{id}/sign_up/email/%{email}"), constraints: { email: /.*/ }
resources :procedures, only: [:index, :show], param: :procedure_id do resources :procedures, only: [:index, :show], param: :procedure_id do
member do member do
resources :groupes, only: [:index, :show], controller: 'groupe_instructeurs' do resources :groupes, only: [:index, :show], controller: 'groupe_instructeurs' do
@ -309,6 +316,20 @@ Rails.application.routes.draw do
end end
end end
resources :avis, only: [:show, :update] do
get '', action: 'procedure', on: :collection, as: :procedure
member do
get 'instruction'
get 'messagerie'
post 'commentaire' => 'avis#create_commentaire'
post 'avis' => 'avis#create_avis'
get 'bilans_bdf'
get 'sign_up/email/:email' => 'avis#sign_up', constraints: { email: /.*/ }, as: 'sign_up'
post 'sign_up/email/:email' => 'avis#create_instructeur', constraints: { email: /.*/ }
end
end
patch 'update_displayed_fields' patch 'update_displayed_fields'
get 'update_sort/:table/:column' => 'procedures#update_sort', as: 'update_sort' get 'update_sort/:table/:column' => 'procedures#update_sort', as: 'update_sort'
post 'add_filter' post 'add_filter'
@ -347,18 +368,6 @@ Rails.application.routes.draw do
end end
end end
end end
resources :avis, only: [:index, :show, :update] do
member do
get 'instruction'
get 'messagerie'
post 'commentaire' => 'avis#create_commentaire'
post 'avis' => 'avis#create_avis'
get 'bilans_bdf'
get 'sign_up/email/:email' => 'avis#sign_up', constraints: { email: /.*/ }, as: 'sign_up'
post 'sign_up/email/:email' => 'avis#create_instructeur', constraints: { email: /.*/ }
end
end
get "recherche" => "recherche#index" get "recherche" => "recherche#index"
end end

View file

@ -4,7 +4,8 @@ describe Instructeurs::AvisController, type: :controller do
let(:claimant) { create(:instructeur) } let(:claimant) { create(:instructeur) }
let(:instructeur) { create(:instructeur) } let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) } let(:procedure) { create(:procedure, :published, instructeurs: [claimant]) }
let(:another_procedure) { create(:procedure, :published, instructeurs: [claimant]) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let!(:avis_without_answer) { Avis.create(dossier: dossier, claimant: claimant, instructeur: instructeur) } let!(:avis_without_answer) { Avis.create(dossier: dossier, claimant: claimant, instructeur: instructeur) }
let!(:avis_with_answer) { Avis.create(dossier: dossier, claimant: claimant, instructeur: instructeur, answer: 'yop') } let!(:avis_with_answer) { Avis.create(dossier: dossier, claimant: claimant, instructeur: instructeur, answer: 'yop') }
@ -14,20 +15,28 @@ describe Instructeurs::AvisController, type: :controller do
describe '#index' do describe '#index' do
before { get :index } before { get :index }
it { expect(response).to have_http_status(:success) }
it { expect(assigns(:avis_by_procedure).flatten).to include(procedure) }
it { expect(assigns(:avis_by_procedure).flatten).not_to include(another_procedure) }
end
describe '#procedure' do
before { get :procedure, params: { procedure_id: procedure.id } }
it { expect(response).to have_http_status(:success) } it { expect(response).to have_http_status(:success) }
it { expect(assigns(:avis_a_donner)).to match([avis_without_answer]) } it { expect(assigns(:avis_a_donner)).to match([avis_without_answer]) }
it { expect(assigns(:avis_donnes)).to match([avis_with_answer]) } it { expect(assigns(:avis_donnes)).to match([avis_with_answer]) }
it { expect(assigns(:statut)).to eq('a-donner') } it { expect(assigns(:statut)).to eq('a-donner') }
context 'with a statut equal to donnes' do context 'with a statut equal to donnes' do
before { get :index, params: { statut: 'donnes' } } before { get :procedure, params: { statut: 'donnes', procedure_id: procedure.id } }
it { expect(assigns(:statut)).to eq('donnes') } it { expect(assigns(:statut)).to eq('donnes') }
end end
end end
describe '#show' do describe '#show' do
before { get :show, params: { id: avis_without_answer.id } } before { get :show, params: { id: avis_without_answer.id, procedure_id: procedure.id } }
it { expect(response).to have_http_status(:success) } it { expect(response).to have_http_status(:success) }
it { expect(assigns(:avis)).to eq(avis_without_answer) } it { expect(assigns(:avis)).to eq(avis_without_answer) }
@ -35,7 +44,7 @@ describe Instructeurs::AvisController, type: :controller do
end end
describe '#instruction' do describe '#instruction' do
before { get :instruction, params: { id: avis_without_answer.id } } before { get :instruction, params: { id: avis_without_answer.id, procedure_id: procedure.id } }
it { expect(response).to have_http_status(:success) } it { expect(response).to have_http_status(:success) }
it { expect(assigns(:avis)).to eq(avis_without_answer) } it { expect(assigns(:avis)).to eq(avis_without_answer) }
@ -43,7 +52,7 @@ describe Instructeurs::AvisController, type: :controller do
end end
describe '#messagerie' do describe '#messagerie' do
before { get :messagerie, params: { id: avis_without_answer.id } } before { get :messagerie, params: { id: avis_without_answer.id, procedure_id: procedure.id } }
it { expect(response).to have_http_status(:success) } it { expect(response).to have_http_status(:success) }
it { expect(assigns(:avis)).to eq(avis_without_answer) } it { expect(assigns(:avis)).to eq(avis_without_answer) }
@ -51,7 +60,7 @@ describe Instructeurs::AvisController, type: :controller do
end end
describe '#bilans_bdf' do describe '#bilans_bdf' do
before { get :bilans_bdf, params: { id: avis_without_answer.id } } before { get :bilans_bdf, params: { id: avis_without_answer.id, procedure_id: procedure.id } }
it { expect(response).to redirect_to(instructeur_avis_path(avis_without_answer)) } it { expect(response).to redirect_to(instructeur_avis_path(avis_without_answer)) }
end end
@ -59,12 +68,12 @@ describe Instructeurs::AvisController, type: :controller do
describe '#update' do describe '#update' do
describe 'without attachment' do describe 'without attachment' do
before do before do
patch :update, params: { id: avis_without_answer.id, avis: { answer: 'answer' } } patch :update, params: { id: avis_without_answer.id, procedure_id: procedure.id, avis: { answer: 'answer' } }
avis_without_answer.reload avis_without_answer.reload
end end
it 'should be ok' do it 'should be ok' do
expect(response).to redirect_to(instruction_instructeur_avis_path(avis_without_answer)) expect(response).to redirect_to(instruction_instructeur_avis_path(avis_without_answer.procedure, avis_without_answer))
expect(avis_without_answer.answer).to eq('answer') expect(avis_without_answer.answer).to eq('answer')
expect(avis_without_answer.piece_justificative_file).to_not be_attached expect(avis_without_answer.piece_justificative_file).to_not be_attached
expect(flash.notice).to eq('Votre réponse est enregistrée.') expect(flash.notice).to eq('Votre réponse est enregistrée.')
@ -78,13 +87,13 @@ describe Instructeurs::AvisController, type: :controller do
before do before do
expect(ClamavService).to receive(:safe_file?).and_return(true) expect(ClamavService).to receive(:safe_file?).and_return(true)
perform_enqueued_jobs do perform_enqueued_jobs do
post :update, params: { id: avis_without_answer.id, avis: { answer: 'answer', piece_justificative_file: file } } post :update, params: { id: avis_without_answer.id, procedure_id: procedure.id, avis: { answer: 'answer', piece_justificative_file: file } }
end end
avis_without_answer.reload avis_without_answer.reload
end end
it 'should be ok' do it 'should be ok' do
expect(response).to redirect_to(instruction_instructeur_avis_path(avis_without_answer)) expect(response).to redirect_to(instruction_instructeur_avis_path(avis_without_answer.procedure, avis_without_answer))
expect(avis_without_answer.answer).to eq('answer') expect(avis_without_answer.answer).to eq('answer')
expect(avis_without_answer.piece_justificative_file).to be_attached expect(avis_without_answer.piece_justificative_file).to be_attached
expect(flash.notice).to eq('Votre réponse est enregistrée.') expect(flash.notice).to eq('Votre réponse est enregistrée.')
@ -96,7 +105,7 @@ describe Instructeurs::AvisController, type: :controller do
let(:file) { nil } let(:file) { nil }
let(:scan_result) { true } let(:scan_result) { true }
subject { post :create_commentaire, params: { id: avis_without_answer.id, commentaire: { body: 'commentaire body', piece_jointe: file } } } subject { post :create_commentaire, params: { id: avis_without_answer.id, procedure_id: procedure.id, commentaire: { body: 'commentaire body', piece_jointe: file } } }
before do before do
allow(ClamavService).to receive(:safe_file?).and_return(scan_result) allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
@ -105,7 +114,7 @@ describe Instructeurs::AvisController, type: :controller do
it do it do
subject subject
expect(response).to redirect_to(messagerie_instructeur_avis_path(avis_without_answer)) expect(response).to redirect_to(messagerie_instructeur_avis_path(avis_without_answer.procedure, avis_without_answer))
expect(dossier.commentaires.map(&:body)).to match(['commentaire body']) expect(dossier.commentaires.map(&:body)).to match(['commentaire body'])
end end
@ -131,7 +140,7 @@ describe Instructeurs::AvisController, type: :controller do
before do before do
@introduction_file = Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') @introduction_file = Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf')
post :create_avis, params: { id: previous_avis.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers, introduction_file: @introduction_file } } post :create_avis, params: { id: previous_avis.id, procedure_id: procedure.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers, introduction_file: @introduction_file } }
created_avis.reload created_avis.reload
end end
@ -178,7 +187,7 @@ describe Instructeurs::AvisController, type: :controller do
it { expect(created_avis.introduction).to eq(intro) } it { expect(created_avis.introduction).to eq(intro) }
it { expect(created_avis.dossier).to eq(previous_avis.dossier) } it { expect(created_avis.dossier).to eq(previous_avis.dossier) }
it { expect(created_avis.claimant).to eq(instructeur) } it { expect(created_avis.claimant).to eq(instructeur) }
it { expect(response).to redirect_to(instruction_instructeur_avis_path(previous_avis)) } it { expect(response).to redirect_to(instruction_instructeur_avis_path(previous_avis.procedure, previous_avis)) }
end end
context 'when the user asked for a confidentiel avis' do context 'when the user asked for a confidentiel avis' do
@ -255,6 +264,7 @@ describe Instructeurs::AvisController, type: :controller do
describe '#sign_up' do describe '#sign_up' do
let(:invited_email) { 'invited@avis.com' } let(:invited_email) { 'invited@avis.com' }
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier) }
let(:procedure) { dossier.procedure }
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) } let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
let(:invitations_email) { true } let(:invitations_email) { true }
@ -263,7 +273,7 @@ describe Instructeurs::AvisController, type: :controller do
expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?) expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?)
.with(avis.id.to_s, invited_email) .with(avis.id.to_s, invited_email)
.and_return(invitations_email) .and_return(invitations_email)
get :sign_up, params: { id: avis.id, email: invited_email } get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email }
end end
context 'when the email belongs to the invitation' do context 'when the email belongs to the invitation' do
@ -286,15 +296,15 @@ describe Instructeurs::AvisController, type: :controller do
context 'when the instructeur is authenticated' do context 'when the instructeur is authenticated' do
before do before do
sign_in(instructeur.user) sign_in(instructeur.user)
get :sign_up, params: { id: avis.id, email: invited_email } get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email }
end end
it { is_expected.to redirect_to instructeur_avis_url(avis) } it { is_expected.to redirect_to instructeur_avis_url(avis.procedure, avis) }
end end
context 'when the instructeur is not authenticated' do context 'when the instructeur is not authenticated' do
before do before do
get :sign_up, params: { id: avis.id, email: invited_email } get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email }
end end
it { is_expected.to redirect_to new_user_session_url } it { is_expected.to redirect_to new_user_session_url }
@ -307,11 +317,11 @@ describe Instructeurs::AvisController, type: :controller do
before do before do
sign_in(instructeur.user) sign_in(instructeur.user)
get :sign_up, params: { id: avis.id, email: invited_email } get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email }
end end
# redirected to dossier but then the instructeur gonna be banished ! # redirected to dossier but then the instructeur gonna be banished !
it { is_expected.to redirect_to instructeur_avis_url(avis) } it { is_expected.to redirect_to instructeur_avis_url(avis.procedure, avis) }
end end
end end
@ -320,6 +330,7 @@ describe Instructeurs::AvisController, type: :controller do
let!(:existing_user) { create(:user, email: existing_user_mail) } let!(:existing_user) { create(:user, email: existing_user_mail) }
let(:invited_email) { 'invited@avis.com' } let(:invited_email) { 'invited@avis.com' }
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier) }
let(:procedure) { dossier.procedure }
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) } let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
let(:avis_id) { avis.id } let(:avis_id) { avis.id }
let(:password) { 'démarches-simplifiées-pwd' } let(:password) { 'démarches-simplifiées-pwd' }
@ -334,6 +345,7 @@ describe Instructeurs::AvisController, type: :controller do
post :create_instructeur, params: { post :create_instructeur, params: {
id: avis_id, id: avis_id,
procedure_id: procedure.id,
email: invited_email, email: invited_email,
user: { user: {
password: password password: password
@ -355,7 +367,7 @@ describe Instructeurs::AvisController, type: :controller do
it { expect(Avis).to have_received(:link_avis_to_instructeur) } it { expect(Avis).to have_received(:link_avis_to_instructeur) }
it { expect(subject.current_instructeur).to eq(created_instructeur) } it { expect(subject.current_instructeur).to eq(created_instructeur) }
it { is_expected.to redirect_to instructeur_avis_index_path } it { is_expected.to redirect_to instructeur_all_avis_path }
it 'creates a corresponding user account for the email' do it 'creates a corresponding user account for the email' do
user = User.find_by(email: invited_email) user = User.find_by(email: invited_email)
@ -375,7 +387,7 @@ describe Instructeurs::AvisController, type: :controller do
let(:password) { '' } let(:password) { '' }
it { expect(created_instructeur).to be_nil } it { expect(created_instructeur).to be_nil }
it { is_expected.to redirect_to sign_up_instructeur_avis_path(avis_id, invited_email) } it { is_expected.to redirect_to sign_up_instructeur_avis_path(procedure.id, avis_id, invited_email) }
it { expect(flash.alert).to eq(['Le mot de passe doit être rempli']) } it { expect(flash.alert).to eq(['Le mot de passe doit être rempli']) }
end end
end end

View file

@ -76,7 +76,7 @@ describe Instructeurs::ProceduresController, type: :controller do
end end
it "redirects avis" do it "redirects avis" do
expect(@controller).to have_received(:redirect_to).with(instructeur_avis_index_path) expect(@controller).to have_received(:redirect_to).with(instructeur_all_avis_path)
end end
end end
end end

View file

@ -6,12 +6,12 @@ feature 'wcag rules for usager', js: true do
context 'pages without the need to be logged in' do context 'pages without the need to be logged in' do
scenario 'homepage' do scenario 'homepage' do
visit root_path visit root_path
expect(page).to be_accessible.excluding ".footer-logo" expect(page).to be_accessible
end end
scenario 'sign_up page' do scenario 'sign_up page' do
visit new_user_registration_path visit new_user_registration_path
expect(page).to be_accessible.excluding ".footer-logo" expect(page).to be_accessible
end end
scenario 'account confirmation page' do scenario 'account confirmation page' do
@ -28,12 +28,12 @@ feature 'wcag rules for usager', js: true do
scenario 'sign_in page' do scenario 'sign_in page' do
visit new_user_session_path visit new_user_session_path
expect(page).to be_accessible.excluding ".footer-logo", '#user_email' expect(page).to be_accessible.excluding '#user_email'
end end
scenario 'contact page' do scenario 'contact page' do
visit contact_path visit contact_path
expect(page).to be_accessible.excluding ".footer-logo" expect(page).to be_accessible
end end
scenario 'commencer page' do scenario 'commencer page' do

View file

@ -42,7 +42,7 @@ feature 'Inviting an expert:' do
invitation_email = open_email('expert2@exemple.fr') invitation_email = open_email('expert2@exemple.fr')
avis = Avis.find_by(email: 'expert2@exemple.fr', dossier: dossier) avis = Avis.find_by(email: 'expert2@exemple.fr', dossier: dossier)
sign_up_link = sign_up_instructeur_avis_path(avis.id, avis.email) sign_up_link = sign_up_instructeur_avis_path(avis.dossier.procedure, avis, avis.email)
expect(invitation_email.body).to include(sign_up_link) expect(invitation_email.body).to include(sign_up_link)
end end
@ -71,14 +71,14 @@ feature 'Inviting an expert:' do
let(:avis_email) { 'not-signed-up-expert@exemple.fr' } let(:avis_email) { 'not-signed-up-expert@exemple.fr' }
scenario 'I can sign up' do scenario 'I can sign up' do
visit sign_up_instructeur_avis_path(avis.id, avis_email) visit sign_up_instructeur_avis_path(avis.dossier.procedure, avis, avis_email)
expect(page).to have_field('Email', with: avis_email, disabled: true) expect(page).to have_field('Email', with: avis_email, disabled: true)
fill_in 'Mot de passe', with: 'This is a very complicated password !' fill_in 'Mot de passe', with: 'This is a very complicated password !'
click_on 'Créer un compte' click_on 'Créer un compte'
expect(page).to have_current_path(instructeur_avis_index_path) expect(page).to have_current_path(instructeur_all_avis_path)
expect(page).to have_text('avis à donner 1') expect(page).to have_text('1 avis à donner')
end end
end end
@ -86,13 +86,13 @@ feature 'Inviting an expert:' do
let(:avis_email) { expert.email } let(:avis_email) { expert.email }
scenario 'I can sign in' do scenario 'I can sign in' do
visit sign_up_instructeur_avis_path(avis.id, avis_email) visit sign_up_instructeur_avis_path(avis.dossier.procedure, avis, avis_email)
expect(page).to have_current_path(new_user_session_path) expect(page).to have_current_path(new_user_session_path)
sign_in_with(expert.email, expert_password) sign_in_with(expert.email, expert_password)
expect(page).to have_current_path(instructeur_avis_index_path) expect(page).to have_current_path(instructeur_all_avis_path)
expect(page).to have_text('avis à donner 1') expect(page).to have_text('1 avis à donner')
end end
end end
@ -100,10 +100,11 @@ feature 'Inviting an expert:' do
avis # create avis avis # create avis
login_as expert.user, scope: :user login_as expert.user, scope: :user
visit instructeur_avis_index_path visit instructeur_all_avis_path
expect(page).to have_text('avis à donner 1') expect(page).to have_text('1 avis à donner')
expect(page).to have_text('avis donnés 0') expect(page).to have_text('0 avis donnés')
click_on '1 avis à donner'
click_on avis.dossier.user.email click_on avis.dossier.user.email
within('.tabs') { click_on 'Avis' } within('.tabs') { click_on 'Avis' }
@ -119,8 +120,8 @@ feature 'Inviting an expert:' do
expect(page).to have_content('RIB.pdf') expect(page).to have_content('RIB.pdf')
within('.new-header') { click_on 'Avis' } within('.new-header') { click_on 'Avis' }
expect(page).to have_text('avis à donner 0') expect(page).to have_text('0 avis à donner')
expect(page).to have_text('avis donné 1') expect(page).to have_text('1 avis donné')
end end
# TODO # TODO

View file

@ -159,12 +159,6 @@ feature 'Instructing a dossier:' do
click_on 'Demander un avis' click_on 'Demander un avis'
end end
def test_mail(to, content)
mail = ActionMailer::Base.deliveries.last
expect(mail.to).to match([to])
expect(mail.body.parts.map(&:to_s)).to all(include(content))
end
def test_statut_bar(a_suivre: 0, suivi: 0, traite: 0, tous_les_dossiers: 0, archive: 0) def test_statut_bar(a_suivre: 0, suivi: 0, traite: 0, tous_les_dossiers: 0, archive: 0)
texts = [ texts = [
"à suivre #{a_suivre}", "à suivre #{a_suivre}",
@ -177,13 +171,6 @@ feature 'Instructing a dossier:' do
texts.each { |text| expect(page).to have_text(text) } texts.each { |text| expect(page).to have_text(text) }
end end
def avis_sign_up(avis, email)
visit sign_up_instructeur_avis_path(avis, email)
fill_in 'user_password', with: 'démarches-simplifiées-pwd'
click_on 'Créer un compte'
expect(page).to have_current_path(instructeur_avis_index_path)
end
def dossier_present?(id, statut) def dossier_present?(id, statut)
within(:css, '.dossiers-table') do within(:css, '.dossiers-table') do
expect(page).to have_text(id) expect(page).to have_text(id)

View file

@ -29,7 +29,7 @@ describe DossierLinkHelper do
let(:instructeur) { create(:instructeur) } let(:instructeur) { create(:instructeur) }
let!(:avis) { create(:avis, dossier: dossier, instructeur: instructeur) } let!(:avis) { create(:avis, dossier: dossier, instructeur: instructeur) }
it { expect(helper.dossier_linked_path(instructeur, dossier)).to eq(instructeur_avis_path(avis)) } it { expect(helper.dossier_linked_path(instructeur, dossier)).to eq(instructeur_avis_path(avis.dossier.procedure, avis)) }
end end
context "when access as user" do context "when access as user" do

View file

@ -49,13 +49,13 @@ RSpec.describe EtablissementHelper, type: :helper do
describe '#pretty_currency' do describe '#pretty_currency' do
subject { pretty_currency(etablissement.entreprise_capital_social) } subject { pretty_currency(etablissement.entreprise_capital_social) }
it { is_expected.to eq('123 000,00 €') } it { is_expected.to eq('123 000 €') }
end end
describe '#pretty_currency with special unit' do describe '#pretty_currency with special unit' do
subject { pretty_currency(12345, unit: 'k€') } subject { pretty_currency(12345, unit: 'k€') }
it { is_expected.to eq('12 345,00 k€') } it { is_expected.to eq('12 345 k€') }
end end
describe '#pretty_date_exercice' do describe '#pretty_date_exercice' do
subject { pretty_date_exercice("201908") } subject { pretty_date_exercice("201908") }

View file

@ -7,7 +7,7 @@ RSpec.describe AvisMailer, type: :mailer do
it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") } it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") }
it { expect(subject.body).to have_text("Vous avez été invité par\r\n#{avis.claimant.email}\r\nà donner votre avis sur le dossier nº #{avis.dossier.id} de la démarche :\r\n#{avis.dossier.procedure.libelle}") } it { expect(subject.body).to have_text("Vous avez été invité par\r\n#{avis.claimant.email}\r\nà donner votre avis sur le dossier nº #{avis.dossier.id} de la démarche :\r\n#{avis.dossier.procedure.libelle}") }
it { expect(subject.body).to include(avis.introduction) } it { expect(subject.body).to include(avis.introduction) }
it { expect(subject.body).to include(instructeur_avis_url(avis)) } it { expect(subject.body).to include(instructeur_avis_url(avis.dossier.procedure.id, avis)) }
context 'when the recipient is not already registered' do context 'when the recipient is not already registered' do
before do before do
@ -15,7 +15,7 @@ RSpec.describe AvisMailer, type: :mailer do
avis.instructeur = nil avis.instructeur = nil
end end
it { expect(subject.body).to include(sign_up_instructeur_avis_url(avis.id, avis.email)) } it { expect(subject.body).to include(sign_up_instructeur_avis_url(avis.dossier.procedure.id, avis.id, avis.email)) }
end end
end end
end end