Merge pull request #5975 from betagouv/main

2021-03-10-01
This commit is contained in:
Kara Diaby 2021-03-10 17:22:54 +01:00 committed by GitHub
commit 9c6406910e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 225 additions and 274 deletions

View file

@ -1,152 +0,0 @@
version: 2
defaults: &defaults
working_directory: ~/tps
docker:
- image: circleci/ruby:2.7.1-node-browsers
- image: circleci/postgres:10.12
environment:
POSTGRES_USER: tps_test
POSTGRES_PASSWORD: tps_test
POSTGRES_DB: tps_test
bundle_restore_cache: &bundle_restore_cache
restore_cache:
name: Restore Bundler Package Cache
keys:
- bundle-install-v10-{{ arch }}-{{ checksum "Gemfile.lock" }}
- bundle-install-v10-{{ arch }}
- bundle-install-v10
bundle_save_cache: &bundle_save_cache
save_cache:
name: Save Bundler Package Cache
key: bundle-install-v10-{{ arch }}-{{ checksum "Gemfile.lock" }}
paths:
- ~/vendor/bundle
aptget_install: &aptget_install
run:
name: Install GEOS
command: sudo apt-get install libgeos-dev
bundle_install: &bundle_install
run:
name: Install Ruby Dependencies
command: bundle install --path ~/vendor/bundle
yarn_restore_cache: &yarn_restore_cache
restore_cache:
name: Restore Yarn Package Cache
keys:
- yarn-install-v3-{{ arch }}-{{ checksum "yarn.lock" }}
- yarn-install-v3-{{ arch }}
- yarn-install-v3
yarn_save_cache: &yarn_save_cache
save_cache:
name: Save Yarn Package Cache
key: yarn-install-v3-{{ arch }}-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn
yarn_install: &yarn_install
run:
name: Install JS Dependencies
command: yarn install --frozen-lockfile --non-interactive || yarn install --frozen-lockfile --non-interactive
webpacker_restore_cache: &webpacker_restore_cache
restore_cache:
name: Restore Webpacker Cache
keys:
- webpacker-v1-{{ .Branch }}-{{ .Revision }}
- webpacker-v1-{{ .Branch }}
- webpacker-v1
webpacker_save_cache: &webpacker_save_cache
save_cache:
name: Save Webpacker Cache
key: webpacker-v1-{{ .Branch }}-{{ .Revision }}
paths:
- public/packs-test
- tmp/cache/webpacker
webpacker_precompile: &webpacker_precompile
run:
environment:
RAILS_ENV: test
name: Precompile Webpack assets
command: bin/webpack
jobs:
build:
<<: *defaults
steps:
- checkout
- *aptget_install
- *bundle_restore_cache
- *bundle_install
- *bundle_save_cache
- *yarn_restore_cache
- *yarn_install
- *yarn_save_cache
test:
<<: *defaults
parallelism: 3
steps:
- checkout
- *aptget_install
- *bundle_restore_cache
- *bundle_install
- *yarn_restore_cache
- *yarn_install
- *webpacker_restore_cache
- *webpacker_precompile
- *webpacker_save_cache
- run:
environment:
DATABASE_URL: "postgres://tps_test@localhost:5432/tps_test"
name: Create Database
command: bundle exec rake db:create db:schema:load db:migrate RAILS_ENV=test
- run:
environment:
DATABASE_URL: "postgres://tps_test@localhost:5432/tps_test"
name: Run Tests, Splitted by Timings
command: |
COMMAND="bundle exec rspec --profile 10 \
--format RspecJunitFormatter \
--out ~/test_results/rspec.xml \
--format progress \
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
echo $COMMAND
eval $COMMAND
- store_test_results:
path: ~/test_results
- store_artifacts:
path: tmp/capybara
destination: screenshots
lint:
<<: *defaults
steps:
- checkout
- *aptget_install
- *bundle_restore_cache
- *bundle_install
- *yarn_restore_cache
- *yarn_install
- run:
name: Run linters
command: bundle exec rake lint
workflows:
version: 2
build_and_test:
jobs:
- build
- test:
requires:
- build
- lint:
requires:
- build

View file

