2019-06-06-01 (#3933)

2019-06-06-01
This commit is contained in:
Pierre de La Morinerie 2019-06-06 11:51:16 +02:00 committed by GitHub
commit c31da8bc63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 138 additions and 14 deletions

View file

@ -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 ||

View file

@ -1 +1,2 @@
import '../shared/track/sendinblue';
import '../shared/track/crisp';

View file

@ -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
]
]
]
]);
}

View file

@ -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)

View file

@ -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

View file

@ -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'

View file

@ -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

View file

@ -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;' %>

View file

@ -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 }

View file

@ -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=""

View file

@ -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

View file

@ -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

View file

@ -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