-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'staging' into rdv-solidarites-oauth
- Loading branch information
Showing
59 changed files
with
1,593 additions
and
485 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class FranceTravailClient | ||
def self.create_participation(payload:, headers:) | ||
Faraday.post( | ||
"#{ENV['FRANCE_TRAVAIL_API_URL']}/partenaire/rendez-vous-partenaire/v1/rendez-vous", | ||
payload.to_json, | ||
headers | ||
) | ||
end | ||
|
||
def self.update_participation(payload:, headers:) | ||
Faraday.put( | ||
"#{ENV['FRANCE_TRAVAIL_API_URL']}/partenaire/rendez-vous-partenaire/v1/rendez-vous", | ||
payload.to_json, | ||
headers | ||
) | ||
end | ||
|
||
def self.delete_participation(france_travail_id:, headers:) | ||
Faraday.delete( | ||
"#{ENV['FRANCE_TRAVAIL_API_URL']}/partenaire/rendez-vous-partenaire/v1/rendez-vous/#{france_travail_id}", | ||
{}, | ||
headers | ||
) | ||
end | ||
|
||
def self.retrieve_user_token(payload:, headers:) | ||
Faraday.post( | ||
"#{ENV['FRANCE_TRAVAIL_API_URL']}/partenaire/rechercher-usager/v2/usagers/par-datenaissance-et-nir", | ||
payload.to_json, | ||
headers | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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); | ||
this.handleFirstVisit(); | ||
} | ||
|
||
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); | ||
} | ||
} | ||
|
||
handleFirstVisit() { | ||
const firstVisit = localStorage.getItem("crispFirstVisit"); | ||
if (!firstVisit) { | ||
window.$crisp.push(["on", "session:loaded", () => { | ||
window.$crisp.push(["do", "chat:open"]); | ||
localStorage.setItem("crispFirstVisit", "true"); | ||
}]); | ||
} | ||
} | ||
|
||
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"]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module OutgoingWebhooks | ||
module FranceTravail | ||
class BaseJob < ApplicationJob | ||
include LockedAndOrderedJobs | ||
|
||
discard_on FranceTravailApi::RetrieveUserToken::UserNotFound | ||
|
||
def self.lock_key(participation_id:, **) | ||
"#{base_lock_key}:#{participation_id}" | ||
end | ||
|
||
def self.job_timestamp(timestamp:, **) | ||
timestamp | ||
end | ||
end | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
app/jobs/outgoing_webhooks/france_travail/create_participation_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module OutgoingWebhooks | ||
module FranceTravail | ||
class CreateParticipationJob < BaseJob | ||
def perform(participation_id:, timestamp:) | ||
call_service!(FranceTravailApi::CreateParticipation, participation_id: participation_id, timestamp: timestamp) | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
app/jobs/outgoing_webhooks/france_travail/delete_participation_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module OutgoingWebhooks | ||
module FranceTravail | ||
class DeleteParticipationJob < BaseJob | ||
def perform(participation_id:, france_travail_id:, user_id:, timestamp:) | ||
call_service!(FranceTravailApi::DeleteParticipation, | ||
participation_id: participation_id, | ||
france_travail_id: france_travail_id, | ||
user_id: user_id, timestamp: timestamp) | ||
end | ||
end | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
app/jobs/outgoing_webhooks/france_travail/update_participation_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module OutgoingWebhooks | ||
module FranceTravail | ||
class UpdateParticipationJob < BaseJob | ||
def perform(participation_id:, timestamp:) | ||
call_service!(FranceTravailApi::UpdateParticipation, participation_id: participation_id, timestamp: timestamp) | ||
end | ||
end | ||
end | ||
end |
10 changes: 0 additions & 10 deletions
10
app/jobs/outgoing_webhooks/send_france_travail_webhook_job.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
app/models/concerns/participation/france_travail_payload.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
module Participation::FranceTravailPayload | ||
extend ActiveSupport::Concern | ||
|
||
# rubocop:disable Metrics/AbcSize | ||
def to_ft_payload | ||
{ | ||
id: france_travail_id, | ||
adresse: address, | ||
date: starts_at.to_datetime, | ||
duree: duration_in_min, | ||
information: motif.instruction_for_rdv, | ||
initiateur: france_travail_initiateur, | ||
libelleAdresse: organisation.name, | ||
modaliteContact: france_travail_modalite, | ||
motif: france_travail_motif, | ||
organisme: { | ||
code: france_travail_organisme_code, | ||
emailContact: organisation.email, | ||
idStructure: organisation.safir_code, | ||
libelleStructure: organisation.name, | ||
telephoneContact: organisation.phone_number | ||
}, | ||
statut: france_travail_statut, | ||
telephoneContactUsager: user.phone_number, | ||
theme: motif.name, | ||
typeReception: france_travail_type_reception, | ||
interlocuteur: { | ||
email: agents.first.email, | ||
nom: agents.first.last_name, | ||
prenom: agents.first.first_name | ||
} | ||
} | ||
end | ||
# rubocop:enable Metrics/AbcSize | ||
|
||
private | ||
|
||
# Liste des modalités FT (on ne prend en compte que le physique et le telephone): PHYSIQUE, TELEPHONE, VISIO | ||
def france_travail_modalite | ||
by_phone? ? "TELEPHONE" : "PHYSIQUE" | ||
end | ||
|
||
# Liste des initiateurs FT : USAGER, PARTENAIRE | ||
def france_travail_initiateur | ||
created_by_user? ? "USAGER" : "PARTENAIRE" | ||
end | ||
|
||
# Liste des motifs FT : AUT, ACC, ORI | ||
def france_travail_motif | ||
case motif.motif_category&.motif_category_type | ||
when "rsa_orientation" | ||
"ORI" | ||
when "rsa_accompagnement" | ||
"ACC" | ||
else | ||
"AUT" | ||
end | ||
end | ||
|
||
# Liste des codes organismes FT : IND, FT, CD, DCD, ML, CE | ||
def france_travail_organisme_code | ||
case organisation.organisation_type | ||
when "conseil_departemental" | ||
"CD" | ||
when "france_travail" | ||
"FT" | ||
when "delegataire_rsa" | ||
"DCD" | ||
else | ||
"IND" | ||
end | ||
end | ||
|
||
# Liste des types de réception FT : COL, IND | ||
def france_travail_type_reception | ||
collectif? ? "COL" : "IND" | ||
end | ||
|
||
# Liste des statuts FT : PRIS, EFFECTUE, MODIFIE, ABSENT, ANNULE | ||
def france_travail_statut | ||
case status | ||
when "seen" | ||
"EFFECTUE" | ||
when "excused", "revoked" | ||
"ANNULE" | ||
when "noshow" | ||
"ABSENT" | ||
else | ||
"PRIS" | ||
end | ||
end | ||
end |
Oops, something went wrong.