Skip to content

Commit

Permalink
Merge branch 'main' into fix-access-token-multi-route-use
Browse files Browse the repository at this point in the history
  • Loading branch information
remy-auricoste committed Dec 6, 2023
2 parents c64d4aa + 5335ff8 commit b8b35f8
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 160 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: ["javascript"]
language: ["javascript-typescript"]

steps:
- name: Checkout repository
Expand All @@ -53,3 +53,5 @@ jobs:

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
10 changes: 5 additions & 5 deletions .infra/ansible/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
chdir: /opt/app
cmd: "sudo /opt/app/tools/reload-proxy.sh"

- name: "Désactivation du mode maintenance"
shell:
chdir: /opt/app
cmd: "sudo /opt/app/tools/maintenance/maintenance-off.sh"

- name: "Verification des certificats SSL"
shell:
chdir: /opt/app
Expand Down Expand Up @@ -121,8 +126,3 @@
shell:
chdir: /opt/app
cmd: "sudo docker system prune --all --force"

- name: "Désactivation du mode maintenance"
shell:
chdir: /opt/app
cmd: "sudo /opt/app/tools/maintenance/maintenance-off.sh"
10 changes: 5 additions & 5 deletions .infra/docker-compose.preview-system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ services:

mongodb:
<<: *default
image: mongo:6.0.2-focal
image: mongo:6.0.11
hostname: mongodb
container_name: lba_mongodb
deploy:
Expand Down Expand Up @@ -72,7 +72,7 @@ services:
resources:
limits:
memory: 2g
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.6
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.15
environment:
- ES_JAVA_OPTS=-Xmx512m -Xms512m
- discovery.type=single-node
Expand Down Expand Up @@ -108,7 +108,7 @@ services:

smtp:
<<: *default
image: axllent/mailpit:v1.5.5
image: axllent/mailpit:v1.10.1
container_name: lba_smtp
ports:
- 1025:1025
Expand All @@ -126,7 +126,7 @@ services:

nodeexporter:
<<: *default
image: prom/node-exporter:v1.5.0
image: prom/node-exporter:v1.7.0
hostname: "{{host_name}}"
user: root
command:
Expand All @@ -150,7 +150,7 @@ services:

cadvisor:
<<: *default
image: gcr.io/cadvisor/cadvisor:v0.46.0
image: gcr.io/cadvisor/cadvisor:v0.47.2
hostname: "{{host_name}}"
privileged: true
devices:
Expand Down
4 changes: 2 additions & 2 deletions .infra/docker-compose.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ services:

metabase:
<<: *default
image: metabase/metabase:v0.46.6.4
image: metabase/metabase:v0.47.8
deploy:
<<: *deploy-default
resources:
Expand Down Expand Up @@ -122,7 +122,7 @@ services:

elasticsearch:
<<: *default
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.6
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.15
deploy:
<<: *deploy-default
resources:
Expand Down
3 changes: 2 additions & 1 deletion .infra/docker-compose.recette.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.8"