@ -115,7 +115,6 @@ group :development, :test do
gem 'graphql-schema_comparator'
gem 'mina', git: 'https://github.com/mina-deploy/mina.git', require: false # Deploy
gem 'pry-byebug' # Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'rspec_junit_formatter', require: false
gem 'rspec-rails'
gem 'simple_xlsx_reader'
gem 'spring' # Spring speeds up development by keeping your application running in the background

View file

@ -416,7 +416,7 @@ GEM
mini_magick (4.11.0)
mini_mime (1.0.2)
mini_portile2 (2.5.0)
minitest (5.14.3)
minitest (5.14.4)
momentjs-rails (2.20.1)
railties (>= 3.1)
multi_json (1.15.0)
@ -579,17 +579,15 @@ GEM
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-rails (4.0.2)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
rspec-rails (5.0.0)
actionpack (>= 5.2)
activesupport (>= 5.2)
railties (>= 5.2)
rspec-core (~> 3.10)
rspec-expectations (~> 3.10)
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.10.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
@ -855,7 +853,6 @@ DEPENDENCIES
rgeo-geojson
rqrcode
rspec-rails
rspec_junit_formatter
rubocop
rubocop-rails_config
rubocop-rspec-focused

View file

@ -27,6 +27,7 @@ module CreateAvisConcern
introduction: create_avis_params[:introduction],
introduction_file: create_avis_params[:introduction_file],
claimant: current_instructeur,
claimant_type: current_instructeur.dossiers.present? ? 'Instructeur' : 'Expert',
dossier: dossier,
confidentiel: confidentiel,
experts_procedure: experts_procedure

View file

@ -12,13 +12,13 @@ module Instructeurs
DONNES_STATUS = 'donnes'
def index
avis = current_instructeur.avis.includes(dossier: [groupe_instructeur: :procedure])
avis = current_instructeur.avis.includes(: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) })
instructeur_avis = current_instructeur.avis.includes(:dossier).where(dossiers: { revision: @procedure.revisions })
@avis_a_donner = instructeur_avis.without_answer
@avis_donnes = instructeur_avis.with_answer

View file

@ -254,7 +254,7 @@ module Users
dossier = Dossier.new(
revision: procedure.active_revision,
groupe_instructeur: procedure.defaut_groupe_instructeur,
groupe_instructeur: procedure.defaut_groupe_instructeur_for_new_dossier,
user: current_user,
state: Dossier.states.fetch(:brouillon)
)
@ -338,7 +338,21 @@ module Users
end
def change_groupe_instructeur?
params[:dossier][:groupe_instructeur_id].present? && @dossier.groupe_instructeur_id != params[:dossier][:groupe_instructeur_id].to_i
if params[:dossier].key?(:groupe_instructeur_id)
groupe_instructeur_id = params[:dossier][:groupe_instructeur_id]
if groupe_instructeur_id.nil?
@dossier.groupe_instructeur_id.present?
else
@dossier.groupe_instructeur_id != groupe_instructeur_id.to_i
end
end
end
def groupe_instructeur_from_params
groupe_instructeur_id = params[:dossier][:groupe_instructeur_id]
if groupe_instructeur_id.present?
@dossier.procedure.groupe_instructeurs.find(groupe_instructeur_id)
end
end
def update_dossier_and_compute_errors
@ -357,13 +371,16 @@ module Users
if !@dossier.save
errors += @dossier.errors.full_messages
elsif change_groupe_instructeur?
groupe_instructeur = @dossier.procedure.groupe_instructeurs.find(params[:dossier][:groupe_instructeur_id])
@dossier.assign_to_groupe_instructeur(groupe_instructeur)
@dossier.assign_to_groupe_instructeur(groupe_instructeur_from_params)
end
end
if !save_draft?
errors += @dossier.check_mandatory_champs
if @dossier.groupe_instructeur.nil?
errors << "Le champ « #{@dossier.procedure.routing_criteria_name} » doit être rempli"
end
end
errors

View file

@ -19,7 +19,7 @@ module Mutations
def authorized?(dossier:, groupe_instructeur:)
if dossier.groupe_instructeur == groupe_instructeur
return false, { errors: ["Le dossier est déjà avec le grope instructeur: '#{groupe_instructeur.label}'"] }
elsif dossier.groupe_instructeur.procedure != groupe_instructeur.procedure
elsif dossier.procedure != groupe_instructeur.procedure
return false, { errors: ["Le groupe instructeur '#{groupe_instructeur.label}' nappartient pas à la même démarche que le dossier"] }
else
true

