Merge pull request #6648 from betagouv/main

2021-11-17-01
This commit is contained in:
LeSim 2021-11-17 09:50:26 +01:00 committed by GitHub
commit 8fb6e32132
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 3641 additions and 1639 deletions

View file

@ -2,14 +2,24 @@ class Champs::PieceJustificativeController < ApplicationController
before_action :authenticate_logged_user!
def update
@champ = policy_scope(Champ).find(params[:champ_id])
@champ.piece_justificative_file.attach(params[:blob_signed_id])
if @champ.save
if attach_piece_justificative_or_retry
render :show
else
errors = @champ.errors.full_messages
render :json => { errors: errors }, :status => 422
render json: { errors: @champ.errors.full_messages }, status: 422
end
end
private
def attach_piece_justificative
@champ = policy_scope(Champ).find(params[:champ_id])
@champ.piece_justificative_file.attach(params[:blob_signed_id])
@champ.save
end
def attach_piece_justificative_or_retry
attach_piece_justificative
rescue ActiveRecord::StaleObjectError
attach_piece_justificative
end
end

View file

@ -0,0 +1,21 @@
# frozen_string_literal: true
module Instructeurs
class CommentairesController < ProceduresController
def destroy
commentaire = Dossier.find(params[:dossier_id]).commentaires.find(params[:id])
if commentaire.sent_by?(current_instructeur)
commentaire.piece_jointe.purge_later if commentaire.piece_jointe.attached?
commentaire.discard!
commentaire.update!(body: '')
flash[:notice] = t('views.shared.commentaires.destroy.notice')
else
flash[:alert] = I18n.t('views.shared.commentaires.destroy.alert_reasons.acl')
end
redirect_to(messagerie_instructeur_dossier_path(params[:procedure_id], params[:dossier_id]))
rescue Discard::RecordNotDiscarded
flash[:alert] = I18n.t('views.shared.commentaires.destroy.alert_reasons.already_discarded')
redirect_to(messagerie_instructeur_dossier_path(params[:procedure_id], params[:dossier_id]))
end
end
end

View file

@ -190,10 +190,10 @@ module NewAdministrateur
end
def update_routing_enabled
procedure.update!(routing_enabled: true)
procedure.update!(routing_enabled_params)
redirect_to admin_procedure_groupe_instructeurs_path(procedure),
notice: "Le routage est activé."
notice: "Le routage est #{procedure.routing_enabled? ? "activée" : "désactivée"}."
end
def update_instructeurs_self_management_enabled
@ -326,5 +326,9 @@ module NewAdministrateur
def instructeurs_self_management_enabled_params
params.require(:procedure).permit(:instructeurs_self_management_enabled)
end
def routing_enabled_params
{ routing_enabled: params.require(:routing) == 'enable' }
end
end
end

View file

@ -251,11 +251,11 @@ module NewAdministrateur
end
def procedure_params
editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :cadre_juridique, :deliberation, :notice, :web_hook_url, :declarative_with_state, :euro_flag, :logo, :auto_archive_on, :monavis_embed, :api_entreprise_token]
editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :cadre_juridique, :deliberation, :notice, :web_hook_url, :declarative_with_state, :logo, :auto_archive_on, :monavis_embed, :api_entreprise_token, :duree_conservation_dossiers_dans_ds]
permited_params = if @procedure&.locked?
params.require(:procedure).permit(*editable_params)
else
params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :for_individual, :path)
params.require(:procedure).permit(*editable_params, :for_individual, :path)
end
if permited_params[:auto_archive_on].present?
permited_params[:auto_archive_on] = Date.parse(permited_params[:auto_archive_on]) + 1.day

View file

