Merge pull request #4017 from betagouv/dev

2019-07-01-01
This commit is contained in:
Keirua 2019-07-01 11:45:24 +02:00 committed by GitHub
commit d282829ca5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 95 additions and 20 deletions

View file

@ -64,7 +64,7 @@ En local, un utilisateur de test est créé automatiquement, avec les identifian
AutoArchiveProcedureJob.set(cron: "* * * * *").perform_later AutoArchiveProcedureJob.set(cron: "* * * * *").perform_later
WeeklyOverviewJob.set(cron: "0 7 * * 1").perform_later WeeklyOverviewJob.set(cron: "0 7 * * 1").perform_later
AutoReceiveDossiersForProcedureJob.set(cron: "* * * * *").perform_later(procedure_declaratoire_id, Dossier.states.fetch(:en_instruction)) AutoReceiveDossiersForProcedureJob.set(cron: "* * * * *").perform_later(procedure_declaratoire_id, Dossier.states.fetch(:en_instruction))
SendinblueUpdateAdministrateursJob.set(cron: "0 10 * * *").perform_later UpdateAdministrateurUsageStatisticsJob.set(cron: "0 10 * * *").perform_later
FindDubiousProceduresJob.set(cron: "0 0 * * *").perform_later FindDubiousProceduresJob.set(cron: "0 0 * * *").perform_later
Administrateurs::ActivateBeforeExpirationJob.set(cron: "0 8 * * *").perform_later Administrateurs::ActivateBeforeExpirationJob.set(cron: "0 8 * * *").perform_later
WarnExpiringDossiersJob.set(cron: "0 0 1 * *").perform_later WarnExpiringDossiersJob.set(cron: "0 0 1 * *").perform_later

View file

@ -1,4 +1,6 @@
class UpdateAdministrateurUsageStatisticsJob < ApplicationJob class UpdateAdministrateurUsageStatisticsJob < ApplicationJob
queue_as :cron
def perform def perform
AdministrateurUsageStatisticsService.new.update_administrateurs AdministrateurUsageStatisticsService.new.update_administrateurs
end end

View file

@ -79,6 +79,7 @@ class Dossier < ApplicationRecord
piece_justificative_file_attachment: :blob piece_justificative_file_attachment: :blob
], ],
pieces_justificatives: [], pieces_justificatives: [],
avis: [],
etablissement: [], etablissement: [],
individual: [], individual: [],
user: []) user: [])
@ -176,7 +177,7 @@ class Dossier < ApplicationRecord
end end
def messagerie_available? def messagerie_available?
!brouillon? && !archived !brouillon? && !archived && !procedure.archivee?
end end
def retention_end_date def retention_end_date

View file

@ -23,6 +23,7 @@ class DossierSerializer < ActiveModel::Serializer
has_many :pieces_justificatives has_many :pieces_justificatives
has_many :types_de_piece_justificative has_many :types_de_piece_justificative
has_one :justificatif_motivation has_one :justificatif_motivation
has_many :avis
has_many :champs, serializer: ChampSerializer has_many :champs, serializer: ChampSerializer

View file

@ -24,6 +24,7 @@ class AdministrateurUsageStatisticsService
def administrateur_stats(administrateur) def administrateur_stats(administrateur)
nb_dossiers_by_procedure_id = nb_dossiers_by_procedure_id(administrateur.id) nb_dossiers_by_procedure_id = nb_dossiers_by_procedure_id(administrateur.id)
nb_dossiers_by_synthetic_state = nb_dossiers_by_synthetic_state(administrateur.id) nb_dossiers_by_synthetic_state = nb_dossiers_by_synthetic_state(administrateur.id)
nb_dossiers_roi = nb_dossiers_by_procedure_id.reject { |procedure_id, _count| is_brouillon(procedure_id) }.map { |_procedure_id, count| count }.sum
result = { result = {
ds_sign_in_count: administrateur.sign_in_count, ds_sign_in_count: administrateur.sign_in_count,
@ -57,7 +58,9 @@ class AdministrateurUsageStatisticsService
.map { |_procedure_id, count| count } .map { |_procedure_id, count| count }
.max || 0, .max || 0,
nb_dossiers_traite: nb_dossiers_by_synthetic_state['termine'], nb_dossiers_traite: nb_dossiers_by_synthetic_state['termine'],
nb_dossiers_dossier_en_instruction: nb_dossiers_by_synthetic_state['en_instruction'] nb_dossiers_dossier_en_instruction: nb_dossiers_by_synthetic_state['en_instruction'],
admin_roi_low: nb_dossiers_roi * 7.04,
admin_roi_high: nb_dossiers_roi * 17.25
} }
if administrateur.current_sign_in_at.present? if administrateur.current_sign_in_at.present?