View file

@ -4,6 +4,7 @@
#
# id :integer not null, primary key
# answer :text
# claimant_type :string
# confidentiel :boolean default(FALSE), not null
# email :string
# introduction :text
@ -22,6 +23,7 @@ class Avis < ApplicationRecord
belongs_to :instructeur, optional: true
belongs_to :experts_procedure, optional: true
belongs_to :claimant, class_name: 'Instructeur', optional: false
has_one :procedure, through: :dossier
has_one_attached :piece_justificative_file
has_one_attached :introduction_file
@ -79,10 +81,6 @@ class Avis < ApplicationRecord
]
end
def procedure
dossier.procedure
end
def revoked?
revoked_at.present?
end

View file

@ -77,7 +77,7 @@ class Dossier < ApplicationRecord
has_many :dossier_operation_logs, -> { order(:created_at) }, inverse_of: :dossier
belongs_to :groupe_instructeur, optional: false
belongs_to :groupe_instructeur, optional: true
belongs_to :revision, class_name: 'ProcedureRevision', optional: false
belongs_to :user, optional: false
@ -293,8 +293,8 @@ class Dossier < ApplicationRecord
# select users who have submitted dossier for the given 'procedures.id'
users_who_submitted =
state_not_brouillon
.joins(:groupe_instructeur)
.where("groupe_instructeurs.procedure_id = procedures.id")
.joins(:revision)
.where("procedure_revisions.procedure_id = procedures.id")
.select(:user_id)
# select dossier in brouillon where procedure closes in two days and for which the user has not submitted a Dossier
state_brouillon
@ -321,7 +321,7 @@ class Dossier < ApplicationRecord
delegate :siret, :siren, to: :etablissement, allow_nil: true
delegate :france_connect_information, to: :user
before_save :build_default_champs, if: Proc.new { groupe_instructeur_id_was.nil? }
before_save :build_default_champs, if: Proc.new { revision_id_was.nil? }
before_save :update_search_terms
after_save :send_dossier_received
@ -330,7 +330,7 @@ class Dossier < ApplicationRecord
validates :user, presence: true
validates :individual, presence: true, if: -> { revision.procedure.for_individual? }
validates :groupe_instructeur, presence: true
validates :groupe_instructeur, presence: true, if: -> { !brouillon? }
def motivation
return nil if !termine?
@ -419,7 +419,7 @@ class Dossier < ApplicationRecord
end
def show_groupe_instructeur_details?
procedure.routee? && (!procedure.feature_enabled?(:procedure_routage_api) || !defaut_groupe_instructeur?)
procedure.routee? && groupe_instructeur.present? && (!procedure.feature_enabled?(:procedure_routage_api) || !defaut_groupe_instructeur?)
end
def show_groupe_instructeur_selector?
@ -427,7 +427,7 @@ class Dossier < ApplicationRecord
end
def assign_to_groupe_instructeur(groupe_instructeur, author = nil)
if groupe_instructeur.procedure == procedure && groupe_instructeur != self.groupe_instructeur
if (groupe_instructeur.nil? || groupe_instructeur.procedure == procedure) && self.groupe_instructeur != groupe_instructeur
if update(groupe_instructeur: groupe_instructeur, groupe_instructeur_updated_at: Time.zone.now)
unfollow_stale_instructeurs

View file

@ -599,6 +599,12 @@ class Procedure < ApplicationRecord
groupe_instructeurs.count > 1
end
def defaut_groupe_instructeur_for_new_dossier
if !routee? || feature_enabled?(:procedure_routage_api)
defaut_groupe_instructeur
end
end
def can_be_deleted_by_administrateur?
brouillon? || dossiers.state_instruction_commencee.empty?
end

View file