@ -1,10 +1,9 @@
module Users
class ProfilController < UserController
before_action :ensure_update_email_is_authorized, only: :update_email
before_action :find_transfers, only: [:show, :renew_api_token]
def show
@waiting_merge_emails = waiting_merge_emails
@waiting_transfers = current_user.dossiers.joins(:transfer).group('dossier_transfers.email').count.to_a
end
def renew_api_token
@ -56,6 +55,11 @@ module Users
private
def find_transfers
@waiting_merge_emails = waiting_merge_emails
@waiting_transfers = current_user.dossiers.joins(:transfer).group('dossier_transfers.email').count.to_a
end
def waiting_merge_emails
users_requesting_merge.pluck(:email)
end

View file

@ -24,6 +24,7 @@ module CommentaireHelper
end
def pretty_commentaire(commentaire)
return t('views.shared.commentaires.destroy.deleted_body') if commentaire.discarded?
body_formatted = commentaire.sent_by_system? ? commentaire.body : simple_format(commentaire.body)
sanitize(body_formatted)
end

View file

@ -1,6 +1,6 @@
module ConservationDeDonneesHelper
def politiques_conservation_de_donnees(procedure)
[conservation_dans_ds(procedure), conservation_hors_ds(procedure)].compact
[conservation_dans_ds(procedure)].compact
end
private
@ -10,10 +10,4 @@ module ConservationDeDonneesHelper
"Dans #{APPLICATION_NAME} : #{procedure.duree_conservation_dossiers_dans_ds} mois"
end
end
def conservation_hors_ds(procedure)
if procedure.duree_conservation_dossiers_hors_ds.present?
"Par ladministration : #{procedure.duree_conservation_dossiers_hors_ds} mois"
end
end
end

View file

@ -6,6 +6,7 @@ class DossierMailer < ApplicationMailer
layout 'mailers/layout'
default from: NO_REPLY_EMAIL
after_action :prevent_perform_deliveries, only: [:notify_new_answer]
def notify_new_draft(dossier)
I18n.with_locale(dossier.user_locale) do
@ -20,12 +21,14 @@ class DossierMailer < ApplicationMailer
end
end
def notify_new_answer(dossier, body = nil)
def notify_new_answer
commentaire = params[:commentaire]
dossier = commentaire.dossier
I18n.with_locale(dossier.user_locale) do
@dossier = dossier
@service = dossier.procedure.service
@logo_url = attach_logo(dossier.procedure)
@body = body
@body = commentaire.body
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
mail(to: dossier.user_email_for(:notification), subject: @subject) do |format|
@ -168,6 +171,10 @@ class DossierMailer < ApplicationMailer
protected
def prevent_perform_deliveries
mail.perform_deliveries = false if params[:commentaire].discarded?
end
# This is an override of `default_i18n_subject` method
# https://api.rubyonrails.org/v5.0.0/classes/ActionMailer/Base.html#method-i-default_i18n_subject
#

View file

@ -4,6 +4,7 @@
#
# id :integer not null, primary key
# body :string
# discarded_at :datetime
# email :string
# created_at :datetime not null
# updated_at :datetime not null
@ -13,6 +14,7 @@
#
class Commentaire < ApplicationRecord
include FileValidationConcern
include Discard::Model
self.ignored_columns = [:user_id]
belongs_to :dossier, inverse_of: :commentaires, touch: true, optional: false
@ -24,7 +26,7 @@ class Commentaire < ApplicationRecord
has_one_attached :piece_jointe
validates :body, presence: { message: "ne peut être vide" }
validates :body, presence: { message: "ne peut être vide" }, unless: :discarded?
FILE_MAX_SIZE = 20.megabytes
validates :piece_jointe,
@ -75,7 +77,11 @@ class Commentaire < ApplicationRecord
end
def sent_by?(someone)
email == someone.email
someone.present? && email == someone&.email
end
def soft_deletable?(connected_user)
sent_by?(connected_user) && sent_by_instructeur? && !discarded?
end
def file_url
@ -92,13 +98,15 @@ class Commentaire < ApplicationRecord
# - If a user or an invited user posted a commentaire, do nothing,
# the notification system will properly
# - Otherwise, a instructeur posted a commentaire, we need to notify the user
if sent_by_instructeur? || sent_by_expert?
if sent_by_instructeur?
notify_user(wait: 5.minutes)
elsif sent_by_expert?
notify_user
end
end
def notify_user
DossierMailer.notify_new_answer(dossier, body).deliver_later
def notify_user(job_options = {})
DossierMailer.with(commentaire: self).notify_new_answer.deliver_later(job_options)
end
def messagerie_available?

