From a8f3277a34918a4daeb37d7724ee476df41a0b4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20Villeneuve?=
<4990201+Michaelvilleneuve@users.noreply.github.com>
Date: Wed, 22 Jan 2025 16:53:52 +0100
Subject: [PATCH 1/7] fix(teleprocedure): change wording (#2582)
---
app/views/website/teleprocedure_landings/_13.html.erb | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/app/views/website/teleprocedure_landings/_13.html.erb b/app/views/website/teleprocedure_landings/_13.html.erb
index febd66f91..a8c9b36e4 100644
--- a/app/views/website/teleprocedure_landings/_13.html.erb
+++ b/app/views/website/teleprocedure_landings/_13.html.erb
@@ -1,6 +1,5 @@
-
Si vous résidez dans l’une des 29 communes listées ci-dessous, vous êtes concerné par une expérimentation du Conseil départemental des Bouches-du-Rhône visant à faciliter votre prise de rendez-vous RSA.
-À la suite de votre demande de RSA, un email et/ou un SMS va vous être transmis par le Conseil départemental pour fixer un premier rendez-vous d’orientation. Veuillez cliquer sur le lien contenu dans ce mail/SMS pour choisir un créneau à votre convenance.
-
-Communes concernées : Marseille - 2e arrondissement, Marseille - 3e arrondissement, Arles, Aureille, Barbentane, Baux-de-Provence, Boulbon, Cabannes, Chateaurenard, Eygalières, Eyragues, Fontvieille, Graveson, Maillane, Mas-Blanc-des-Alpilles, Maussane-les-Alpilles, Saint-Pierre-de-Mézoargues, Molleges, Mouries, Noves, Orgon, Paradou, Plan-d'Orgon, Rognonas, Saint-Andiol, Saint-Etienne-du-Gres, Saintes-Maries-de-la-Mer, Saint-Martin-de-Crau, Saint-Rémy-de-Provence, Tarascon, Verquieres.
-
-Si vous ne résidez pas dans l’une des 29 communes listées ci-dessus, vous n’êtes pas concerné par ces modalités de prise de rendez-vous et serez convié à votre rendez-vous d’orientation par courrier postal avec accusé de réception.
+Vous pouvez désormais choisir le jour et l’heure, les plus appropriés à votre emploi du temps, pour rencontrer le conseiller d’orientation qui définira avec vous les démarches et actions à mettre en œuvre pour faciliter votre insertion.
+
+À la suite de votre demande de RSA, un email et/ou un SMS vous sera transmis par le Conseil départemental pour fixer votre premier rendez-vous d’orientation. Cliquez sur le lien contenu dans ce mail/SMS pour choisir un créneau à votre convenance.
+
+Simple, rapide, facile le service « RENDEZ-VOUS INSERTION » est disponible sur tous les Pôles d’insertion des Bouches-du- Rhône est accessible en un clic.
From ffef538eb2d4c224321a6e584368874f1618eb2c Mon Sep 17 00:00:00 2001
From: Neuville Romain
Date: Wed, 22 Jan 2025 17:29:04 +0100
Subject: [PATCH 2/7] feat(crisp): add crisp chatbox for connected agents
(#2561)
* feat(crisp): add crisp chatbox for connected agents
* use a stimulus controller only and a feature flag
* better naming
* apply Amines suggestions
---
.env.example | 3 +
app/controllers/application_controller.rb | 1 +
app/controllers/concerns/crisp_concern.rb | 18 ++++++
.../controllers/crisp_controller.js | 60 +++++++++++++++++++
app/models/agent.rb | 6 ++
app/views/common/_crisp.html.erb | 6 ++
app/views/layouts/_application_base.html.erb | 1 +
config/anonymizer.yml | 1 +
.../initializers/content_security_policy.rb | 3 +-
config/webpack/webpack.config.js | 1 +
...0250122135459_add_crisp_token_to_agents.rb | 13 ++++
db/schema.rb | 5 +-
12 files changed, 115 insertions(+), 3 deletions(-)
create mode 100644 app/controllers/concerns/crisp_concern.rb
create mode 100644 app/javascript/controllers/crisp_controller.js
create mode 100644 app/views/common/_crisp.html.erb
create mode 100644 db/migrate/20250122135459_add_crisp_token_to_agents.rb
diff --git a/.env.example b/.env.example
index e8143c161..ed7659211 100644
--- a/.env.example
+++ b/.env.example
@@ -52,3 +52,6 @@ CARNET_DE_BORD_API_SECRET=secret_api_token
DEPARTMENTS_WHERE_PARCOURS_DISABLED=44
ORGANISATION_IDS_WHERE_STATS_DISABLED=
+
+CRISP_WEBSITE_ID=change_me
+ENABLE_CRISP=true
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index a3e5039cd..159749c77 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -8,6 +8,7 @@ class ApplicationController < ActionController::Base
include EnvironmentsHelper
include TurboStreamConcern
include ModalAgreementsConcern
+ include CrispConcern
protect_from_forgery with: :exception
before_action :set_sentry_context
diff --git a/app/controllers/concerns/crisp_concern.rb b/app/controllers/concerns/crisp_concern.rb
new file mode 100644
index 000000000..9d954ce66
--- /dev/null
+++ b/app/controllers/concerns/crisp_concern.rb
@@ -0,0 +1,18 @@
+module CrispConcern
+ extend ActiveSupport::Concern
+
+ included do
+ before_action :should_display_crisp_chatbox, if: -> { request.get? }
+ end
+
+ private
+
+ def should_display_crisp_chatbox
+ if current_agent.nil? || agent_impersonated? || ENV["ENABLE_CRISP"] != "true"
+ @should_display_crisp_chatbox = false
+ return
+ end
+
+ @should_display_crisp_chatbox = true
+ end
+end
diff --git a/app/javascript/controllers/crisp_controller.js b/app/javascript/controllers/crisp_controller.js
new file mode 100644
index 000000000..8fd59f9ec
--- /dev/null
+++ b/app/javascript/controllers/crisp_controller.js
@@ -0,0 +1,60 @@
+import { Controller } from "@hotwired/stimulus";
+
+export default class extends Controller {
+ static values = {
+ displayCrisp: Boolean,
+ userEmail: String,
+ userNickname: String,
+ userCrispToken: String,
+ };
+
+ connect() {
+ if (!this.displayCrispValue) {
+ // If the user is logged out from the app but crisp is still loaded, we loggout the user from crisp
+ if (window.$crisp) { this.logout(); };
+ return;
+ }
+
+ if (window.CRISP_TOKEN_ID === this.userCrispTokenValue) {
+ // If the user is already logged in, we don't need to do anything
+ return;
+ }
+
+ const user = {
+ email: this.userEmailValue,
+ nickname: this.userNicknameValue,
+ crispToken: this.userCrispTokenValue,
+ };
+
+ this.initCrisp(user);
+ }
+
+ initCrisp(user) {
+ window.$crisp = [];
+ window.CRISP_WEBSITE_ID = process.env.CRISP_WEBSITE_ID;
+
+ if (user) {
+ window.CRISP_TOKEN_ID = user.crispToken;
+ window.$crisp.push(["set", "user:email", [user.email]]);
+ window.$crisp.push(["set", "user:nickname", [user.nickname]]);
+ }
+
+ if (!document.querySelector("script[src='https://client.crisp.chat/l.js']")) {
+ const crispScriptTag = document.createElement("script");
+ crispScriptTag.async = true;
+ crispScriptTag.src = "https://client.crisp.chat/l.js";
+
+ const firstScriptTag = document.getElementsByTagName("head")[0];
+ firstScriptTag.appendChild(crispScriptTag);
+ }
+ }
+
+ logout() {
+ if (window.$crisp) {
+ window.CRISP_TOKEN_ID = null;
+ window.$crisp.push(["do", "session:reset"]);
+ window.$crisp.push(["do", "session:destroy"]);
+ window.$crisp.push(["do", "chat:hide"]);
+ }
+ }
+}
diff --git a/app/models/agent.rb b/app/models/agent.rb
index 3a7e434fa..7cd732037 100644
--- a/app/models/agent.rb
+++ b/app/models/agent.rb
@@ -28,6 +28,8 @@ class Agent < ApplicationRecord
scope :super_admins, -> { where(super_admin: true) }
scope :with_last_name, -> { where.not(last_name: nil) }
+ before_create :generate_crisp_token
+
def delete_organisation(organisation)
organisations.delete(organisation)
save!
@@ -59,6 +61,10 @@ def with_rdv_solidarites_session(&)
private
+ def generate_crisp_token
+ self.crisp_token ||= SecureRandom.uuid
+ end
+
# This is to make sure an agent can't be set as super_admin through an agent creation or update in the app.
# To set an agent as superadmin a developer should use agent#update_column.
def cannot_save_as_super_admin
diff --git a/app/views/common/_crisp.html.erb b/app/views/common/_crisp.html.erb
new file mode 100644
index 000000000..e70618c02
--- /dev/null
+++ b/app/views/common/_crisp.html.erb
@@ -0,0 +1,6 @@
+
+ data-crisp-user-email-value="<%= current_agent&.email %>"
+ data-crisp-user-nickname-value="<%= current_agent&.to_s %>"
+ data-crisp-user-crisp-token-value="<%= current_agent&.crisp_token %>">
+
diff --git a/app/views/layouts/_application_base.html.erb b/app/views/layouts/_application_base.html.erb
index cff633731..90f533d50 100644
--- a/app/views/layouts/_application_base.html.erb
+++ b/app/views/layouts/_application_base.html.erb
@@ -29,6 +29,7 @@
<%= yield %>
<%= render 'common/accept_cgu_modal' if @should_display_accept_cgu %>
<%= render 'common/accept_dpa_modal' if @should_display_accept_dpa %>
+ <%= render 'common/crisp' %>
<%= render 'common/footer' %>