Skip to content

Commit

Permalink
Merge pull request #1230 from StartupsPoleEmploi/dev
Browse files Browse the repository at this point in the history
feat: maj logos + favicon + corrige souci connexion
  • Loading branch information
JulienPerrin authored Apr 2, 2024
2 parents 035db00 + cf48f42 commit 2768901
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 143 deletions.
5 changes: 3 additions & 2 deletions backend/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
"client_id": "client_id",
"client_secret": "client_secret",
"callback_url": "http://127.0.0.1:8080/peconnect/callback",
"issuer_url": "https://authentification-candidat.pole-emploi.fr:443/connexion/oauth2",
"api_url": "https://api.emploi-store.fr/partenaire/peconnect-individu/v1/userinfo",
"issuer_url": "https://authentification-candidat.francetravail.fr/connexion/oauth2/realms/root/realms/individu",
"endpoint": "https://authentification-candidat.francetravail.fr/connexion/oauth2",
"api_url": "https://api.francetravail.io/partenaire/peconnect-individu/v1/userinfo",
"timeout": 1000
},
"sentry": {
Expand Down
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test": "npm run test:unit && npm run test:integration",
"test:unit": "mocha --recursive --exit --timeout 5000 test/unit",
"test:integration": "npm run db:memory:stop; npm run db:memory:start && ANOTEA_MONGODB_URI=mongodb://127.0.0.1:27018/anotea?w=1 mocha --recursive --exit --timeout 5000 test/integration",
"test:integration:log": "ANOTEA_LOG_LEVEL=error npm run db:memory:stop; npm run db:memory:start && ANOTEA_MONGODB_URI=mongodb://127.0.0.1:27018/anotea?w=1 mocha --recursive --exit --timeout 5000 test/integration",
"test:integration:log": "npm run db:memory:stop; npm run db:memory:start && ANOTEA_LOG_LEVEL=error ANOTEA_MONGODB_URI=mongodb://127.0.0.1:27018/anotea?w=1 mocha --recursive --exit --timeout 5000 test/integration",
"test:coverage": "nyc --reporter=html --reporter=text-summary mocha --recursive --exit --timeout 5000 test",
"test:all": "npm run db:memory:stop; npm run db:memory:start && ANOTEA_MONGODB_URI=mongodb://127.0.0.1:27018/anotea?w=1 npm run test",
"lint": "eslint src test",
Expand Down
15 changes: 11 additions & 4 deletions backend/src/core/components/peconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ module.exports = (db, configuration) => {

let clientId = configuration.peconnect.client_id;
let issuerUrl = configuration.peconnect.issuer_url;
let endpoint = configuration.peconnect.endpoint;
let callbackUrl = configuration.peconnect.callback_url;

let issuer = new Issuer({
issuer: issuerUrl,
jwks_uri: `https://entreprise.francetravail.fr/connexion/oauth2/connect/jwk_uri`,
authorization_endpoint: `${issuerUrl}/authorize`,
token_endpoint: `${issuerUrl}/access_token?realm=/individu`,
jwks_uri: `${endpoint}/connect/jwk_uri`,
authorization_endpoint: `${endpoint}/authorize`,
token_endpoint: `${endpoint}/access_token?realm=/individu`,
token_endpoint_auth_methods_supported: 'client_secret_post',
userinfo_endpoint: configuration.peconnect.api_url,
});
Expand Down Expand Up @@ -54,7 +55,13 @@ module.exports = (db, configuration) => {
throw new BadDataError('Unable to find PE connect token');
}

let tokenSet = await client.callback(callbackUrl, params, { state: auth.state, nonce: auth.nonce });
let tokenSet;
try {
tokenSet = await client.callback(callbackUrl, params, { state: auth.state, nonce: auth.nonce });
} catch (e) {
console.error('getUserInfo', e);
throw e;
}

return await client.userinfo(tokenSet.access_token);
},
Expand Down
1 change: 1 addition & 0 deletions backend/src/http/site/pages-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module.exports = ({ db, configuration, communes, peconnect }) => {
db.collection('stagiaires').updateOne({ _id: stagiaire._id }, { $set: { 'tracking.peConnectSucceed': new Date() } });
return res.redirect(`${configuration.app.public_hostname}/questionnaire/${stagiaire.token}`);
} catch (e) {
console.error(e);
return res.status(500).render('errors/error');
}
});
Expand Down
Binary file modified backend/src/http/site/static/images/favicon.ico
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable camelcase */
/* eslint-disable max-statements-per-line */
const uuid = require('node-uuid');
const _ = require('lodash');
const { promiseAll } = require('../../../job-utils');
Expand All @@ -10,6 +12,41 @@ module.exports = async (db, logger) => {
invalid: 0,
};

