From 3b513af32a4ccff63513f437ddd2dcc372eca317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chai=CC=88b=20Martinez?= Date: Thu, 30 May 2019 19:20:45 +0200 Subject: [PATCH 1/5] Add nb_of_dossiers by years and deadline to PipeDrive Person MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chaïb Martinez --- app/lib/pipedrive/person_adapter.rb | 12 +++++++++--- app/services/pipedrive_service.rb | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/lib/pipedrive/person_adapter.rb b/app/lib/pipedrive/person_adapter.rb index a6289bb90..fe225fd33 100644 --- a/app/lib/pipedrive/person_adapter.rb +++ b/app/lib/pipedrive/person_adapter.rb @@ -1,6 +1,8 @@ class Pipedrive::PersonAdapter PIPEDRIVE_POSTE_ATTRIBUTE_ID = '33a790746f1713d712fe97bcce9ac1ca6374a4d6' PIPEDRIVE_SOURCE_ATTRIBUTE_ID = '2fa7864f467ffa97721cbcd08df5a3d591b15f50' + PIPEDRIVE_NB_DOSSIERS_ATTRIBUTE_ID = '2734a3ff19f4b88bd0d7b4cf02c47c7545617207' + PIPEDRIVE_DEADLINE_ATTRIBUTE_ID = 'ef766dd14de7da246fb5fc1704f45d1f1830f6c9' PIPEDRIVE_ROBOT_ID = '2748449' def self.get_demandes_from_persons_owned_by_robot @@ -11,7 +13,9 @@ class Pipedrive::PersonAdapter poste: datum[PIPEDRIVE_POSTE_ATTRIBUTE_ID], email: datum.dig('email', 0, 'value'), tel: datum.dig('phone', 0, 'value'), - organisation: datum['org_name'] + organisation: datum['org_name'], + nb_dossiers: datum[PIPEDRIVE_NB_DOSSIERS_ATTRIBUTE_ID], + deadline: datum[PIPEDRIVE_DEADLINE_ATTRIBUTE_ID] } end end @@ -22,7 +26,7 @@ class Pipedrive::PersonAdapter Pipedrive::API.put_person(person_id, params) end - def self.add_person(email, phone, name, organization_id, poste, source) + def self.add_person(email, phone, name, organization_id, poste, source, nb_of_dossiers, deadline) params = { email: email, phone: phone, @@ -30,7 +34,9 @@ class Pipedrive::PersonAdapter org_id: organization_id, owner_id: PIPEDRIVE_ROBOT_ID, "#{PIPEDRIVE_POSTE_ATTRIBUTE_ID}": poste, - "#{PIPEDRIVE_SOURCE_ATTRIBUTE_ID}": source + "#{PIPEDRIVE_SOURCE_ATTRIBUTE_ID}": source, + "#{PIPEDRIVE_NB_DOSSIERS_ATTRIBUTE_ID}": nb_of_dossiers, + "#{PIPEDRIVE_DEADLINE_ATTRIBUTE_ID}": deadline } response = Pipedrive::API.post_person(params) diff --git a/app/services/pipedrive_service.rb b/app/services/pipedrive_service.rb index ecd9b8a17..33b80f68e 100644 --- a/app/services/pipedrive_service.rb +++ b/app/services/pipedrive_service.rb @@ -19,7 +19,7 @@ class PipedriveService def self.add_demande(email, phone, name, poste, source, organization_name, address, nb_of_procedures, nb_of_dossiers, deadline) organization_id = Pipedrive::OrganizationAdapter.add_organization(organization_name, address) - person_id = Pipedrive::PersonAdapter.add_person(email, phone, name, organization_id, poste, source) + person_id = Pipedrive::PersonAdapter.add_person(email, phone, name, organization_id, poste, source, nb_of_dossiers, deadline) Pipedrive::DealAdapter.add_deal(organization_id, person_id, organization_name, nb_of_procedures, nb_of_dossiers, deadline) end end From 9198f7f43776ba2010456598628eeaccaf37118b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chai=CC=88b=20Martinez?= Date: Thu, 30 May 2019 19:21:48 +0200 Subject: [PATCH 2/5] Remove useless select options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chaïb Martinez --- app/views/manager/demandes/index.html.erb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/views/manager/demandes/index.html.erb b/app/views/manager/demandes/index.html.erb index 9703d5fdb..173185b86 100644 --- a/app/views/manager/demandes/index.html.erb +++ b/app/views/manager/demandes/index.html.erb @@ -34,13 +34,7 @@ <%= form_tag(manager_demandes_create_administrateur_path) do -%> <%= select_tag "stage_id", options_for_select({ - "suspect" => Pipedrive::DealAdapter::PIPEDRIVE_SUSPECTS_COMPTE_CREE_STAGE_ID, - "administration centrale" => Pipedrive::DealAdapter::PIPEDRIVE_ADMIN_CENTRAL_STOCK_STAGE_ID, - "service déco. régional" => Pipedrive::DealAdapter::PIPEDRIVE_SERVICE_DECO_REGIONAL_STOCK_STAGE_ID, - "service déco. départemental" => Pipedrive::DealAdapter::PIPEDRIVE_SERVICE_DECO_DEPARTEMENTAL_STOCK_STAGE_ID, - "collectivité dép. ou rég." =>Pipedrive::DealAdapter::PIPEDRIVE_COLLECTIVITE_DEP_OU_REG_STOCK_STAGE_ID, - "collectivité locale" => Pipedrive::DealAdapter::PIPEDRIVE_COLLECTIVITE_LOCALE_STOCK_STAGE_ID, - "organisme" => Pipedrive::DealAdapter::PIPEDRIVE_ORGANISMES_STOCK_STAGE_ID + "suspect" => Pipedrive::DealAdapter::PIPEDRIVE_SUSPECTS_COMPTE_CREE_STAGE_ID }), style: 'margin-bottom: 20px; width: inherit;' %> From 5a216b558345c0c23bd3f3c8020ff4b78b3713a1 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 4 Jun 2019 17:59:02 +0200 Subject: [PATCH 3/5] Fix default button type fix #3924 --- app/views/shared/dossiers/editable_champs/_repetition.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/dossiers/editable_champs/_repetition.html.haml b/app/views/shared/dossiers/editable_champs/_repetition.html.haml index 7f25613da..9184d8590 100644 --- a/app/views/shared/dossiers/editable_champs/_repetition.html.haml +++ b/app/views/shared/dossiers/editable_champs/_repetition.html.haml @@ -7,7 +7,7 @@ = form.hidden_field :_destroy, disabled: true .flex.row-reverse - if champ.persisted? - %button.button.danger.remove-row + %button.button.danger.remove-row{ type: :button } Supprimer - else %button.button.danger{ type: :button } From eccd456325e72385b186ad95d89dc019f2207591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chai=CC=88b=20Martinez?= Date: Wed, 15 May 2019 14:15:48 +0200 Subject: [PATCH 4/5] Add crisp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chaïb Martinez --- app/controllers/application_controller.rb | 16 ++++++++++ .../packs/{sendinblue.js => track-admin.js} | 1 + app/javascript/shared/track/crisp.js | 32 +++++++++++++++++++ app/views/layouts/application.html.haml | 2 +- app/views/layouts/application_old.html.haml | 2 +- config/env.example | 3 ++ config/secrets.yml | 5 +++ 7 files changed, 59 insertions(+), 2 deletions(-) rename app/javascript/packs/{sendinblue.js => track-admin.js} (53%) create mode 100644 app/javascript/shared/track/crisp.js diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c87f47a4d..df168b7c1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -96,6 +96,7 @@ class ApplicationController < ActionController::Base if administrateur_signed_in? gon.sendinblue = sendinblue_config + gon.crisp = crisp_config end end @@ -239,6 +240,21 @@ class ApplicationController < ActionController::Base } end + def crisp_config + crisp = Rails.application.secrets.crisp + + { + key: crisp[:client_key], + enabled: crisp[:enabled], + administrateur: { + email: current_administrateur&.email, + DS_SIGN_IN_COUNT: current_administrateur&.sign_in_count, + DS_CREATED_AT: current_administrateur&.created_at, + DS_ID: current_administrateur&.id + } + } + end + def current_email current_user&.email || current_gestionnaire&.email || diff --git a/app/javascript/packs/sendinblue.js b/app/javascript/packs/track-admin.js similarity index 53% rename from app/javascript/packs/sendinblue.js rename to app/javascript/packs/track-admin.js index 01e9b8317..3ea9c4765 100644 --- a/app/javascript/packs/sendinblue.js +++ b/app/javascript/packs/track-admin.js @@ -1 +1,2 @@ import '../shared/track/sendinblue'; +import '../shared/track/crisp'; diff --git a/app/javascript/shared/track/crisp.js b/app/javascript/shared/track/crisp.js new file mode 100644 index 000000000..a016a1ab2 --- /dev/null +++ b/app/javascript/shared/track/crisp.js @@ -0,0 +1,32 @@ +const { key, enabled, administrateur } = gon.crisp || {}; + +if (enabled) { + window.$crisp = []; + window.CRISP_WEBSITE_ID = key; + + const script = document.createElement('script'); + const firstScript = document.getElementsByTagName('script')[0]; + script.type = 'text/javascript'; + script.id = 'crisp-js'; + script.async = true; + script.src = 'https://client.crisp.chat/l.js'; + firstScript.parentNode.insertBefore(script, firstScript); + + window.$crisp.push(['set', 'user:email', [administrateur.email]]); + window.$crisp.push(['set', 'session:segments', [['administrateur']]]); + window.$crisp.push([ + 'set', + 'session:data', + [ + [ + ['DS_ID', administrateur.email], + ['DS_SIGN_IN_COUNT', administrateur.DS_SIGN_IN_COUNT], + [ + 'URL_MANAGER', + 'https://www.demarches-simplifiees.fr/manager/administrateurs/' + + administrateur.DS_ID + ] + ] + ] + ]); +} diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 2eb205c1a..456ebfb5c 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -14,7 +14,7 @@ = favicon_link_tag(image_url("favicons/32x32.png"), type: "image/png", sizes: "32x32") = favicon_link_tag(image_url("favicons/96x96.png"), type: "image/png", sizes: "96x96") - - packs = ['application', 'track', administrateur_signed_in? ? 'sendinblue' : nil].compact + - packs = ['application', 'track', administrateur_signed_in? ? 'track-admin' : nil].compact = javascript_packs_with_chunks_tag *packs, defer: true, 'data-turbolinks-track': 'reload' = stylesheet_link_tag 'new_design/new_application', media: 'all', 'data-turbolinks-track': 'reload' = stylesheet_link_tag 'new_design/print', media: 'print', 'data-turbolinks-track': 'reload' diff --git a/app/views/layouts/application_old.html.haml b/app/views/layouts/application_old.html.haml index 043342b4d..ce233e5f3 100644 --- a/app/views/layouts/application_old.html.haml +++ b/app/views/layouts/application_old.html.haml @@ -12,7 +12,7 @@ = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': "reload" = stylesheet_link_tag 'print', media: 'print', 'data-turbolinks-track': "reload" - - packs = ['application-old', 'track', administrateur_signed_in? ? 'sendinblue' : nil].compact + - packs = ['application-old', 'track', administrateur_signed_in? ? 'track-admin' : nil].compact = javascript_packs_with_chunks_tag *packs, defer: true, 'data-turbolinks-track': 'reload' = javascript_include_tag 'application', defer: true, 'data-turbolinks-track': 'reload' = csrf_meta_tags diff --git a/config/env.example b/config/env.example index 0c2473e18..b1aa41f94 100644 --- a/config/env.example +++ b/config/env.example @@ -46,6 +46,9 @@ MATOMO_ENABLED="disabled" MATOMO_ID="73" SENDINBLUE_ENABLED="disabled" +SENDINBLUE_CLIENT_KEY="" +CRISP_ENABLED="disabled" +CRISP_CLIENT_KEY="" MAILTRAP_ENABLED="disabled" MAILTRAP_USERNAME="" diff --git a/config/secrets.yml b/config/secrets.yml index 9a035f676..9a74a71cc 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -61,6 +61,11 @@ defaults: &defaults enabled: <%= ENV['SENTRY_ENABLED'] == 'enabled' %> client_key: <%= ENV['SENTRY_DSN_JS'] %> environment: <%= ENV['SENTRY_CURRENT_ENV'] %> + crisp: + enabled: <%= ENV['CRISP_ENABLED'] == 'enabled' %> + client_key: <%= ENV['CRISP_CLIENT_KEY'] %> + + development: <<: *defaults From 0b49e61ec0ae2034e115be217affc76d406696e9 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 6 Jun 2019 09:09:17 +0000 Subject: [PATCH 5/5] tasks: repair updated_at of dossiers wrongly touched by PJ migration When running the PJ migration task, migrated dossiers have their updated_at attribute modified. This means a yellow notification badge pops up on the Instructeurs pages. This PR repairs the affected dossiers, by restoring an approximative updated_at from the latest workflow value (or the timestamp of the migrated champ). --- ...6_fix_timestamps_of_migrated_dossiers.rake | 19 ++++++++ ...ix_timestamps_of_migrated_dossiers_spec.rb | 48 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 lib/tasks/2019_06_06_fix_timestamps_of_migrated_dossiers.rake create mode 100644 spec/lib/tasks/2019_06_06_fix_timestamps_of_migrated_dossiers_spec.rb diff --git a/lib/tasks/2019_06_06_fix_timestamps_of_migrated_dossiers.rake b/lib/tasks/2019_06_06_fix_timestamps_of_migrated_dossiers.rake new file mode 100644 index 000000000..42688fa49 --- /dev/null +++ b/lib/tasks/2019_06_06_fix_timestamps_of_migrated_dossiers.rake @@ -0,0 +1,19 @@ +require Rails.root.join("lib", "tasks", "task_helper") + +namespace :fix_timestamps_of_migrated_dossiers do + desc 'Fix the timestamps of dossiers affected by the faulty PJ migration' + task run: :environment do + affected_time_range = Time.utc(2019, 6, 4, 8, 0)..Time.utc(2019, 6, 4, 18, 0) + dossiers = Dossier.unscoped.where(procedure_id: 0..1000).where(updated_at: affected_time_range) + + progress = ProgressReport.new(dossiers.count) + + dossiers.find_each do |dossier| + fixed_updated_at = dossier.processed_at || dossier.en_instruction_at || dossier.en_construction_at || dossier.champs.last.updated_at || nil + dossier.update_column(:updated_at, fixed_updated_at) + + progress.inc + end + progress.finish + end +end diff --git a/spec/lib/tasks/2019_06_06_fix_timestamps_of_migrated_dossiers_spec.rb b/spec/lib/tasks/2019_06_06_fix_timestamps_of_migrated_dossiers_spec.rb new file mode 100644 index 000000000..4661eaf72 --- /dev/null +++ b/spec/lib/tasks/2019_06_06_fix_timestamps_of_migrated_dossiers_spec.rb @@ -0,0 +1,48 @@ +describe '2019_06_06_fix_timestamps_of_migrated_dossiers' do + let(:affected_procedure) { create(:simple_procedure, id: 500) } + let(:procedure_outside_range) { create(:simple_procedure, id: 5000) } + + let(:affected_dossier) { create(:dossier, procedure: affected_procedure) } + let(:dossier_outside_time_range) { create(:dossier, procedure: affected_procedure) } + let(:dossier_outside_procedure_range) { create(:dossier, procedure: procedure_outside_range) } + + let(:creation_time) { Time.utc(2017, 1, 1, 12, 0) } + let(:en_construction_time) { Time.utc(2018, 1, 1, 12, 0) } + let(:pj_migration_time) { Time.utc(2019, 6, 4, 12, 0) } + + let(:rake_task) { Rake::Task['fix_timestamps_of_migrated_dossiers:run'] } + + before do + Timecop.freeze(creation_time) do + affected_dossier + dossier_outside_time_range + dossier_outside_procedure_range + end + Timecop.freeze(en_construction_time) do + affected_dossier.update_column(:en_construction_at, Time.zone.now) + end + Timecop.freeze(pj_migration_time.prev_week) do + dossier_outside_time_range.tap(&:touch).reload + end + Timecop.freeze(pj_migration_time) do + dossier_outside_procedure_range.tap(&:touch).reload + affected_dossier.tap(&:touch).reload + end + + rake_task.invoke + end + + after { rake_task.reenable } + + it 'fix the updated_at of affected dossiers' do + expect(affected_dossier.reload.updated_at).to eq(en_construction_time) + end + + it 'ignores dossiers with a procedure_id outside of the procedure range' do + expect(dossier_outside_procedure_range.reload.updated_at).to eq(pj_migration_time) + end + + it 'ignores dossiers with an updated_at outside of the time range' do + expect(dossier_outside_time_range.reload.updated_at).to eq(pj_migration_time.prev_week) + end +end