@ -125,10 +125,10 @@ class AdministrateurUsageStatisticsService
result = {}
Dossier
.joins(groupe_instructeur: { procedure: [:administrateurs] })
.joins(revision: { procedure: [:administrateurs] })
.group(
'administrateurs.id',
'groupe_instructeurs.procedure_id',
'procedure_revisions.procedure_id',
<<~EOSQL
CASE
WHEN state IN('accepte', 'refuse', 'sans_suite') THEN 'termine'

View file

@ -11,7 +11,7 @@
= link_to 'Jai déjà un compte', commencer_sign_in_path(path: @procedure.path), class: ['button large expand']
- else
- dossiers = current_user.dossiers.where(groupe_instructeur: @procedure.groupe_instructeurs)
- dossiers = current_user.dossiers.where(revision: @procedure.revisions)
- drafts = dossiers.merge(Dossier.state_brouillon)
- not_drafts = dossiers.merge(Dossier.state_not_brouillon)

View file

@ -34,19 +34,9 @@
= f.label :groupe_instructeur_id do
= dossier.procedure.routing_criteria_name
%span.mandatory *
-# The routing dropdown has 'include_blank: false', because otherwise a blank
-# value may nullify the groupe_instructeur and thus the link between the dossier
-# and its procedure.
-#
-# If, one day, we need to make clearer to the user that they must actually choose an
-# option, THINK TWICE before adding a blank option, and what would happen if the form is
-# saved when the blank option is selected.
-# Instead please consider other possibilities; like using CSS to gray out the default option,
-# or adding some "(please select an option)" wording aside the label of the default group.
-# CSS
= f.select :groupe_instructeur_id,
dossier.procedure.groupe_instructeurs.order(:label).map { |gi| [gi.label, gi.id] },
{ include_blank: false }
{ include_blank: dossier.brouillon? }
= f.fields_for :champs, dossier.champs do |champ_form|
- champ = champ_form.object

View file

@ -23,9 +23,9 @@ if (!Array.isArray(nodeModulesLoader.exclude)) {
nodeModulesLoader.exclude =
nodeModulesLoader.exclude == null ? [] : [nodeModulesLoader.exclude];
}
nodeModulesLoader.exclude.push({
and: [/mapbox-gl/, { not: [/react-mapbox-gl/] }]
});
nodeModulesLoader.exclude.push(
path.resolve(__dirname, '..', '..', 'node_modules/mapbox-gl')
);
// Uncoment next lines to run webpack-bundle-analyzer
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');

View file

@ -0,0 +1,6 @@
class AddClaimantTypeToAvis < ActiveRecord::Migration[6.0]
def change
add_column :avis, :claimant_type, :string
remove_foreign_key :avis, :instructeurs, column: "claimant_id"
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_02_04_180955) do
ActiveRecord::Schema.define(version: 2021_03_07_143807) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -122,6 +122,7 @@ ActiveRecord::Schema.define(version: 2021_02_04_180955) do
t.boolean "confidentiel", default: false, null: false
t.datetime "revoked_at"
t.bigint "experts_procedure_id"
t.string "claimant_type"
t.index ["claimant_id"], name: "index_avis_on_claimant_id"
t.index ["dossier_id"], name: "index_avis_on_dossier_id"
t.index ["experts_procedure_id"], name: "index_avis_on_experts_procedure_id"
@ -729,7 +730,6 @@ ActiveRecord::Schema.define(version: 2021_02_04_180955) do
add_foreign_key "attestation_templates", "procedures"
add_foreign_key "attestations", "dossiers"
add_foreign_key "avis", "experts_procedures"
add_foreign_key "avis", "instructeurs", column: "claimant_id"
add_foreign_key "champs", "champs", column: "parent_id"
add_foreign_key "closed_mails", "procedures"
add_foreign_key "commentaires", "dossiers"

View file