View file

@ -12,6 +12,9 @@ class CommentaireService
end end
def build_with_email(email, dossier, params) def build_with_email(email, dossier, params)
if !dossier.messagerie_available?
raise ArgumentError, "Commentaires cannot be added to brouillons or archived Dossiers"
end
attributes = params.merge(email: email, dossier: dossier) attributes = params.merge(email: email, dossier: dossier)
Commentaire.new(attributes) Commentaire.new(attributes)
end end

View file

@ -4,4 +4,7 @@
%li.message{ class: commentaire_is_from_me_class(commentaire, connected_user) } %li.message{ class: commentaire_is_from_me_class(commentaire, connected_user) }
= render partial: "shared/dossiers/messages/message", locals: { commentaire: commentaire, connected_user: connected_user, messagerie_seen_at: messagerie_seen_at } = render partial: "shared/dossiers/messages/message", locals: { commentaire: commentaire, connected_user: connected_user, messagerie_seen_at: messagerie_seen_at }
- if dossier.archived?
= render partial: "shared/dossiers/messages/messagerie_disabled", locals: { service: dossier.procedure.service }
- else
= render partial: "shared/dossiers/messages/form", locals: { commentaire: new_commentaire, form_url: form_url } = render partial: "shared/dossiers/messages/form", locals: { commentaire: new_commentaire, form_url: form_url }

View file

@ -0,0 +1,14 @@
.card.feedback
.card-title
La messagerie est désormais désactivée.
%p
Pour poser une question sur ce dossier, contactez :
%p
= service.nom
%br
= service.organisme
%br
- horaires = "Horaires : #{formatted_horaires(service.horaires)}"
= simple_format(horaires)
%p
= link_to service.email, "mailto:#{service.email}"

View file

@ -27,7 +27,9 @@
%a{ href: "tel:#{service.telephone}" }= service.telephone %a{ href: "tel:#{service.telephone}" }= service.telephone
%p %p
Horaires : #{formatted_horaires(service.horaires)} - horaires = "Horaires : #{formatted_horaires(service.horaires)}"
= simple_format(horaires)
- politiques = politiques_conservation_de_donnees(procedure) - politiques = politiques_conservation_de_donnees(procedure)
- if politiques.present? - if politiques.present?

View file

@ -59,7 +59,7 @@ Rails.application.configure do
port: 3000 port: 3000
} }
# Use Content-Security-Policy-Report-Only instead of Content-Security-Policy # Use Content-Security-Policy-Report-Only headers
config.content_security_policy_report_only = true config.content_security_policy_report_only = true
# Raises error for missing translations # Raises error for missing translations

View file

@ -109,7 +109,8 @@ Rails.application.configure do
host: ENV['APP_HOST'] host: ENV['APP_HOST']
} }
config.content_security_policy_report_only = true # The Content-Security-Policy is NOT in Report-Only mode
config.content_security_policy_report_only = false
config.lograge.enabled = ENV['LOGRAGE_ENABLED'] == 'enabled' config.lograge.enabled = ENV['LOGRAGE_ENABLED'] == 'enabled'
end end