View file

@ -83,14 +83,16 @@ class Dossier < ApplicationRecord
has_many :avis, inverse_of: :dossier, dependent: :destroy
has_many :experts, through: :avis
has_many :traitements, -> { order(:processed_at) }, inverse_of: :dossier, dependent: :destroy do
def passer_en_construction(processed_at: Time.zone.now)
def passer_en_construction(instructeur: nil, processed_at: Time.zone.now)
build(state: Dossier.states.fetch(:en_construction),
instructeur_email: instructeur&.email,
process_expired: false,
processed_at: processed_at)
end
def passer_en_instruction(processed_at: Time.zone.now)
def passer_en_instruction(instructeur: nil, processed_at: Time.zone.now)
build(state: Dossier.states.fetch(:en_instruction),
instructeur_email: instructeur&.email,
process_expired: false,
processed_at: processed_at)
end
@ -735,7 +737,7 @@ class Dossier < ApplicationRecord
self.en_construction_close_to_expiration_notice_sent_at = nil
self.conservation_extension = 0.days
self.en_instruction_at = self.traitements
.passer_en_instruction
.passer_en_instruction(instructeur: instructeur)
.processed_at
save!
@ -759,7 +761,7 @@ class Dossier < ApplicationRecord
self.en_construction_close_to_expiration_notice_sent_at = nil
self.conservation_extension = 0.days
self.en_construction_at = self.traitements
.passer_en_construction
.passer_en_construction(instructeur: instructeur)
.processed_at
save!
log_dossier_operation(instructeur, :repasser_en_construction)
@ -770,7 +772,7 @@ class Dossier < ApplicationRecord
self.termine_close_to_expiration_notice_sent_at = nil
self.conservation_extension = 0.days
self.en_instruction_at = self.traitements
.passer_en_instruction
.passer_en_instruction(instructeur: instructeur)
.processed_at
attestation&.destroy

View file

@ -51,6 +51,7 @@
#
class Procedure < ApplicationRecord
self.ignored_columns = [:duree_conservation_dossiers_hors_ds]
include ProcedureStatsConcern
include EncryptableConcern
include FileValidationConcern
@ -238,7 +239,6 @@ class Procedure < ApplicationRecord
validate :check_juridique
validates :path, presence: true, format: { with: /\A[a-z0-9_\-]{3,200}\z/ }, uniqueness: { scope: [:path, :closed_at, :hidden_at, :unpublished_at], case_sensitive: false }
validates :duree_conservation_dossiers_dans_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: MAX_DUREE_CONSERVATION }
validates :duree_conservation_dossiers_hors_ds, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates_with MonAvisEmbedValidator
FILE_MAX_SIZE = 20.megabytes

View file

@ -201,7 +201,7 @@ class User < ApplicationRecord
def merge(old_user)
transaction do
old_user.dossiers.update_all(user_id: id)
old_user.dossiers.with_discarded.update_all(user_id: id)
old_user.invites.update_all(user_id: id)
old_user.merge_logs.update_all(user_id: id)

View file

