Merge pull request #4861 from betagouv/dev

2020-03-05-01
This commit is contained in:
Keirua 2020-03-05 10:59:43 +01:00 committed by GitHub
commit e3908065d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 161 additions and 39 deletions

View file

@ -5,7 +5,7 @@ gem 'actiontext', git: 'https://github.com/kobaltz/actiontext.git', branch: 'arc
gem 'active_link_to' # Automatically set a class on active links
gem 'active_model_serializers'
gem 'active_storage_validations'
gem 'activestorage-openstack', git: 'https://github.com/tchak/activestorage-openstack.git', branch: 'fix-activestorage-filename-wrap'
gem 'activestorage-openstack'
gem 'administrate'
gem 'after_party'
gem 'anchored'

View file

@ -15,17 +15,6 @@ GIT
open4 (~> 1.3.4)
rake
GIT
remote: https://github.com/tchak/activestorage-openstack.git
revision: 907582f14d785fb965baebe9524c0162b1bd57c9
branch: fix-activestorage-filename-wrap
specs:
activestorage-openstack (1.3.0)
fog-openstack (~> 1.0)
marcel
mime-types
rails (>= 5.2.2)
GEM
remote: https://rubygems.org/
specs:
@ -77,6 +66,11 @@ GEM
actionpack (= 5.2.4.1)
activerecord (= 5.2.4.1)
marcel (~> 0.3.1)
activestorage-openstack (1.4.1)
fog-openstack (~> 1.0)
marcel
mime-types
rails (>= 5.2.2)
activesupport (5.2.4.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
@ -458,7 +452,7 @@ GEM
byebug (~> 10.0)
pry (~> 0.10)
public_suffix (4.0.3)
puma (3.12.2)
puma (3.12.4)
pundit (2.0.1)
activesupport (>= 3.0.0)
rack (2.2.2)
@ -723,7 +717,7 @@ DEPENDENCIES
active_link_to
active_model_serializers
active_storage_validations
activestorage-openstack!
activestorage-openstack
administrate
after_party
anchored

View file

@ -52,6 +52,10 @@
p {
margin-bottom: $default-spacer;
}
input[type='date'] {
display: inline;
}
}
.editable-champ {

View file

@ -23,6 +23,7 @@ module CreateAvisConcern
{
email: email,
introduction: create_avis_params[:introduction],
introduction_file: create_avis_params[:introduction_file],
claimant: current_instructeur,
dossier: dossier,
confidentiel: confidentiel
@ -43,7 +44,6 @@ module CreateAvisConcern
sent_emails_addresses << avis.email_to_display
end
end
flash.notice = "Une demande d'avis a été envoyée à #{sent_emails_addresses.uniq.join(", ")}"
end
@ -61,6 +61,6 @@ module CreateAvisConcern
end
def create_avis_params
params.require(:avis).permit(:introduction, :confidentiel, :invite_linked_dossiers, emails: [])
params.require(:avis).permit(:introduction_file, :introduction, :confidentiel, :invite_linked_dossiers, emails: [])
end
end

View file

@ -74,6 +74,9 @@ module NewAdministrateur
else
params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :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
end
permited_params
end
end

View file

@ -10,7 +10,7 @@ module DossierHelper
end
def highlight_if_unseen_class(seen_at, updated_at)
if seen_at&.<(updated_at)
if updated_at.present? && seen_at&.<(updated_at)
"highlighted"
end
end

View file

@ -6,6 +6,7 @@ class Avis < ApplicationRecord
belongs_to :claimant, class_name: 'Instructeur'
has_one_attached :piece_justificative_file
has_one_attached :introduction_file
validates :email, format: { with: Devise.email_regexp, message: "n'est pas valide" }, allow_nil: true
validates :claimant, presence: true

View file

@ -187,7 +187,7 @@ class Dossier < ApplicationRecord
.joins('LEFT OUTER JOIN "commentaires" ON "commentaires" . "dossier_id" = "dossiers" . "id" and commentaires.updated_at > follows.messagerie_seen_at and "commentaires"."email" != \'contact@tps.apientreprise.fr\' AND "commentaires"."email" != \'contact@demarches-simplifiees.fr\'')
updated_demandes = joined_dossiers
.where('champs.updated_at > follows.demande_seen_at')
.where('champs.updated_at > follows.demande_seen_at OR groupe_instructeur_updated_at > follows.demande_seen_at')
updated_annotations = joined_dossiers
.where('champs_privates_dossiers.updated_at > follows.annotations_privees_seen_at')
@ -301,7 +301,7 @@ class Dossier < ApplicationRecord
def assign_to_groupe_instructeur(groupe_instructeur, author = nil)
if groupe_instructeur.procedure == procedure && groupe_instructeur != self.groupe_instructeur
if update(groupe_instructeur: groupe_instructeur)
if update(groupe_instructeur: groupe_instructeur, groupe_instructeur_updated_at: Time.zone.now)
unfollow_stale_instructeurs
if author.present?

View file

@ -98,7 +98,8 @@ class Instructeur < ApplicationRecord
.find_by(instructeur: self, dossier: dossier)
if follow.present?
demande = follow.dossier.champs.updated_since?(follow.demande_seen_at).any?
demande = follow.dossier.champs.updated_since?(follow.demande_seen_at).any? || follow.dossier.groupe_instructeur_updated_at&.>(follow.demande_seen_at)
demande = false if demande.nil?
annotations_privees = follow.dossier.champs_private.updated_since?(follow.annotations_privees_seen_at).any?

View file

@ -5,7 +5,10 @@
- @expired_dossiers.group_by(&:procedure).each do |procedure, dossiers|
%dl
%dt
- if procedure.present?
#{procedure.libelle} (#{link_to(procedure.id, manager_procedure_url(procedure))}) :
- else
Procédure supprimée
%dd
= dossiers.map { |d| link_to(d.id, manager_dossier_url(d)) }.join(', ').html_safe
@ -14,7 +17,10 @@
- @expiring_dossiers.group_by(&:procedure).each do |procedure, dossiers|
%dl
%dt
- if procedure.present?
#{procedure.libelle} (#{link_to(procedure.id, manager_procedure_url(procedure))}) :
- else
Procédure supprimée
%dd
= dossiers.map { |d| link_to(d.id, manager_dossier_url(d)) }.join(', ').html_safe

View file

@ -11,6 +11,10 @@
%span.date Demande d'avis envoyée le #{l(@avis.created_at, format: '%d/%m/%y')}
%p.introduction= @avis.introduction
- if @avis.introduction_file.attached?
= render partial: 'shared/attachment/show', locals: { attachment: @avis.introduction_file.attachment }
%br/
= form_for @avis, url: instructeur_avis_path(@avis), html: { class: 'form' } do |f|
= f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true
= render 'shared/attachment/edit',

View file

@ -5,6 +5,12 @@
= form_for avis, url: url, html: { class: 'form' } do |f|
= f.email_field :emails, placeholder: 'Adresses email, séparées par des virgules', required: true, multiple: true, onchange: "javascript:DS.replaceSemicolonByComma(event);"
= f.text_area :introduction, rows: 3, value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true
%p.tab-title Ajouter une pièce jointe
.form-group
= render 'shared/attachment/edit',
{ form: f,
attached_file: avis.introduction_file,
user_can_destroy: true }
- if linked_dossiers.present?
= f.check_box :invite_linked_dossiers, {}, true, false

View file

@ -7,7 +7,7 @@
.container.groupe-instructeur
.card
.card-title Réaffectation des dossiers du groupe « {@groupe_instructeur.label} »
.card-title Réaffectation des dossiers du groupe « #{@groupe_instructeur.label} »
%p
Le groupe « #{@groupe_instructeur.label} » contient des dossiers. Afin de procéder à sa suppression, vous devez réaffecter ses dossiers à un autre groupe instructeur.

View file

@ -106,19 +106,19 @@
= f.text_field :web_hook_url, class: 'form-control', placeholder: 'https://callback.exemple.fr/'
= f.label :auto_archive_on do
Clôture automatique à 00h01 le :
= f.date_field :auto_archive_on, id: 'auto_archive_on', value: @procedure.auto_archive_on
%p.explication
La clôture automatique suspend la publication de la démarche et entraîne le passage de tous les dossiers "en construction"
(c'est à dire ceux qui ont été déposés), au statut "en instruction", ce qui ne permet plus aux usagers de les modifier.
Date limite de dépôt des dossiers
%p.notice
Si une date est définie, aucun dossier ne pourra plus être déposé ou modifié après cette limite.
%p.notice
Le
- value = @procedure.auto_archive_on ? @procedure.auto_archive_on - 1.day : nil
= f.date_field :auto_archive_on, id: 'auto_archive_on', value: value
à 23 h 59
= f.label :declarative_with_state do
Démarche déclarative
%p.notice
Par défaut, un dossier déposé peut être complété ou corrigé par le demandeur jusqu'à sa mise en instruction.<br>
Dans une démarche déclarative, une fois déposé, un dossier ne peut plus être modifié.
Soit il passe immédiatement « en instruction » pour être traité soit il est immédiatement « accepté ».
= f.select :declarative_with_state, Procedure.declarative_attributes_for_select, { prompt: 'Non' }, class: 'form-control'
%p.explication
Par défaut, une démarche nest pas déclarative ; à son dépôt, un dossier est « en construction ». Vous pouvez choisir de la rendre déclarative, afin que tous les dossiers déposés passent immédiatement au statut « en instruction » ou « accepté ».
%br
%br
Dans le cadre dune démarche déclarative, au dépôt, seul lemail associé à létat choisi est envoyé. (ex: démarche déclarative « accepté » : envoi uniquement de lemail d'acceptation)

View file

@ -2,6 +2,9 @@
%tbody
- if dossier.procedure.routee?
%th= dossier.procedure.routing_criteria_name
%td= dossier.groupe_instructeur.label
%td
%td{ class: highlight_if_unseen_class(demande_seen_at, dossier.groupe_instructeur_updated_at) }= dossier.groupe_instructeur.label
%td.updated-at
%span{ class: highlight_if_unseen_class(demande_seen_at, dossier.groupe_instructeur_updated_at) }
modifié le
= try_format_datetime(dossier.updated_at)
= render partial: "shared/dossiers/champ_row", locals: { champs: champs, demande_seen_at: demande_seen_at, profile: profile, repetition: false }

View file

@ -0,0 +1,5 @@
class AddGroupeInstructeurUpdatedAtToDossiers < ActiveRecord::Migration[5.2]
def change
add_column :dossiers, :groupe_instructeur_updated_at, :timestamp
end
end

View file

@ -252,6 +252,7 @@ ActiveRecord::Schema.define(version: 2020_02_27_100001) do
t.datetime "brouillon_close_to_expiration_notice_sent_at"
t.index "to_tsvector('french'::regconfig, (search_terms || private_search_terms))", name: "index_dossiers_on_search_terms_private_search_terms", using: :gin
t.index "to_tsvector('french'::regconfig, search_terms)", name: "index_dossiers_on_search_terms", using: :gin
t.datetime "groupe_instructeur_updated_at"
t.index ["archived"], name: "index_dossiers_on_archived"
t.index ["groupe_instructeur_id"], name: "index_dossiers_on_groupe_instructeur_id"
t.index ["hidden_at"], name: "index_dossiers_on_hidden_at"

View file

@ -126,7 +126,9 @@ describe Instructeurs::AvisController, type: :controller do
let(:invite_linked_dossiers) { nil }
before do
post :create_avis, params: { id: previous_avis.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers } }
@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 } }
created_avis.reload
end
context 'when an invalid email' do
@ -139,6 +141,16 @@ describe Instructeurs::AvisController, type: :controller do
it { expect(Avis.last).to eq(previous_avis) }
end
context 'ask review with attachment' do
let(:previous_avis_confidentiel) { false }
let(:asked_confidentiel) { false }
let(:emails) { ["toto@totomail.com"] }
it { expect(created_avis.introduction_file).to be_attached }
it { expect(created_avis.introduction_file.filename).to eq("piece_justificative_0.pdf") }
it { expect(flash.notice).to eq("Une demande d'avis a été envoyée à toto@totomail.com") }
end
context 'with multiple emails' do
let(:asked_confidentiel) { false }
let(:previous_avis_confidentiel) { false }

View file

@ -113,7 +113,7 @@ feature 'Inviting an expert:' do
expect(page).to have_text('Cet avis est confidentiel')
fill_in 'avis_answer', with: 'Ma réponse dexpert : cest un oui.'
find('.attachment input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/RIB.pdf')
find('.attachment input[name="avis[piece_justificative_file]"]').attach_file(Rails.root + 'spec/fixtures/files/RIB.pdf')
click_on 'Envoyer votre avis'
expect(page).to have_content('Votre réponse est enregistrée')

View file

@ -38,6 +38,13 @@ feature 'The routing', js: true do
victor = User.find_by(email: 'victor@inst.com').instructeur
# add superwoman to littéraire groupe
find('input.select2-search__field').send_keys('superwoman@inst.com', :enter)
perform_enqueued_jobs { click_on 'Affecter' }
expect(page).to have_text("Linstructeur superwoman@inst.com a été affecté")
superwoman = User.find_by(email: 'superwoman@inst.com').instructeur
# add scientifique groupe
click_on 'Groupes dinstructeurs'
fill_in 'Ajouter un groupe', with: 'scientifique'
@ -51,6 +58,11 @@ feature 'The routing', js: true do
marie = User.find_by(email: 'marie@inst.com').instructeur
# add superwoman to scientifique groupe
find('input.select2-search__field').send_keys('superwoman@inst.com', :enter)
perform_enqueued_jobs { click_on 'Affecter' }
expect(page).to have_text("Linstructeur superwoman@inst.com a été affecté")
# publish
publish_procedure(procedure)
log_out(old_layout: true)
@ -134,6 +146,31 @@ feature 'The routing', js: true do
expect(page).to have_current_path(instructeur_procedures_path)
expect(find('.procedure-stats')).not_to have_css('span.notifications')
log_out
# the instructeurs who belong to scientifique AND litteraire groups manage scientifique and litterraire dossiers
register_instructeur_and_log_in(superwoman.email)
visit procedure_path(procedure, params: { statut: 'tous' })
expect(page).to have_text(litteraire_user.email)
expect(page).to have_text(scientifique_user.email)
# follow the dossier
click_on scientifique_user.email
click_on 'Suivre le dossier'
visit procedure_path(procedure, params: { statut: 'tous' })
click_on litteraire_user.email
click_on 'Suivre le dossier'
log_out
# scientifique_user updates its group
user_update_group(scientifique_user, 'littéraire')
# the instructeurs who belong to scientifique AND litteraire groups should have a notification
visit new_user_session_path
sign_in_with superwoman.user.email, password
expect(page).to have_current_path(instructeur_procedures_path)
expect(find('.procedure-stats')).to have_css('span.notifications')
end
def publish_procedure(procedure)
@ -164,6 +201,19 @@ feature 'The routing', js: true do
log_out
end
def user_update_group(user, new_group)
login_as user, scope: :user
visit dossiers_path
click_on user.dossiers.first.id.to_s
click_on "Modifier mon dossier"
select(new_group, from: 'dossier_groupe_instructeur_id')
click_on "Enregistrer les modifications du dossier"
expect(page).to have_text(new_group)
log_out
end
def register_instructeur_and_log_in(email)
confirmation_email = emails_sent_to(email)
.filter { |m| m.subject == 'Activez votre compte instructeur' }

View file

@ -223,6 +223,13 @@ describe Instructeur, type: :model do
it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false }) }
end
context 'when there is a modification on groupe instructeur' do
let(:groupe_instructeur) { create(:groupe_instructeur, instructeurs: [instructeur], procedure: dossier.procedure) }
before { dossier.assign_to_groupe_instructeur(groupe_instructeur) }
it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false }) }
end
context 'when there is a modification on private champs' do
before { dossier.champs_private.first.update_attribute('value', 'toto') }