@ -0,0 +1,46 @@
namespace :after_party do
desc 'Deployment task: backfill_claimant_type_on_avis_table'
task backfill_claimant_type_on_avis_table: :environment do
puts "Running deploy task 'backfill_claimant_type_on_avis_table'"
BATCH_SIZE = 20000
with_dossiers = Avis.where(claimant_type: nil).includes(claimant: :assign_to).where.not(claimant: { assign_tos: { id: nil } })
((with_dossiers.count / BATCH_SIZE).ceil + 1).times do
with_dossiers
.limit(BATCH_SIZE)
.update_all(claimant_type: 'Instructeur')
end
without_dossiers = Avis.where(claimant_type: nil).includes(claimant: :assign_to).where(claimant: { assign_tos: { id: nil } })
without_dossiers.find_each do |avis|
claimant = avis.claimant.user
instructeur = avis.instructeur
if instructeur && avis.experts_procedure_id.blank?
User.create_or_promote_to_expert(instructeur.user.email, SecureRandom.hex)
instructeur.user.reload
experts_procedure = ExpertsProcedure.find_or_create_by(procedure: avis.procedure, expert: instructeur.user.expert)
avis.update_columns(claimant_type: 'Expert', experts_procedure_id: experts_procedure.id)
elsif instructeur.blank? && avis.experts_procedure_id.blank?
expert = User.create_or_promote_to_expert(avis.email, SecureRandom.hex).expert
expert.reload
experts_procedure = ExpertsProcedure.find_or_create_by(procedure: avis.procedure, expert: expert)
avis.update_columns(claimant_type: 'Expert', experts_procedure_id: experts_procedure.id)
elsif avis.experts_procedure_id.present?
avis.update_column(:claimant_type, 'Expert')
elsif claimant.blank?
avis.destroy
end
end
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -275,20 +275,8 @@ describe Instructeurs::ProceduresController, type: :controller do
it { expect(assigns(:procedure)).to eq(procedure) }
end
context 'with a new brouillon dossier' do
let!(:brouillon_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:brouillon)) }
before { subject }
it { expect(assigns(:a_suivre_dossiers)).to be_empty }
it { expect(assigns(:followed_dossiers)).to be_empty }
it { expect(assigns(:termines_dossiers)).to be_empty }
it { expect(assigns(:all_state_dossiers)).to be_empty }
it { expect(assigns(:archived_dossiers)).to be_empty }
end
context 'with a new dossier without follower' do
let!(:new_unfollow_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
let!(:new_unfollow_dossier) { create(:dossier, :en_instruction, procedure: procedure) }
before { subject }
@ -310,7 +298,7 @@ describe Instructeurs::ProceduresController, type: :controller do
end
context 'with a new dossier with a follower' do
let!(:new_followed_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
let!(:new_followed_dossier) { create(:dossier, :en_instruction, procedure: procedure) }
before do
instructeur.followed_dossiers << new_followed_dossier
@ -339,7 +327,7 @@ describe Instructeurs::ProceduresController, type: :controller do
end
context 'with a termine dossier with a follower' do
let!(:termine_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:accepte)) }
let!(:termine_dossier) { create(:dossier, :accepte, procedure: procedure) }
before { subject }
@ -361,7 +349,7 @@ describe Instructeurs::ProceduresController, type: :controller do
end
context 'with an archived dossier' do
let!(:archived_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true) }
let!(:archived_dossier) { create(:dossier, :en_instruction, procedure: procedure, archived: true) }
before { subject }
@ -372,8 +360,8 @@ describe Instructeurs::ProceduresController, type: :controller do
it { expect(assigns(:archived_dossiers)).to match_array([archived_dossier]) }
context 'and terminer dossiers on each of the others groups' do
let!(:archived_dossier_on_gi_2) { create(:dossier, groupe_instructeur: gi_2, state: Dossier.states.fetch(:en_instruction), archived: true) }
let!(:archived_dossier_on_gi_3) { create(:dossier, groupe_instructeur: gi_3, state: Dossier.states.fetch(:en_instruction), archived: true) }
let!(:archived_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2, archived: true) }
let!(:archived_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3, archived: true) }
before { subject }
@ -382,10 +370,10 @@ describe Instructeurs::ProceduresController, type: :controller do
end
describe 'statut' do
let!(:a_suivre__dossier) { Timecop.freeze(1.day.ago) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) } }
let!(:new_followed_dossier) { Timecop.freeze(2.days.ago) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) } }
let!(:termine_dossier) { Timecop.freeze(3.days.ago) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:accepte)) } }
let!(:archived_dossier) { Timecop.freeze(4.days.ago) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true) } }
let!(:a_suivre__dossier) { Timecop.freeze(1.day.ago) { create(:dossier, :en_instruction, procedure: procedure) } }
let!(:new_followed_dossier) { Timecop.freeze(2.days.ago) { create(:dossier, :en_instruction, procedure: procedure) } }
let!(:termine_dossier) { Timecop.freeze(3.days.ago) { create(:dossier, :accepte, procedure: procedure) } }
let!(:archived_dossier) { Timecop.freeze(4.days.ago) { create(:dossier, :en_instruction, procedure: procedure, archived: true) } }
before do
instructeur.followed_dossiers << new_followed_dossier

View file