@ -2,18 +2,12 @@
- if traitements.any?
%ul.tab-list
- traitements.each do |traitement|
- if traitement.instructeur_email.present?
%li
= "Le #{l(traitement.processed_at, format: '%d %B %Y à %R')}, "
= traitement.instructeur_email
a
%strong= t(traitement.state, scope: 'activerecord.attributes.traitement.state').downcase
ce dossier
- else
%li
= "Le #{l(traitement.processed_at, format: '%d %B %Y à %R')}, "
ce dossier a été
%strong= t(traitement.state, scope: 'activerecord.attributes.traitement.state').downcase
%li
- processed_at = l(traitement.processed_at, format: '%d %B %Y à %R')
- if traitement.instructeur_email.present?
= t(".with_email.#{traitement.state}", processed_at: processed_at, email: traitement.instructeur_email)
- else
= t(".without_email.#{traitement.state}", processed_at: processed_at)
- else
%p.tab-paragraph Aucune décision na été rendue

View file

@ -1,18 +1,23 @@
.card
.card-title Routage
%p.notice= t('.notice_html')
- if !procedure.routee?
%p.notice= t('.notice_html')
= link_to t('.button.routing_enable'), update_routing_enabled_admin_procedure_groupe_instructeurs_path(procedure), class: 'button primary mt-1', method: 'patch'
- if procedure.routee?
- if procedure.routing_enabled? && procedure.groupe_instructeurs.size == 1
= link_to t('.button.routing_disable'), update_routing_enabled_admin_procedure_groupe_instructeurs_path(procedure, routing: :disable), class: 'button primary mt-1', method: 'patch'
- else
= link_to t('.button.routing_enable'), update_routing_enabled_admin_procedure_groupe_instructeurs_path(procedure, routing: :enable), class: 'button primary mt-1', method: 'patch'
.card-title.mt-4 Lautogestion des instructeurs
%p.notice= t('.self_managment_notice_html')
.card-title.mt-4 Lautogestion des instructeurs
%p.notice= t('.self_managment_notice_html')
= form_for procedure,
method: :patch,
url: update_instructeurs_self_management_enabled_admin_procedure_groupe_instructeurs_path(procedure),
html: { class: 'form procedure-form__column--form no-background' } do |f|
%label.toggle-switch
= f.check_box :instructeurs_self_management_enabled, class: 'toggle-switch-checkbox', onchange: 'this.form.submit()'
%span.toggle-switch-control.round
%span.toggle-switch-label.on
%span.toggle-switch-label.off
= form_for procedure,
method: :patch,
url: update_instructeurs_self_management_enabled_admin_procedure_groupe_instructeurs_path(procedure),
html: { class: 'form procedure-form__column--form no-background' } do |f|
%label.toggle-switch
= f.check_box :instructeurs_self_management_enabled, class: 'toggle-switch-checkbox', onchange: 'this.form.submit()'
%span.toggle-switch-control.round
%span.toggle-switch-label.on
%span.toggle-switch-label.off

View file

@ -10,10 +10,11 @@
'Instructeurs'] }
.container.groupe-instructeur
= render partial: 'new_administrateur/groupe_instructeurs/routing', locals: { procedure: @procedure }
- if @procedure.routee?
= render partial: 'new_administrateur/groupe_instructeurs/edit', locals: { procedure: @procedure, groupes_instructeurs: @groupes_instructeurs }
- else
= render partial: 'new_administrateur/groupe_instructeurs/routing', locals: { procedure: @procedure }
= render partial: 'new_administrateur/groupe_instructeurs/instructeurs',
locals: { procedure: @procedure,
groupe_instructeur: @procedure.defaut_groupe_instructeur,

View file

@ -11,6 +11,11 @@
.rich-text= pretty_commentaire(commentaire)
.message-extras.flex.justify-start
- if commentaire.soft_deletable?(connected_user)
= button_to instructeur_commentaire_path(commentaire.dossier.procedure, commentaire.dossier, commentaire), method: :delete, class: 'button danger', data: { confirm: t('views.shared.commentaires.destroy.confirm') } do
%span.icon.delete
= t('views.shared.commentaires.destroy.button')
- if commentaire.piece_jointe.attached?
.attachment-link
= render partial: "shared/attachment/show", locals: { attachment: commentaire.piece_jointe.attachment }

View file

@ -5,7 +5,7 @@
#profil-page.container
%h1 Profil
- if @waiting_merge_emails.any?
- if @waiting_merge_emails.present?
.card
.card-title Demande de fusion de comptes
%p
@ -37,7 +37,7 @@
application_name: APPLICATION_NAME,
legit_admin_domains: LEGIT_ADMIN_DOMAINS.join(', '))
= form_for @current_user, url: update_email_path, method: :patch, html: { class: 'form' } do |f|
= form_for current_user, url: update_email_path, method: :patch, html: { class: 'form' } do |f|
= f.email_field :email, value: nil, placeholder: 'Nouvelle adresse email', required: true
= f.submit "Changer mon adresse", class: 'button primary'
@ -50,7 +50,7 @@
= email_field_tag :next_owner, nil, required: true
= submit_tag "Transférer tous mes dossiers", class: 'button primary', data: { confirm: t('.transfer_confirmation') }
- if @waiting_transfers.any?
- if @waiting_transfers.present?
.card.warning
.card-title= t('.waiting_transfers')
%ul