View file

@ -45,7 +45,7 @@ Rails.application.configure do
protocol: :http protocol: :http
} }
# Use Content-Security-Policy-Report-Only instead of Content-Security-Policy # Use Content-Security-Policy-Report-Only headers
config.content_security_policy_report_only = true config.content_security_policy_report_only = true
config.active_job.queue_adapter = :test config.active_job.queue_adapter = :test

View file

@ -13,8 +13,8 @@ Rails.application.config.content_security_policy do |policy|
# Pour les CSS, on a beaucoup de style inline et quelques balises <style> # Pour les CSS, on a beaucoup de style inline et quelques balises <style>
# c'est trop compliqué pour être rectifié immédiatement (et sans valeur ajoutée: # c'est trop compliqué pour être rectifié immédiatement (et sans valeur ajoutée:
# c'est hardcodé dans les vues, donc pas injectable). # c'est hardcodé dans les vues, donc pas injectable).
policy.style_src :self, :unsafe_inline, "*.crisp.chat", "crisp.chat" policy.style_src :self, "*.crisp.chat", "crisp.chat", :unsafe_inline
policy.connect_src "wss://*.crisp.chat" policy.connect_src :self, "wss://*.crisp.chat"
# Pour tout le reste, par défaut on accepte uniquement ce qui vient de chez nous # Pour tout le reste, par défaut on accepte uniquement ce qui vient de chez nous
# et dans la notification on inclue la source de l'erreur # et dans la notification on inclue la source de l'erreur
policy.default_src :self, :data, :report_sample, "fonts.gstatic.com", "in-automate.sendinblue.com", "player.vimeo.com", "app.franceconnect.gouv.fr", "sentry.io", "static.demarches-simplifiees.fr", "*.crisp.chat", "crisp.chat", "*.sibautomation.com", "sibautomation.com", "data" policy.default_src :self, :data, :report_sample, "fonts.gstatic.com", "in-automate.sendinblue.com", "player.vimeo.com", "app.franceconnect.gouv.fr", "sentry.io", "static.demarches-simplifiees.fr", "*.crisp.chat", "crisp.chat", "*.sibautomation.com", "sibautomation.com", "data"

View file

@ -157,7 +157,7 @@ describe API::V1::DossiersController do
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, :en_construction, procedure: procedure, motivation: "Motivation") } } let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, :en_construction, procedure: procedure, motivation: "Motivation") } }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:body) { JSON.parse(retour.body, symbolize_names: true) } let(:body) { JSON.parse(retour.body, symbolize_names: true) }
let(:field_list) { [:id, :created_at, :updated_at, :archived, :individual, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state, :initiated_at, :processed_at, :received_at, :motivation, :email, :instructeurs, :justificatif_motivation] } let(:field_list) { [:id, :created_at, :updated_at, :archived, :individual, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state, :initiated_at, :processed_at, :received_at, :motivation, :email, :instructeurs, :justificatif_motivation, :avis] }
subject { body[:dossier] } subject { body[:dossier] }
it 'return REST code 200', :show_in_doc do it 'return REST code 200', :show_in_doc do

View file

@ -13,7 +13,7 @@ RSpec.describe NotificationMailer, type: :mailer do
end end
let(:user) { create(:user) } let(:user) { create(:user) }
let(:dossier) { create(:dossier, :with_service, user: user) } let(:dossier) { create(:dossier, :with_service, :en_construction, user: user) }
describe '.send_notification' do describe '.send_notification' do
let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') } let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') }

View file