services:
smtp:
image: axllent/mailpit:v1.5.5
image: axllent/mailpit:v1.10.1
deploy:
resources:
limits:
Expand All @@ -29,6 +29,7 @@ services:
environment:
- MP_DATA_FILE=/data/mailpit.db
- MP_UI_AUTH_FILE=/auth
- MP_WEBROOT=/smtp/
logging:
driver: "fluentd"
options:
Expand Down
16 changes: 2 additions & 14 deletions .infra/files/configs/reverse_proxy/locations/70_smtp.conf.template
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
location ~ ^/smtp/(.*)$ {
location /smtp {
set $upstream http://smtp:8025;
proxy_pass $upstream/$1$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;

# Websocket configuration
# See:
# - https://www.nginx.com/blog/websocket-nginx/
# - https://github.com/mailhog/MailHog/issues/117
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
include includes/proxy.conf;
}
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.8"

services:
mongodb:
image: mongo:6.0.2-focal
image: mongo:6.0.11
restart: unless-stopped
hostname: mongodb
mem_limit: 5g
Expand All @@ -21,7 +21,7 @@ services:
start_period: 10s

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.6
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.15
container_name: lba_elasticsearch
environment:
- ES_JAVA_OPTS=-Xmx512m -Xms512m
Expand Down Expand Up @@ -55,7 +55,7 @@ services:
- lba_clamav_data:/var/lib/clamav

smtp:
image: axllent/mailpit:v1.5.5
image: axllent/mailpit:v1.10.1
restart: unless-stopped
ports:
- 1025:1025
Expand Down
8 changes: 7 additions & 1 deletion server/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ function createJobAction(name) {

program.command("db:validate").description("Validate Documents").option("-q, --queued", "Run job asynchronously", false).action(createJobAction("db:validate"))

program.command("fix-diffusible-companies").description("Clean companies not diffusible").action(createJobAction("fix-diffusible-companies"))
program
.command("fix-diffusible-companies")
.description("Clean companies not diffusible.")
.option("-c, --collection_list <string>", " <collection_list> est la liste des collections à réparer séparées par des ,")
.option("-q, --queued", "Run job asynchronously", false)
.action(createJobAction("fix-diffusible-companies"))

program.command("check-diffusible-companies").description("Check companies are diffusible").action(createJobAction("check-diffusible-companies"))
program.command("fiab:kevin").description("Run migrations up").action(createJobAction("fiab:kevin"))
program.command("db:obfuscate").description("Pseudonymisation des documents").option("-q, --queued", "Run job asynchronously", false).action(createJobAction("db:obfuscate"))
Expand Down
15 changes: 1 addition & 14 deletions server/src/http/controllers/metiers/metiers.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { zRoutes } from "shared/index.js"

import { getCoupleAppellationRomeIntitule, getMetiers, getMetiersPourCfd, getMetiersPourEtablissement, getTousLesMetiers } from "../../../services/metiers.service"
import { getCoupleAppellationRomeIntitule, getMetiers, getMetiersPourCfd, getTousLesMetiers } from "../../../services/metiers.service"
import { Server } from "../../server"

const config = {
Expand All @@ -24,19 +24,6 @@ export default (server: Server) => {
}
)

server.get(
"/v1/metiers/metiersParEtablissement/:siret",
{
schema: zRoutes.get["/v1/metiers/metiersParEtablissement/:siret"],
config,
},
async (req, res) => {
const { siret } = req.params
const result = await getMetiersPourEtablissement({ siret })
return res.send(result)
}
)

server.get(
"/v1/metiers/all",
{
Expand Down
112 changes: 109 additions & 3 deletions server/src/jobs/database/fixDiffusibleCompanies.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { setTimeout } from "timers/promises"

import Boom from "boom"
import { ILbaCompany } from "shared"
import { ILbaCompany, IRecruiter, IUserRecruteur, JOB_STATUS } from "shared"
import { EDiffusibleStatus } from "shared/constants/diffusibleStatus"
import { ETAT_UTILISATEUR, RECRUITER_STATUS, VALIDATION_UTILISATEUR } from "shared/constants/recruteur"

import { logger } from "@/common/logger"
import { Recruiter, UserRecruteur } from "@/common/model"
import { db } from "@/common/mongodb"
import { getEtablissementDiffusionStatus } from "@/services/etablissement.service"

const MAX_RETRY = 100
const DELAY = 100
const ANONYMIZED = "anonymized"

const getDiffusionStatus = async (siret: string, count = 1) => {
const isDiffusible = await getEtablissementDiffusionStatus(siret)
Expand Down Expand Up @@ -51,8 +54,111 @@ const fixLbaCompanies = async () => {
logger.info(`Fixing lba companies done`)
}

export async function fixDiffusibleCompanies(): Promise<void> {
await fixLbaCompanies()
const deactivateRecruiter = async (recruiter: IRecruiter) => {
console.log("deactivating non diffusible recruiter : ", recruiter.establishment_siret)
recruiter.status = RECRUITER_STATUS.ARCHIVE
recruiter.address = ANONYMIZED
recruiter.geo_coordinates = ANONYMIZED
recruiter.address_detail = recruiter.address_detail
? { status_diffusion: recruiter.address_detail.status_diffusion, libelle_commune: ANONYMIZED }
: { libelle_commune: ANONYMIZED }

for await (const job of recruiter.jobs) {
job.job_status = JOB_STATUS.ACTIVE ? JOB_STATUS.ANNULEE : job.job_status
}

await Recruiter.updateOne({ _id: recruiter._id }, { $set: { ...recruiter } })
}

const deactivateUserRecruteur = async (userRecruteur: IUserRecruteur) => {
console.log("deactivating non diffusible userRecruteur : ", userRecruteur.establishment_siret)

const userStatus = {
user: "SERVEUR",
validation_type: VALIDATION_UTILISATEUR.AUTO,
status: ETAT_UTILISATEUR.DESACTIVE,
reason: "Anonymization des données",
date: new Date(),
}
if (!userRecruteur.status) {
userRecruteur.status = []
}
userRecruteur.status.push(userStatus)

userRecruteur.address = ANONYMIZED
userRecruteur.geo_coordinates = ANONYMIZED

if (userRecruteur.address_detail) {
userRecruteur.address_detail = { libelle_commune: ANONYMIZED }
}

await UserRecruteur.updateOne({ _id: userRecruteur._id }, { $set: { ...userRecruteur } })
}

const fixRecruiters = async () => {
logger.info(`Fixing diffusible recruiters and offers`)
const recruiters: AsyncIterable<IRecruiter> = await db.collection("recruiters").find({})

let count = 0
let deactivatedCount = 0
let errorCount = 0
for await (const recruiter of recruiters) {
if (count % 100 === 0) {
logger.info(`${count} recruiters checked. ${deactivatedCount} removed. ${errorCount} errors`)
}
count++
try {
const isDiffusible = await getDiffusionStatus(recruiter.establishment_siret)

if (isDiffusible !== EDiffusibleStatus.DIFFUSIBLE) {
deactivateRecruiter(recruiter)

deactivatedCount++
}
} catch (err) {
errorCount++
console.log(err)
break
}
}

const userRecruteurs: AsyncIterable<IUserRecruteur> = await db.collection("userrecruteurs").find({})

count = 0
deactivatedCount = 0
errorCount = 0
for await (const userRecruteur of userRecruteurs) {
if (count % 100 === 0) {
logger.info(`${count} userRecruteurs checked. ${deactivatedCount} removed. ${errorCount} errors`)
}
count++
try {
const isDiffusible = userRecruteur.establishment_siret ? await getDiffusionStatus(userRecruteur.establishment_siret) : EDiffusibleStatus.NOT_FOUND

if (isDiffusible !== EDiffusibleStatus.DIFFUSIBLE) {
deactivateUserRecruteur(userRecruteur)

deactivatedCount++
}
} catch (err) {
errorCount++
console.log(err)
break
}
}
}

export async function fixDiffusibleCompanies(payload: { collection_list?: string }): Promise<void> {
const collectionList = payload?.collection_list ?? "lbacompanies,recruiters"
const list = collectionList.split(",")

if (list.includes("lbacompanies")) {
await fixLbaCompanies()
}

if (list.includes("recruiters")) {
await fixRecruiters()
}
}

export async function checkDiffusibleCompanies(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion server/src/jobs/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export async function runJob(job: IInternalJobsCronTask | IInternalJobsSimple):
case "mongodb:indexes:create":
return createMongoDBIndexes()
case "fix-diffusible-companies":
return fixDiffusibleCompanies()
return fixDiffusibleCompanies(job.payload)
case "check-diffusible-companies":
return checkDiffusibleCompanies()
case "db:validate":
Expand Down
12 changes: 0 additions & 12 deletions server/src/services/metiers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,6 @@ export const getMetiersPourCfd = async ({ cfd }: { cfd: string }): Promise<IMeti
return metiers
}

/**
* Récupère la liste des métiers associés à un établissement en paramètre identifié par son SIRET
* @param {string} siret
* @returns {Promise<IMetiers>}
*/
export const getMetiersPourEtablissement = async ({ siret }: { siret: string }): Promise<IMetiers> => {
const romeResponse = await getRomesFromCatalogue({ siret })
const { romes } = romeResponse
const metiers = await getMetiersFromRomes(romes)
return metiers
}

/**
* Récupère la liste des métiers dans la table domaines / métiers correspondant à un tableau de codes ROME
* @param {string[]} romes
Expand Down
Loading

0 comments on commit b8b35f8

Please sign in to comment.