View file

@ -17,3 +17,17 @@ fr:
download_archive: Télécharger une archive au format .zip de tous les dossiers et leurs pièces jointes
archive_pending_html: Archive en cours de création<br>(demandée il y a %{created_period})
archive_ready_html: Télécharger larchive<br>(demandée il y a %{generated_period})
dossiers:
decisions_rendues_block:
without_email:
en_construction: Le %{processed_at} ce dossier a été passé en construction
en_instruction: Le %{processed_at} ce dossier a été passé en instruction
accepte: Le %{processed_at} ce dossier a été accepté
refuse: Le %{processed_at} ce dossier a été refusé
classe_sans_suite: Le %{processed_at} ce dossier a été classé sans suite
with_email:
en_construction: Le %{processed_at}, %{email} a passé ce dossier en construction
en_instruction: Le %{processed_at}, %{email} a passé ce dossier en instruction
accepte: Le %{processed_at}, %{email} a accepté ce dossier
refuse: Le %{processed_at}, %{email} a refusé ce dossier
classe_sans_suite: Le %{processed_at}, %{email} a classé ce dossier sans suite

View file

@ -43,4 +43,5 @@ fr:
Lautogestion des instructeurs permet aux instructeurs de gérer eux-mêmes la liste des instructeurs de la démarche.
button:
routing_enable: Activer le routage
routing_disable: Désactiver le routage
self_managment_toggle: Activer lautogestion des instructeurs

View file

@ -1,6 +1,14 @@
en:
views:
shared:
dossiers:
identite_entreprise:
warning_for_private_info: "The establishment %{etablissement} applied his right to not publish information regarding his identity. These informaiton won't be visible from instructor services"
avis:
demande_envoyee_le: "Feedback send at %{date}"
demande_revoquee_le: "Feedback revoked at %{date}"
reponse_donnee_le: "Response sent at %{date}"
en_attente: "Waiting for response"
france_connect_login:
title: "With FranceConnect"
description: "France connect is a solution proposed by the government to secure and simplify the connection to web services."
@ -12,3 +20,12 @@ en:
already_user: "I already have an account"
create: 'Create an account'
signin: 'Sign in'
commentaires:
destroy:
button: 'Destroy this message'
confirm: "Are you sure you want to destroy this message ?"
deleted_body: Message deleted
notice: 'Your message had been deleted'
alert_reasons:
acl: "Can not destroy message: it does not belong to you"
already_discarded: "Can not destroy message: it was already destroyed"

View file

@ -20,3 +20,12 @@ fr:
already_user: 'Jai déjà un compte'
create: 'Créer un compte'
signin: 'Connexion'
commentaires:
destroy:
button: 'Supprimer le message'
confirm: "Êtes-vous sûr de vouloir supprimer ce message ?"
deleted_body: Message supprimé
notice: 'Votre message a été supprimé'
alert_reasons:
acl: "Impossible de supprimer le message, celui ci ne vous appartient pas"
already_discarded: "Ce message a déjà été supprimé"