@ -342,6 +342,7 @@ describe Users::DossiersController, type: :controller do
{
id: dossier.id,
dossier: {
groupe_instructeur_id: dossier.groupe_instructeur_id,
champs_attributes: {
id: first_champ.id,
value: value
@ -418,6 +419,8 @@ describe Users::DossiersController, type: :controller do
let(:another_group) { create(:groupe_instructeur, procedure: procedure) }
let(:instructeur_of_dossier) { create(:instructeur) }
let(:instructeur_in_another_group) { create(:instructeur) }
context "and grope instructeur is set" do
let!(:dossier) { create(:dossier, groupe_instructeur: dossier_group, user: user) }
before do
@ -434,6 +437,29 @@ describe Users::DossiersController, type: :controller do
end
end
context "and groupe instructeur is not set" do
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
let(:submit_payload) do
{
id: dossier.id,
dossier: {
champs_attributes: {
id: first_champ.id,
value: value
}
},
submit_draft: false
}
end
it "can not submit" do
subject
expect(flash.alert).to eq(['Le champ « Votre ville » doit être rempli'])
end
end
end
context "on an closed procedure" do
before { dossier.procedure.close! }
@ -557,6 +583,7 @@ describe Users::DossiersController, type: :controller do
{
id: dossier.id,
dossier: {
groupe_instructeur_id: dossier.groupe_instructeur_id,
champs_attributes: [
{
id: first_champ.id,
@ -826,7 +853,7 @@ describe Users::DossiersController, type: :controller do
context "with PDF output" do
let(:procedure) { create(:procedure) }
let(:dossier) {
let(:dossier) do
create(:dossier,
:accepte,
:with_all_champs,
@ -834,7 +861,8 @@ describe Users::DossiersController, type: :controller do
:with_commentaires,
procedure: procedure,
user: user)
}
end
subject! { get(:show, params: { id: dossier.id, format: :pdf }) }
context 'when the dossier is a brouillon' do

View file

@ -19,7 +19,7 @@ FactoryBot.define do
# Assign the procedure to the dossier through the groupe_instructeur
if dossier.groupe_instructeur.nil?
dossier.groupe_instructeur = procedure.defaut_groupe_instructeur
dossier.groupe_instructeur = procedure.routee? ? nil : procedure.defaut_groupe_instructeur
end
dossier.build_default_individual
@ -117,6 +117,7 @@ FactoryBot.define do
trait :en_construction do
after(:create) do |dossier, _evaluator|
dossier.state = Dossier.states.fetch(:en_construction)
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
dossier.en_construction_at ||= dossier.created_at + 1.minute
dossier.save!
end
@ -125,6 +126,7 @@ FactoryBot.define do
trait :en_instruction do
after(:create) do |dossier, _evaluator|
dossier.state = Dossier.states.fetch(:en_instruction)
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
dossier.en_construction_at ||= dossier.created_at + 1.minute
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
dossier.save!
@ -139,6 +141,7 @@ FactoryBot.define do
after(:create) do |dossier, evaluator|
dossier.state = Dossier.states.fetch(:accepte)
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
processed_at = evaluator.processed_at
if processed_at.present?
dossier.en_construction_at ||= processed_at - 2.minutes
@ -156,6 +159,7 @@ FactoryBot.define do
trait :refuse do
after(:create) do |dossier, _evaluator|
dossier.state = Dossier.states.fetch(:refuse)
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
dossier.en_construction_at ||= dossier.created_at + 1.minute
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
dossier.traitements.build(state: Dossier.states.fetch(:refuse), processed_at: dossier.en_instruction_at + 1.minute)
@ -166,6 +170,7 @@ FactoryBot.define do
trait :sans_suite do
after(:create) do |dossier, _evaluator|
dossier.state = Dossier.states.fetch(:sans_suite)
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
dossier.en_construction_at ||= dossier.created_at + 1.minute
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
dossier.traitements.build(state: Dossier.states.fetch(:sans_suite), processed_at: dossier.en_instruction_at + 1.minute)

View file

@ -733,8 +733,8 @@ describe ProcedurePresentation do
let!(:gi_2) { procedure.groupe_instructeurs.create(label: 'gi2') }
let!(:gi_3) { procedure.groupe_instructeurs.create(label: 'gi3') }
let!(:kept_dossier) { create(:dossier, procedure: procedure) }
let!(:discarded_dossier) { create(:dossier, procedure: procedure, groupe_instructeur: gi_2) }
let!(:kept_dossier) { create(:dossier, :en_construction, procedure: procedure) }
let!(:discarded_dossier) { create(:dossier, :en_construction, procedure: procedure, groupe_instructeur: gi_2) }
it { is_expected.to contain_exactly(kept_dossier.id) }

View file

@ -603,6 +603,7 @@ describe Procedure do
Timecop.freeze(now) do
procedure.publish_or_reopen!(administrateur)
end
procedure.reload
canonical_procedure.reload
end
@ -1054,7 +1055,7 @@ describe Procedure do
end
context 'with a new brouillon dossier' do
let!(:brouillon_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:brouillon)) }
let!(:brouillon_dossier) { create(:dossier, procedure: procedure) }
it { expect(subject['a_suivre']).to eq(0) }
it { expect(subject['suivis']).to eq(0) }
@ -1064,7 +1065,7 @@ describe Procedure do
end
context 'with a new dossier without follower' do
let!(:new_unfollow_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
let!(:new_unfollow_dossier) { create(:dossier, :en_instruction, procedure: procedure) }
it { expect(subject['a_suivre']).to eq(1) }
it { expect(subject['suivis']).to eq(0) }
@ -1073,8 +1074,8 @@ describe Procedure do
it { expect(subject['archived']).to eq(0) }
context 'and dossiers without follower on each of the others groups' do
let!(:new_unfollow_dossier_on_gi_2) { create(:dossier, groupe_instructeur: gi_2, state: Dossier.states.fetch(:en_instruction)) }
let!(:new_unfollow_dossier_on_gi_3) { create(:dossier, groupe_instructeur: gi_3, state: Dossier.states.fetch(:en_instruction)) }
let!(:new_unfollow_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2) }
let!(:new_unfollow_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3) }
before { subject }
@ -1084,7 +1085,7 @@ describe Procedure do
end
context 'with a new dossier with a follower' do
let!(:new_followed_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
let!(:new_followed_dossier) { create(:dossier, :en_instruction, procedure: procedure) }
before do
instructeur.followed_dossiers << new_followed_dossier
@ -1097,8 +1098,8 @@ describe Procedure do
it { expect(subject['archived']).to eq(0) }
context 'and dossier with a follower on each of the others groups' do
let!(:new_follow_dossier_on_gi_2) { create(:dossier, groupe_instructeur: gi_2, state: Dossier.states.fetch(:en_instruction)) }
let!(:new_follow_dossier_on_gi_3) { create(:dossier, groupe_instructeur: gi_3, state: Dossier.states.fetch(:en_instruction)) }
let!(:new_follow_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2) }
let!(:new_follow_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3) }
before do
instructeur.followed_dossiers << new_follow_dossier_on_gi_2 << new_follow_dossier_on_gi_3
@ -1121,7 +1122,7 @@ describe Procedure do
end
context 'with a termine dossier' do
let!(:termine_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:accepte)) }
let!(:termine_dossier) { create(:dossier, :accepte, procedure: procedure) }
it { expect(subject['a_suivre']).to eq(0) }
it { expect(subject['suivis']).to eq(0) }
@ -1130,8 +1131,8 @@ describe Procedure do
it { expect(subject['archived']).to eq(0) }
context 'and terminer dossiers on each of the others groups' do
let!(:termine_dossier_on_gi_2) { create(:dossier, groupe_instructeur: gi_2, state: Dossier.states.fetch(:accepte)) }
let!(:termine_dossier_on_gi_3) { create(:dossier, groupe_instructeur: gi_3, state: Dossier.states.fetch(:accepte)) }
let!(:termine_dossier_on_gi_2) { create(:dossier, :accepte, groupe_instructeur: gi_2) }
let!(:termine_dossier_on_gi_3) { create(:dossier, :accepte, groupe_instructeur: gi_3) }
before { subject }
@ -1144,7 +1145,7 @@ describe Procedure do
end
context 'with an archived dossier' do
let!(:archived_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true) }
let!(:archived_dossier) { create(:dossier, :en_instruction, procedure: procedure, archived: true) }
it { expect(subject['a_suivre']).to eq(0) }
it { expect(subject['suivis']).to eq(0) }
@ -1153,8 +1154,8 @@ describe Procedure do
it { expect(subject['archived']).to eq(1) }
context 'and terminer dossiers on each of the others groups' do
let!(:archived_dossier_on_gi_2) { create(:dossier, groupe_instructeur: gi_2, state: Dossier.states.fetch(:en_instruction), archived: true) }
let!(:archived_dossier_on_gi_3) { create(:dossier, groupe_instructeur: gi_3, state: Dossier.states.fetch(:en_instruction), archived: true) }
let!(:archived_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2, archived: true) }
let!(:archived_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3, archived: true) }
it { expect(subject['archived']).to eq(2) }
end