View file

@ -67,6 +67,31 @@ describe 'shared/dossiers/champs.html.haml', type: :view do
expect(subject).to include(procedure.routing_criteria_name)
expect(subject).to include(dossier.groupe_instructeur.label)
end
context "with seen_at" do
let(:dossier) { create(:dossier) }
let(:nouveau_groupe_instructeur) { create(:groupe_instructeur, procedure: dossier.procedure) }
let(:champ1) { create(:champ, :checkbox, value: "on") }
let(:champs) { [champ1] }
context "with a demande_seen_at after groupe_instructeur_updated_at" do
let(:demande_seen_at) { dossier.groupe_instructeur_updated_at + 1.hour }
it "expect to not highlight new group instructeur label" do
dossier.assign_to_groupe_instructeur(nouveau_groupe_instructeur)
expect(subject).not_to have_css(".highlighted")
end
end
context "with a demande_seen_at before groupe_instructeur_updated_at" do
let(:demande_seen_at) { dossier.groupe_instructeur_updated_at - 1.hour }
it "expect to not highlight new group instructeur label" do
dossier.assign_to_groupe_instructeur(nouveau_groupe_instructeur)
expect(subject).to have_css(".highlighted")
end
end
end
end
context "with a dossier champ, but we are not authorized to acces the dossier" do