const findCodeRegionResponsable = organisme_formation_responsable => {
if (!organisme_formation_responsable ||
!organisme_formation_responsable.coordonnees_organisme ||
!organisme_formation_responsable.coordonnees_organisme.coordonnees ||
!organisme_formation_responsable.coordonnees_organisme.coordonnees.adresse ||
!organisme_formation_responsable.coordonnees_organisme.coordonnees.adresse.region) {
return '11';
}

let lieu = organisme_formation_responsable.coordonnees_organisme.coordonnees.adresse.region;
switch (lieu) {
case '26': lieu = '27'; break;
case '43': lieu = '27'; break;
case '23': lieu = '28'; break;
case '25': lieu = '28'; break;
case '22': lieu = '32'; break;
case '31': lieu = '32'; break;
case '21': lieu = '44'; break;
case '41': lieu = '44'; break;
case '42': lieu = '44'; break;
case '54': lieu = '75'; break;
case '72': lieu = '75'; break;
case '74': lieu = '75'; break;
case '73': lieu = '76'; break;
case '91': lieu = '76'; break;
case '82': lieu = '84'; break;
case '83': lieu = '84'; break;
case '93': lieu = '93'; break;
case '94': lieu = '94'; break;
default: break;
}

return lieu;
};

const getOrganismesFromIntercarif = async () => {
let accumulator = {};

Expand All @@ -25,9 +62,9 @@ module.exports = async (db, logger) => {
&& organisme_formation_responsable.siret_organisme_formation.siret !== '0') {
let siret = organisme_formation_responsable.siret_organisme_formation.siret;
let hasCourriel = undefined;
if (organisme_formation_responsable
&& organisme_formation_responsable.coordonnees_organisme
&& organisme_formation_responsable.coordonnees_organisme.coordonnees
if (organisme_formation_responsable
&& organisme_formation_responsable.coordonnees_organisme
&& organisme_formation_responsable.coordonnees_organisme.coordonnees
&& organisme_formation_responsable.coordonnees_organisme.coordonnees.courriel)
hasCourriel = !!(organisme_formation_responsable.coordonnees_organisme.coordonnees.courriel);

Expand Down Expand Up @@ -63,40 +100,6 @@ module.exports = async (db, logger) => {
return Object.values(accumulator);
};

const findCodeRegionResponsable = organisme_formation_responsable => {
if (!organisme_formation_responsable
|| !organisme_formation_responsable.coordonnees_organisme
|| !organisme_formation_responsable.coordonnees_organisme.coordonnees
|| !organisme_formation_responsable.coordonnees_organisme.coordonnees.adresse
|| !organisme_formation_responsable.coordonnees_organisme.coordonnees.adresse.region) {
throw new Error(`Unable to find region for organisme ${organisme_formation_responsable.siret_organisme_formation.siret}`);
}

let lieu = organisme_formation_responsable.coordonnees_organisme.coordonnees.adresse.region;
switch (lieu) {
case '26': lieu = '27'; break;
case '43': lieu = '27'; break;
case '23': lieu = '28'; break;
case '25': lieu = '28'; break;
case '22': lieu = '32'; break;
case '31': lieu = '32'; break;
case '21': lieu = '44'; break;
case '41': lieu = '44'; break;
case '42': lieu = '44'; break;
case '54': lieu = '75'; break;
case '72': lieu = '75'; break;
case '74': lieu = '75'; break;
case '73': lieu = '76'; break;
case '91': lieu = '76'; break;
case '82': lieu = '84'; break;
case '83': lieu = '84'; break;
case '93': lieu = '93'; break;
case '94': lieu = '94'; break;
}

return lieu;
};

const synchronizeAccount = async data => {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module.exports = async (db, logger) => {
let lieu = data.lieux_de_formation.find(lieu => lieu.coordonnees.adresse.region);

if (!lieu) {
throw new Error(`Unable to find region for organisme ${data.organisme_formateur.siret_formateur.siret}`);
return '11';
}

let codeRegion = lieu.coordonnees.adresse.region;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe(__filename, withServer(({ startServer, insertIntoDatabase, logAsFinance
assert.strictEqual(response.body.avis[0].qualification, 'positif');

response = await request(app)
.get('/api/backoffice/avis?qualification=négatif')
.get('/api/backoffice/avis?qualification=n%C3%A9gatif')
.set('authorization', `Bearer ${token}`);
assert.strictEqual(response.statusCode, 200);
assert.strictEqual(response.body.avis.length, 1);
Expand Down
23 changes: 0 additions & 23 deletions backend/test/integration/http/api/questionnaire-routes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ describe(__filename, withServer(({ startServer, getTestDatabase, insertIntoDatab

assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(_.omit(response.body.stagiaire, ['_id', 'token']), {
campaign: 'test-campaign',
importDate: date.toJSON(),
avisCreated: false,
refreshKey: '667debb89cf76c83816e5f9dbc7c808e',
individu: {
nom: 'Dupont',
prenom: 'Henri',
email: 'henri@email.fr',
telephones: [
'0123456789',
'NULL'
],
emailValid: true,
identifiant_pe: '1111111111'
},
formation: {
numero: 'F_XX_XX',
intitule: 'Développeur',
Expand Down Expand Up @@ -79,14 +64,6 @@ describe(__filename, withServer(({ startServer, getTestDatabase, insertIntoDatab
},
},
},
unsubscribe: false,
mailSent: true,
mailSentDate: date.toJSON(),
tracking: {
firstRead: date.toJSON()
},
codeRegion: '11',
dispositifFinancement: 'AIF',
});

assert.deepStrictEqual(_.omit(response.body.infosRegion, ['stagiaire']), {
Expand Down
40 changes: 0 additions & 40 deletions backend/test/integration/http/site/emails-routes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,6 @@ const { newStagiaire, newOrganismeAccount } = require('../../../helpers/data/dat


describe(__filename, withServer(({ startServer, getTestDatabase, insertIntoDatabase }) => {

it('should update tracking informations in stagiaires', async () => {

let app = await startServer();
let db = await getTestDatabase();
let stagiaire = newStagiaire({
tracking: {
firstRead: new Date(),
}
});
await insertIntoDatabase('stagiaires', stagiaire);

let response = await request(app).get(`/emails/stagiaires/${stagiaire.token}/track`);

assert.strictEqual(response.statusCode, 200);

let result = await db.collection('stagiaires').findOne({ token: stagiaire.token });

assert.deepStrictEqual(stagiaire.token, result.token);
assert.ok(result.tracking.firstRead);
assert.ok(result.tracking.lastRead);
});

it('should update tracking informations in organismes', async () => {

let app = await startServer();
let db = await getTestDatabase();
let account = newOrganismeAccount();
await insertIntoDatabase('accounts', account);

let response = await request(app).get(`/emails/organismes/${account.token}/track`);

assert.strictEqual(response.statusCode, 200);

let result = await db.collection('accounts').findOne({ token: account.token });

assert.deepStrictEqual(account.token, result.token);
assert.ok(result.tracking.firstRead);
});

it('can unsubscribe', async () => {

let app = await startServer();
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ui",
"version": "1.0.0",
"description": "Anotea: Accédez aux avis des anciens stagiaires pour mieux choisir sa formation !",
"homepage": "https://anotea.pole-emploi.fr/backoffice",
"homepage": "https://anotea.francetravail.fr/backoffice",
"repository": {
"type": "git",
"url": "git@github.com:StartupsPoleEmploi/anotea.git"
Expand Down
Binary file modified ui/public/favicon.ico
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2768901

Please sign in to comment.