View file

@ -351,6 +351,8 @@ Rails.application.routes.draw do
resources :dossiers, only: [:show], param: :dossier_id do
member do
resources :commentaires, only: [:destroy]
get 'attestation'
get 'geo_data'
get 'apercu_attestation'

View file

@ -0,0 +1,6 @@
class AddDiscardedAtToCommentaires < ActiveRecord::Migration[6.1]
def change
add_column :commentaires, :discarded_at, :datetime
# add_index :commentaires, :discarded_at
end
end

View file

@ -10,8 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_11_04_102349) do
ActiveRecord::Schema.define(version: 2021_11_15_112933) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "unaccent"
@ -219,6 +218,7 @@ ActiveRecord::Schema.define(version: 2021_11_04_102349) do
t.bigint "user_id"
t.bigint "instructeur_id"
t.bigint "expert_id"
t.datetime "discarded_at"
t.index ["dossier_id"], name: "index_commentaires_on_dossier_id"
t.index ["expert_id"], name: "index_commentaires_on_expert_id"
t.index ["instructeur_id"], name: "index_commentaires_on_instructeur_id"

View file

@ -0,0 +1,37 @@
# frozen_string_literal: true
describe Instructeurs::CommentairesController, type: :controller do
let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, :published, :for_individual, instructeurs: [instructeur]) }
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
before { sign_in(instructeur.user) }
describe 'destroy' do
context 'when it works' do
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier) }
subject { delete :destroy, params: { dossier_id: dossier.id, procedure_id: procedure.id, id: commentaire.id } }
it 'redirect to dossier' do
expect(subject).to redirect_to(messagerie_instructeur_dossier_path(dossier.procedure, dossier))
end
it 'flash success' do
subject
expect(flash[:notice]).to eq(I18n.t('views.shared.commentaires.destroy.notice'))
end
end
context 'when dossier had been discarded' do
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier, discarded_at: 2.hours.ago) }
subject { delete :destroy, params: { dossier_id: dossier.id, procedure_id: procedure.id, id: commentaire.id } }
it 'redirect to dossier' do
expect(subject).to redirect_to(messagerie_instructeur_dossier_path(dossier.procedure, dossier))
end
it 'flash success' do
subject
expect(flash[:alert]).to eq(I18n.t('views.shared.commentaires.destroy.alert_reasons.already_discarded'))
end
end
end
end

View file

@ -382,6 +382,11 @@ describe Instructeurs::DossiersController, type: :controller do
end
end
describe '#messagerie' do
subject { get :messagerie, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
it { expect(response).to have_http_status(:ok) }
end
describe "#create_commentaire" do
let(:saved_commentaire) { dossier.commentaires.first }
let(:body) { "avant\napres" }

View file

@ -9,7 +9,6 @@ describe NewAdministrateur::ProceduresController, type: :controller do
let(:direction) { 'Direction de test' }
let(:cadre_juridique) { 'cadre juridique' }
let(:duree_conservation_dossiers_dans_ds) { 3 }
let(:duree_conservation_dossiers_hors_ds) { 6 }
let(:monavis_embed) { nil }
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
@ -33,7 +32,6 @@ describe NewAdministrateur::ProceduresController, type: :controller do
direction: direction,
cadre_juridique: cadre_juridique,
duree_conservation_dossiers_dans_ds: duree_conservation_dossiers_dans_ds,
duree_conservation_dossiers_hors_ds: duree_conservation_dossiers_hors_ds,
monavis_embed: monavis_embed,
lien_site_web: lien_site_web
}
@ -164,7 +162,6 @@ describe NewAdministrateur::ProceduresController, type: :controller do
it { expect(subject.direction).to eq(direction) }
it { expect(subject.administrateurs).to eq([admin]) }
it { expect(subject.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds) }
it { expect(subject.duree_conservation_dossiers_hors_ds).to eq(duree_conservation_dossiers_hors_ds) }
end
it { is_expected.to redirect_to(champs_admin_procedure_path(Procedure.last)) }
@ -234,7 +231,6 @@ describe NewAdministrateur::ProceduresController, type: :controller do
let(:organisation) { 'plop' }
let(:direction) { 'plap' }
let(:duree_conservation_dossiers_dans_ds) { 7 }
let(:duree_conservation_dossiers_hors_ds) { 5 }
before { update_procedure }
@ -246,7 +242,6 @@ describe NewAdministrateur::ProceduresController, type: :controller do
it { expect(subject.organisation).to eq(organisation) }
it { expect(subject.direction).to eq(direction) }
it { expect(subject.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds) }
it { expect(subject.duree_conservation_dossiers_hors_ds).to eq(duree_conservation_dossiers_hors_ds) }
end
it { is_expected.to redirect_to(edit_admin_procedure_path id: procedure.id) }