View file

@ -63,10 +63,21 @@ describe 'shared/dossiers/champs.html.haml', type: :view do
let(:dossier) { create(:dossier, procedure: procedure) }
let(:champs) { [] }
it "does not render the routing criteria name and its value" do
expect(subject).not_to include(procedure.routing_criteria_name)
expect(subject).not_to include(dossier.procedure.defaut_groupe_instructeur.label)
end
context "with selected groupe instructeur" do
before do
dossier.groupe_instructeur = dossier.procedure.defaut_groupe_instructeur
end
it "renders the routing criteria name and its value" do
expect(subject).to include(procedure.routing_criteria_name)
expect(subject).to include(dossier.groupe_instructeur.label)
end
end
context "with seen_at" do
let(:dossier) { create(:dossier) }

View file

@ -96,9 +96,19 @@ describe 'shared/dossiers/edit.html.haml', type: :view do
let(:dossier) { create(:dossier, procedure: procedure) }
let(:champs) { [] }
it 'renders the routing criteria name and its value' do
expect(subject).to have_field(procedure.routing_criteria_name)
end
context 'when groupe instructeur is selected' do
before do
dossier.groupe_instructeur = dossier.procedure.defaut_groupe_instructeur
end
it 'renders the routing criteria name and its value' do
expect(subject).to have_field(procedure.routing_criteria_name)
expect(subject).to include(dossier.groupe_instructeur.label)
end
end
end
end