@ -736,6 +736,37 @@ describe Dossier do
end end
end end
describe "#messagerie_available?" do
let(:procedure) { create(:procedure) }
let(:dossier) { create(:dossier, procedure: procedure) }
subject { dossier.messagerie_available? }
context "dossier is brouillon" do
before { dossier.state = Dossier.states.fetch(:brouillon) }
it { is_expected.to be false }
end
context "dossier is archived" do
before { dossier.archived = true }
it { is_expected.to be false }
end
context "procedure is archived" do
before { procedure.archived_at = Date.today }
it { is_expected.to be false }
end
context "procedure is not archived, dossier is not archived" do
before { dossier.state = Dossier.states.fetch(:en_instruction) }
it { is_expected.to be true }
end
end
context "retention date" do context "retention date" do
let(:procedure) { create(:procedure, duree_conservation_dossiers_dans_ds: 6) } let(:procedure) { create(:procedure, duree_conservation_dossiers_dans_ds: 6) }
let(:uninstructed_dossier) { create(:dossier, :en_construction, procedure: procedure) } let(:uninstructed_dossier) { create(:dossier, :en_construction, procedure: procedure) }

View file

@ -29,7 +29,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 0, nb_dossiers: 0,
nb_dossiers_max: 0, nb_dossiers_max: 0,
nb_dossiers_traite: 0, nb_dossiers_traite: 0,
nb_dossiers_dossier_en_instruction: 0 nb_dossiers_dossier_en_instruction: 0,
admin_roi_low: 0,
admin_roi_high: 0
) )
end end
end end
@ -80,7 +82,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 0, nb_dossiers: 0,
nb_dossiers_max: 0, nb_dossiers_max: 0,
nb_dossiers_traite: 0, nb_dossiers_traite: 0,
nb_dossiers_dossier_en_instruction: 0 nb_dossiers_dossier_en_instruction: 0,
admin_roi_low: 0,
admin_roi_high: 0
) )
end end
end end
@ -108,7 +112,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 21, nb_dossiers: 21,
nb_dossiers_max: 21, nb_dossiers_max: 21,
nb_dossiers_traite: 7, nb_dossiers_traite: 7,
nb_dossiers_dossier_en_instruction: 7 nb_dossiers_dossier_en_instruction: 7,
admin_roi_low: 147.84,
admin_roi_high: 362.25
) )
end end
end end
@ -127,7 +133,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 0, nb_dossiers: 0,
nb_dossiers_max: 0, nb_dossiers_max: 0,
nb_dossiers_traite: 0, nb_dossiers_traite: 0,
nb_dossiers_dossier_en_instruction: 0 nb_dossiers_dossier_en_instruction: 0,
admin_roi_low: 0,
admin_roi_high: 0
) )
end end
end end
@ -155,7 +163,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 0, nb_dossiers: 0,
nb_dossiers_max: 0, nb_dossiers_max: 0,
nb_dossiers_traite: 0, nb_dossiers_traite: 0,
nb_dossiers_dossier_en_instruction: 0 nb_dossiers_dossier_en_instruction: 0,
admin_roi_low: 0,
admin_roi_high: 0
) )
end end
end end
@ -181,7 +191,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 3, nb_dossiers: 3,
nb_dossiers_max: 3, nb_dossiers_max: 3,
nb_dossiers_traite: 1, nb_dossiers_traite: 1,
nb_dossiers_dossier_en_instruction: 1 nb_dossiers_dossier_en_instruction: 1,
admin_roi_low: 21.12,
admin_roi_high: 51.75
) )
end end
end end
@ -209,7 +221,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 21, nb_dossiers: 21,
nb_dossiers_max: 21, nb_dossiers_max: 21,
nb_dossiers_traite: 7, nb_dossiers_traite: 7,
nb_dossiers_dossier_en_instruction: 7 nb_dossiers_dossier_en_instruction: 7,
admin_roi_low: 147.84,
admin_roi_high: 362.25
) )
end end
end end

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe CommentaireService do describe CommentaireService do
describe '.create' do describe '.create' do
let(:dossier) { create :dossier } let(:dossier) { create :dossier, :en_construction }
let(:sender) { dossier.user } let(:sender) { dossier.user }
let(:body) { 'Contenu du message.' } let(:body) { 'Contenu du message.' }
let(:file) { nil } let(:file) { nil }