View file

@ -1,30 +1,16 @@
RSpec.describe ConservationDeDonneesHelper, type: :helper do
let(:procedure) { build(:procedure, duree_conservation_dossiers_dans_ds: dans_ds, duree_conservation_dossiers_hors_ds: hors_ds) }
let(:procedure) { build(:procedure, duree_conservation_dossiers_dans_ds: dans_ds) }
describe "politiques_conservation_de_donnees" do
subject { politiques_conservation_de_donnees(procedure) }
context "when both retention times are set" do
context "when retention time is set" do
let(:dans_ds) { 3 }
let(:hors_ds) { 6 }
it { is_expected.to eq(["Dans #{APPLICATION_NAME} : 3 mois", "Par ladministration : 6 mois"]) }
end
context "when only in-app retention time is set" do
let(:dans_ds) { 3 }
let(:hors_ds) { nil }
it { is_expected.to eq(["Dans #{APPLICATION_NAME} : 3 mois"]) }
end
context "when only out of app retention time is set" do
let(:dans_ds) { nil }
let(:hors_ds) { 6 }
it { is_expected.to eq(["Par ladministration : 6 mois"]) }
end
context "when the retention time is not set" do
let(:dans_ds) { nil }
let(:hors_ds) { nil }

View file

@ -28,8 +28,8 @@ RSpec.describe DossierMailer, type: :mailer do
describe '.notify_new_answer with dossier brouillon' do
let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) }
subject { described_class.notify_new_answer(dossier) }
let(:commentaire) { create(:commentaire, dossier: dossier) }
subject { described_class.with(commentaire: commentaire).notify_new_answer }
it { expect(subject.subject).to include("Nouveau message") }
it { expect(subject.subject).to include(dossier.id.to_s) }
@ -40,8 +40,8 @@ RSpec.describe DossierMailer, type: :mailer do
describe '.notify_new_answer with dossier en construction' do
let(:dossier) { create(:dossier, state: "en_construction", procedure: build(:simple_procedure)) }
subject { described_class.notify_new_answer(dossier) }
let(:commentaire) { create(:commentaire, dossier: dossier) }
subject { described_class.with(commentaire: commentaire).notify_new_answer }
it { expect(subject.subject).to include("Nouveau message") }
it { expect(subject.subject).to include(dossier.id.to_s) }
@ -50,6 +50,15 @@ RSpec.describe DossierMailer, type: :mailer do
it_behaves_like 'a dossier notification'
end
describe '.notify_new_answer with commentaire discarded' do
let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) }
let(:commentaire) { create(:commentaire, dossier: dossier, discarded_at: 2.minutes.ago) }
subject { described_class.with(commentaire: commentaire).notify_new_answer }
it { expect(subject.perform_deliveries).to be_falsy }
end
describe '.notify_deletion_to_user' do
let(:deleted_dossier) { build(:deleted_dossier) }