View file

@ -2806,10 +2806,10 @@ bluebird@^3.5.0, bluebird@^3.5.5:
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.4.0:
version "4.11.9"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.9.tgz#26d556829458f9d1e81fc48952493d0ba3507828"
integrity sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.9:
version "4.12.0"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88"
integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==
bn.js@^5.1.1:
version "5.1.1"
@ -2894,7 +2894,7 @@ braces@^3.0.1, braces@~3.0.2:
dependencies:
fill-range "^7.0.1"
brorand@^1.0.1:
brorand@^1.0.1, brorand@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f"
integrity sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=
@ -4779,17 +4779,17 @@ elf-tools@^1.1.1:
integrity sha512-x+p+XNxLk8ittsYN7294mCnQ2i48udu3UGdHBv2gw1u1MVigXctcfbp5H9ebqTJnDxkbs6PdOSBOAdYGGDN7uA==
elliptic@^6.0.0, elliptic@^6.5.2:
version "6.5.3"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.3.tgz#cb59eb2efdaf73a0bd78ccd7015a62ad6e0f93d6"
integrity sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==
version "6.5.4"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb"
integrity sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==
dependencies:
bn.js "^4.4.0"
brorand "^1.0.1"
bn.js "^4.11.9"
brorand "^1.1.0"
hash.js "^1.0.0"
hmac-drbg "^1.0.0"
inherits "^2.0.1"
minimalistic-assert "^1.0.0"
minimalistic-crypto-utils "^1.0.0"
hmac-drbg "^1.0.1"
inherits "^2.0.4"
minimalistic-assert "^1.0.1"
minimalistic-crypto-utils "^1.0.1"
email-butler@^1.0.13:
version "1.0.13"
@ -6428,7 +6428,7 @@ highlight-words-core@1.2.2:
resolved "https://registry.yarnpkg.com/highlight-words-core/-/highlight-words-core-1.2.2.tgz#1eff6d7d9f0a22f155042a00791237791b1eeaaa"
integrity sha512-BXUKIkUuh6cmmxzi5OIbUJxrG8OAk2MqoL1DtO3Wo9D2faJg2ph5ntyuQeLqaHJmzER6H5tllCDA9ZnNe9BVGg==
hmac-drbg@^1.0.0:
hmac-drbg@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
integrity sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=
@ -8252,7 +8252,7 @@ minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1:
resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7"
integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==
minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1:
minimalistic-crypto-utils@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a"
integrity sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=