From af4a27f4e0269b63aa06e3925064edadbc3d949d Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Sun, 7 Mar 2021 22:47:24 +0100 Subject: [PATCH 01/14] add claimant type on avis table --- app/models/avis.rb | 1 + db/migrate/20210307143807_add_claimant_type_to_avis.rb | 6 ++++++ db/schema.rb | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20210307143807_add_claimant_type_to_avis.rb diff --git a/app/models/avis.rb b/app/models/avis.rb index ba410c41f..1db5f026b 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -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 diff --git a/db/migrate/20210307143807_add_claimant_type_to_avis.rb b/db/migrate/20210307143807_add_claimant_type_to_avis.rb new file mode 100644 index 000000000..64b1769a9 --- /dev/null +++ b/db/migrate/20210307143807_add_claimant_type_to_avis.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 12e8fcf65..f2bafeffb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" From 0211d1f105e749c0f041497b7bb2f5701c09b7da Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Sun, 7 Mar 2021 22:47:53 +0100 Subject: [PATCH 02/14] modify create_avis_concern --- app/controllers/concerns/create_avis_concern.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/concerns/create_avis_concern.rb b/app/controllers/concerns/create_avis_concern.rb index ef54d7b2d..3b711733e 100644 --- a/app/controllers/concerns/create_avis_concern.rb +++ b/app/controllers/concerns/create_avis_concern.rb @@ -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 From 0870ebfd905c73a340edb0be454a7f93b686dcb7 Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Sun, 7 Mar 2021 22:48:12 +0100 Subject: [PATCH 03/14] After party backfill claimant type on avis table --- ..._backfill_claimant_type_on_avis_table.rake | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake diff --git a/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake b/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake new file mode 100644 index 000000000..9d1b0dcbf --- /dev/null +++ b/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake @@ -0,0 +1,39 @@ +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'" + + with_dossiers = Avis.where(claimant_type: nil).includes(claimant: :assign_to).where.not(claimant: { assign_tos: { id: nil } }) + with_dossiers.update_all(claimant_type: 'Instructeur') + + without_dossiers = Avis.where(claimant_type: nil).includes(claimant: :assign_to).where(claimant: { assign_tos: { id: nil } }) + without_dossiers.find_each do |avis| + claimant = Instructeur.find(avis.claimant_id).user + instructeur = Instructeur.find(avis.instructeur) if 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 From 1644c9d44b342eb0416307379f9e770aa165bc46 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 9 Mar 2021 11:02:22 +0100 Subject: [PATCH 04/14] Another attempt at fixing IE --- config/webpack/environment.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/webpack/environment.js b/config/webpack/environment.js index d689af6dd..deb5c4c44 100644 --- a/config/webpack/environment.js +++ b/config/webpack/environment.js @@ -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'); From f4fd220d43fec737ed212320569288268c17a468 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Tue, 9 Mar 2021 13:40:10 +0100 Subject: [PATCH 05/14] Revert "Claimant type to avis table" --- .../concerns/create_avis_concern.rb | 1 - app/models/avis.rb | 1 - ...0210307143807_add_claimant_type_to_avis.rb | 6 --- db/schema.rb | 4 +- ..._backfill_claimant_type_on_avis_table.rake | 39 ------------------- 5 files changed, 2 insertions(+), 49 deletions(-) delete mode 100644 db/migrate/20210307143807_add_claimant_type_to_avis.rb delete mode 100644 lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake diff --git a/app/controllers/concerns/create_avis_concern.rb b/app/controllers/concerns/create_avis_concern.rb index 3b711733e..ef54d7b2d 100644 --- a/app/controllers/concerns/create_avis_concern.rb +++ b/app/controllers/concerns/create_avis_concern.rb @@ -27,7 +27,6 @@ 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 diff --git a/app/models/avis.rb b/app/models/avis.rb index 1db5f026b..ba410c41f 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -4,7 +4,6 @@ # # id :integer not null, primary key # answer :text -# claimant_type :string # confidentiel :boolean default(FALSE), not null # email :string # introduction :text diff --git a/db/migrate/20210307143807_add_claimant_type_to_avis.rb b/db/migrate/20210307143807_add_claimant_type_to_avis.rb deleted file mode 100644 index 64b1769a9..000000000 --- a/db/migrate/20210307143807_add_claimant_type_to_avis.rb +++ /dev/null @@ -1,6 +0,0 @@ -class AddClaimantTypeToAvis < ActiveRecord::Migration[6.0] - def change - add_column :avis, :claimant_type, :string - remove_foreign_key :avis, :instructeurs, column: "claimant_id" - end -end diff --git a/db/schema.rb b/db/schema.rb index f2bafeffb..12e8fcf65 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_03_07_143807) do +ActiveRecord::Schema.define(version: 2021_02_04_180955) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -122,7 +122,6 @@ ActiveRecord::Schema.define(version: 2021_03_07_143807) 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" @@ -730,6 +729,7 @@ ActiveRecord::Schema.define(version: 2021_03_07_143807) 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" diff --git a/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake b/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake deleted file mode 100644 index 9d1b0dcbf..000000000 --- a/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake +++ /dev/null @@ -1,39 +0,0 @@ -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'" - - with_dossiers = Avis.where(claimant_type: nil).includes(claimant: :assign_to).where.not(claimant: { assign_tos: { id: nil } }) - with_dossiers.update_all(claimant_type: 'Instructeur') - - without_dossiers = Avis.where(claimant_type: nil).includes(claimant: :assign_to).where(claimant: { assign_tos: { id: nil } }) - without_dossiers.find_each do |avis| - claimant = Instructeur.find(avis.claimant_id).user - instructeur = Instructeur.find(avis.instructeur) if 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 From d04d9ea5d8dc1cdfe3d57b9f89f9b6414f7afa95 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 9 Mar 2021 11:06:53 +0100 Subject: [PATCH 06/14] Remove circle ci config --- .circleci/config.yml | 152 ------------------------------------------- 1 file changed, 152 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 8b83a90de..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -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 From f87efe967000b5dd1dfb209c23ec9f527aa018e3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 9 Mar 2021 13:20:03 +0000 Subject: [PATCH 07/14] build(deps): bump elliptic from 6.5.3 to 6.5.4 Bumps [elliptic](https://github.com/indutny/elliptic) from 6.5.3 to 6.5.4. - [Release notes](https://github.com/indutny/elliptic/releases) - [Commits](https://github.com/indutny/elliptic/compare/v6.5.3...v6.5.4) Signed-off-by: dependabot[bot] --- yarn.lock | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/yarn.lock b/yarn.lock index c7e2d22d0..92310f7e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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= From 9c3e72c84a2759d2a82a6955e8c07408bb70ef39 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 9 Mar 2021 11:21:25 +0100 Subject: [PATCH 08/14] Use revision instead of groupe instructeur as dossier procedure link --- app/controllers/instructeurs/avis_controller.rb | 4 ++-- .../mutations/dossier_changer_groupe_instructeur.rb | 2 +- app/models/avis.rb | 5 +---- app/models/dossier.rb | 8 ++++---- app/services/administrateur_usage_statistics_service.rb | 4 ++-- app/views/commencer/show.html.haml | 2 +- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index 2e552b707..f44da58cf 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -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 diff --git a/app/graphql/mutations/dossier_changer_groupe_instructeur.rb b/app/graphql/mutations/dossier_changer_groupe_instructeur.rb index 0109d00aa..11a21db8f 100644 --- a/app/graphql/mutations/dossier_changer_groupe_instructeur.rb +++ b/app/graphql/mutations/dossier_changer_groupe_instructeur.rb @@ -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}' n’appartient pas à la même démarche que le dossier"] } else true diff --git a/app/models/avis.rb b/app/models/avis.rb index ba410c41f..a571f44fa 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -22,6 +22,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 +80,6 @@ class Avis < ApplicationRecord ] end - def procedure - dossier.procedure - end - def revoked? revoked_at.present? end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 4796b18f0..0845e9059 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -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 @@ -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 diff --git a/app/services/administrateur_usage_statistics_service.rb b/app/services/administrateur_usage_statistics_service.rb index d00de6cb0..3c46a6ab0 100644 --- a/app/services/administrateur_usage_statistics_service.rb +++ b/app/services/administrateur_usage_statistics_service.rb @@ -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' diff --git a/app/views/commencer/show.html.haml b/app/views/commencer/show.html.haml index 81c357f55..7abafdd4a 100644 --- a/app/views/commencer/show.html.haml +++ b/app/views/commencer/show.html.haml @@ -11,7 +11,7 @@ = link_to 'J’ai 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) From 70500e3d565b615619246ce8a84d2c53ae0ec2d3 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 9 Mar 2021 11:21:30 +0100 Subject: [PATCH 09/14] Groupe instructeur selector default blank --- app/controllers/users/dossiers_controller.rb | 25 +++++++++-- app/models/dossier.rb | 6 +-- app/models/procedure.rb | 6 +++ app/views/shared/dossiers/_edit.html.haml | 12 +---- .../procedures_controller_spec.rb | 32 +++++-------- .../users/dossiers_controller_spec.rb | 45 +++++++++++++++---- spec/factories/dossier.rb | 7 ++- spec/models/procedure_presentation_spec.rb | 4 +- spec/models/procedure_spec.rb | 27 +++++------ .../shared/dossiers/_champs.html.haml_spec.rb | 17 +++++-- .../shared/dossiers/_edit.html.haml_spec.rb | 12 ++++- 11 files changed, 124 insertions(+), 69 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 21d93ef9f..486682003 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -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 diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 0845e9059..368e4ef6e 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -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 @@ -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? diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 65037a387..37c97e980 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -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 diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index 290d91e6f..dc8d31118 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -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 diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index 7e5f2e561..eddbdeef4 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -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 diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 5c81263f7..22621ec48 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -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,19 +419,44 @@ 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) } - let!(:dossier) { create(:dossier, groupe_instructeur: dossier_group, user: user) } - before do - allow(DossierMailer).to receive(:notify_new_dossier_depose_to_instructeur).and_return(double(deliver_later: nil)) - create(:assign_to, instructeur: instructeur_of_dossier, procedure: dossier.procedure, instant_email_dossier_notifications_enabled: true, groupe_instructeur: dossier_group) - create(:assign_to, instructeur: instructeur_in_another_group, procedure: dossier.procedure, instant_email_dossier_notifications_enabled: true, groupe_instructeur: another_group) + context "and grope instructeur is set" do + let!(:dossier) { create(:dossier, groupe_instructeur: dossier_group, user: user) } + + before do + allow(DossierMailer).to receive(:notify_new_dossier_depose_to_instructeur).and_return(double(deliver_later: nil)) + create(:assign_to, instructeur: instructeur_of_dossier, procedure: dossier.procedure, instant_email_dossier_notifications_enabled: true, groupe_instructeur: dossier_group) + create(:assign_to, instructeur: instructeur_in_another_group, procedure: dossier.procedure, instant_email_dossier_notifications_enabled: true, groupe_instructeur: another_group) + end + + it "sends notification mail to instructeurs in the correct group instructeur" do + subject + + expect(DossierMailer).to have_received(:notify_new_dossier_depose_to_instructeur).once.with(dossier, instructeur_of_dossier.email) + expect(DossierMailer).not_to have_received(:notify_new_dossier_depose_to_instructeur).with(dossier, instructeur_in_another_group.email) + end end - it "sends notification mail to instructeurs in the correct group instructeur" do - subject + 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 - expect(DossierMailer).to have_received(:notify_new_dossier_depose_to_instructeur).once.with(dossier, instructeur_of_dossier.email) - expect(DossierMailer).not_to have_received(:notify_new_dossier_depose_to_instructeur).with(dossier, instructeur_in_another_group.email) + it "can not submit" do + subject + + expect(flash.alert).to eq(['Le champ « Votre ville » doit être rempli']) + end end end @@ -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, diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 4ec2e572e..29d01759b 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -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) diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 6d600bfb1..1949fb4b9 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -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) } diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index f767a1fce..273527ea6 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -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 diff --git a/spec/views/shared/dossiers/_champs.html.haml_spec.rb b/spec/views/shared/dossiers/_champs.html.haml_spec.rb index 14fedde0b..a441f7ef5 100644 --- a/spec/views/shared/dossiers/_champs.html.haml_spec.rb +++ b/spec/views/shared/dossiers/_champs.html.haml_spec.rb @@ -63,9 +63,20 @@ describe 'shared/dossiers/champs.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 include(procedure.routing_criteria_name) - expect(subject).to include(dossier.groupe_instructeur.label) + 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 diff --git a/spec/views/shared/dossiers/_edit.html.haml_spec.rb b/spec/views/shared/dossiers/_edit.html.haml_spec.rb index 531f2d32c..4935c3024 100644 --- a/spec/views/shared/dossiers/_edit.html.haml_spec.rb +++ b/spec/views/shared/dossiers/_edit.html.haml_spec.rb @@ -98,7 +98,17 @@ describe 'shared/dossiers/edit.html.haml', type: :view do 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 + + 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 From 00d7c3186a89f88b9593564db01be1704f4a2e98 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 9 Mar 2021 12:12:28 +0100 Subject: [PATCH 10/14] fix indentation --- .../users/dossiers_controller_spec.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 22621ec48..1bd747264 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -853,15 +853,16 @@ describe Users::DossiersController, type: :controller do context "with PDF output" do let(:procedure) { create(:procedure) } - let(:dossier) { - create(:dossier, - :accepte, - :with_all_champs, - :with_motivation, - :with_commentaires, - procedure: procedure, - user: user) -} + let(:dossier) do + create(:dossier, + :accepte, + :with_all_champs, + :with_motivation, + :with_commentaires, + procedure: procedure, + user: user) + end + subject! { get(:show, params: { id: dossier.id, format: :pdf }) } context 'when the dossier is a brouillon' do From 5bf499baa00c2da1db94740a5497ef467114fdc1 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 9 Mar 2021 14:47:58 +0100 Subject: [PATCH 11/14] specs: remove rspec_junit_formatter It was unsed by CircleCI to generate test reports in the JUnit XML format, but: - We now use Github Actions, which has its own reporting system, - It prevents us to upgrade to rspec > 3. --- Gemfile | 1 - Gemfile.lock | 3 --- 2 files changed, 4 deletions(-) diff --git a/Gemfile b/Gemfile index 228b0de16..14898ae50 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 081650c09..1c3bcc5d0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -588,8 +588,6 @@ GEM 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 From 4c3fcfeec272b112c50375d12ed2ffa703e995b3 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 9 Mar 2021 14:48:47 +0100 Subject: [PATCH 12/14] specs: upgrade to rspec 5 Rspec 5 is compatible with Rails 6.1. --- Gemfile.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1c3bcc5d0..74145f600 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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,10 +579,10 @@ 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) From 6383e6b9e7fdc9898c7a7ced5da5972144e9b822 Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Tue, 9 Mar 2021 15:39:51 +0100 Subject: [PATCH 13/14] Revert "Revert "Claimant type to avis table"" This reverts commit f4fd220d43fec737ed212320569288268c17a468. --- .../concerns/create_avis_concern.rb | 1 + app/models/avis.rb | 1 + ...0210307143807_add_claimant_type_to_avis.rb | 6 +++ db/schema.rb | 4 +- ..._backfill_claimant_type_on_avis_table.rake | 39 +++++++++++++++++++ 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20210307143807_add_claimant_type_to_avis.rb create mode 100644 lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake diff --git a/app/controllers/concerns/create_avis_concern.rb b/app/controllers/concerns/create_avis_concern.rb index ef54d7b2d..3b711733e 100644 --- a/app/controllers/concerns/create_avis_concern.rb +++ b/app/controllers/concerns/create_avis_concern.rb @@ -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 diff --git a/app/models/avis.rb b/app/models/avis.rb index a571f44fa..3d3cbf598 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -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 diff --git a/db/migrate/20210307143807_add_claimant_type_to_avis.rb b/db/migrate/20210307143807_add_claimant_type_to_avis.rb new file mode 100644 index 000000000..64b1769a9 --- /dev/null +++ b/db/migrate/20210307143807_add_claimant_type_to_avis.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 12e8fcf65..f2bafeffb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake b/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake new file mode 100644 index 000000000..9d1b0dcbf --- /dev/null +++ b/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake @@ -0,0 +1,39 @@ +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'" + + with_dossiers = Avis.where(claimant_type: nil).includes(claimant: :assign_to).where.not(claimant: { assign_tos: { id: nil } }) + with_dossiers.update_all(claimant_type: 'Instructeur') + + without_dossiers = Avis.where(claimant_type: nil).includes(claimant: :assign_to).where(claimant: { assign_tos: { id: nil } }) + without_dossiers.find_each do |avis| + claimant = Instructeur.find(avis.claimant_id).user + instructeur = Instructeur.find(avis.instructeur) if 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 From 53ba442235d6d5c6d1b7c8e7fa899960064b697c Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Tue, 9 Mar 2021 15:41:46 +0100 Subject: [PATCH 14/14] fix after party task --- ...144755_backfill_claimant_type_on_avis_table.rake | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake b/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake index 9d1b0dcbf..9b9790853 100644 --- a/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake +++ b/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake @@ -3,13 +3,20 @@ namespace :after_party do 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.update_all(claimant_type: 'Instructeur') + + ((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 = Instructeur.find(avis.claimant_id).user - instructeur = Instructeur.find(avis.instructeur) if avis.instructeur + 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)