View file

@ -40,6 +40,12 @@ describe Commentaire do
end
end
describe "sent_by?" do
let(:commentaire) { build(:commentaire, instructeur: build(:instructeur)) }
subject { commentaire.sent_by?(nil) }
it { is_expected.to be_falsy }
end
describe "#redacted_email" do
subject { commentaire.redacted_email }
@ -80,8 +86,8 @@ describe Commentaire do
context "with a commentaire created by a instructeur" do
let(:commentaire) { CommentaireService.build(instructeur, dossier, body: "Mon commentaire") }
it "calls notify_user" do
expect(commentaire).to receive(:notify_user)
it "calls notify_user with delay so instructeur can destroy his comment in case of failure" do
expect(commentaire).to receive(:notify_user).with(wait: 5.minutes)
commentaire.save
end
end
@ -90,7 +96,7 @@ describe Commentaire do
let(:commentaire) { CommentaireService.build(expert, dossier, body: "Mon commentaire") }
it "calls notify_user" do
expect(commentaire).to receive(:notify_user)
expect(commentaire).to receive(:notify_user).with(no_args)
commentaire.save
end
end
@ -99,7 +105,7 @@ describe Commentaire do
let(:commentaire) { CommentaireService.build_with_email(CONTACT_EMAIL, dossier, body: "Mon commentaire") }
it "does not call notify_user" do
expect(commentaire).not_to receive(:notify_user)
expect(commentaire).not_to receive(:notify_user).with(no_args)
commentaire.save
end
end

View file

@ -426,13 +426,14 @@ describe User, type: :model do
context 'and the old account has some stuff' do
let!(:dossier) { create(:dossier, user: old_user) }
let!(:hidden_dossier) { create(:dossier, user: old_user, hidden_at: Time.zone.now) }
let!(:invite) { create(:invite, user: old_user) }
let!(:merge_log) { MergeLog.create(user: old_user, from_user_id: 1, from_user_email: 'a') }
it 'transfers the dossier' do
subject
expect(targeted_user.dossiers).to match([dossier])
expect(targeted_user.dossiers.with_discarded).to match([dossier, hidden_dossier])
expect(targeted_user.invites).to match([invite])
expect(targeted_user.merge_logs.first).to eq(merge_log)

View file

@ -46,5 +46,44 @@ describe 'shared/dossiers/messages/message.html.haml', type: :view do
it { is_expected.not_to have_text(instructeur.email) }
end
end
describe 'delete message button for instructeur' do
let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure) }
let(:dossier) { create(:dossier, :en_construction, commentaires: [commentaire], procedure: procedure) }
subject { render 'shared/dossiers/messages/message.html.haml', commentaire: commentaire, messagerie_seen_at: seen_at, connected_user: instructeur, show_reply_button: true }
let(:form_url) { instructeur_commentaire_path(commentaire.dossier.procedure, commentaire.dossier, commentaire) }
context 'on a procedure where commentaire had been written by connected instructeur' do
let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message') }
it { is_expected.to have_selector("form[action=\"#{form_url}\"]") }
end
context 'on a procedure where commentaire had been written by connected instructeur and discarded' do
let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message', discarded_at: 2.days.ago) }
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
it { is_expected.not_to have_selector(".rich-text", text: I18n.t(t('views.shared.commentaires.destroy.deleted_body'))) }
end
context 'on a procedure where commentaire had been written by connected an user' do
let(:commentaire) { create(:commentaire, email: create(:user).email, body: 'Second message') }
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
end
context 'on a procedure where commentaire had been written by connected an expert' do
let(:commentaire) { create(:commentaire, expert: create(:expert), body: 'Second message') }
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
end
context 'on a procedure where commentaire had been written another instructeur' do
let(:commentaire) { create(:commentaire, instructeur: create(:instructeur), body: 'Second message') }
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
end
end
end
end

4909
yarn.lock

File diff suppressed because it is too large Load diff