Skip to content

Commit

Permalink
LBAC-1012: securisation routes (#784)
Browse files Browse the repository at this point in the history
* feat: securisation en cours

* fix: decode special chars

* fix: lean model

* chore: console removed

* feat: related resources added

---------

Co-authored-by: Alan Le Ruyet <[email protected]>
  • Loading branch information
rimiti and alanlr authored Nov 14, 2023
1 parent 9ff2417 commit 070fec0
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 19 deletions.
4 changes: 2 additions & 2 deletions server/src/http/routes/admin/etablissement.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default (server: Server) => {
onRequest: [server.auth(zRoutes.get["/admin/etablissements/siret-formateur/:siret"])],
},
async ({ params }, res) => {
const etablissement = await Etablissement.findOne({ formateur_siret: params.siret })
const etablissement = await Etablissement.findOne({ formateur_siret: params.siret }).lean()

if (!etablissement) {
throw Boom.notFound()
Expand All @@ -38,7 +38,7 @@ export default (server: Server) => {
onRequest: [server.auth(zRoutes.get["/admin/etablissements/:id"])],
},
async (req, res) => {
const etablissement = await Etablissement.findById(req.params.id)
const etablissement = await Etablissement.findById(req.params.id).lean()

if (!etablissement) {
throw Boom.notFound()
Expand Down
15 changes: 11 additions & 4 deletions server/src/http/routes/admin/formations.controller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Boom from "boom"
import { zRoutes } from "shared/index"

import { getCatalogueFormations } from "../../../services/catalogue.service"
Expand All @@ -19,12 +20,18 @@ export default (server: Server) => {
async (req, res) => {
const { search_item } = req.query

if (!search_item) {
throw Boom.badRequest("Invalid search_item.")
}

const searchItemDecoded = decodeURIComponent(search_item)

const response = await getCatalogueFormations({
$or: [
{ etablissement_formateur_siret: search_item },
{ etablissement_formateur_uai: search_item },
{ id_rco_formation: search_item },
{ cle_ministere_educatif: search_item },
{ etablissement_formateur_siret: searchItemDecoded },
{ etablissement_formateur_uai: searchItemDecoded },
{ id_rco_formation: searchItemDecoded },
{ cle_ministere_educatif: searchItemDecoded },
],
})

Expand Down
2 changes: 1 addition & 1 deletion shared/models/elligibleTraining.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const ZEligibleTrainingsForAppointmentSchema = z
etablissement_formateur_zip_code: ZEtablissement.shape.formateur_zip_code,
training_code_formation_diplome: z.string(),
lieu_formation_email: z.string().nullable(),
is_lieu_formation_email_customized: z.boolean().nullable(),
is_lieu_formation_email_customized: z.boolean().nullish(),
referrers: z.array(z.string()).default([]),
rco_formation_id: z.string().nullable(),
is_catalogue_published: z.boolean(),
Expand Down
16 changes: 14 additions & 2 deletions shared/routes/eligibleTrainingsForAppointment.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ export const zEligibleTrainingsForAppointmentRoutes = {
securityScheme: {
auth: "cookie-session",
access: "admin",
ressources: {},
ressources: {
eligibleTrainingsForAppointment: [
{
etablissement_formateur_siret: { type: "params", key: "siret" },
},
],
},
},
},
},
Expand All @@ -44,7 +50,13 @@ export const zEligibleTrainingsForAppointmentRoutes = {
securityScheme: {
auth: "cookie-session",
access: "admin",
ressources: {},
ressources: {
eligibleTrainingsForAppointment: [
{
_id: { type: "params", key: "id" },
},
],
},
},
},
},
Expand Down
32 changes: 23 additions & 9 deletions shared/routes/etablissement.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,37 @@ export const zEtablissementRoutes = {
path: "/admin/etablissements/siret-formateur/:siret",
params: z.object({ siret: extensions.siret }).strict(),
response: {
// TODO ANY TO BE FIXED
"2xx": z.any(),
// "2xx": ZEtablissement,
"2xx": ZEtablissement.strict(),
},
securityScheme: {
auth: "cookie-session",
access: "admin",
ressources: {},
ressources: {
eligibleTrainingsForAppointment: [
{
etablissement_formateur_siret: { type: "params", key: "siret" },
},
],
},
},
},
"/admin/etablissements/:id": {
method: "get",
path: "/admin/etablissements/:id",
params: z.object({ id: zObjectId }).strict(),
response: {
// TODO ANY TO BE FIXED
"2xx": z.any(),
// "2xx": ZEtablissement,
"2xx": ZEtablissement.strict(),
},
securityScheme: {
auth: "cookie-session",
access: "admin",
ressources: {},
ressources: {
etablissement: [
{
_id: { type: "params", key: "id" },
},
],
},
},
},
"/etablissements/:id": {
Expand Down Expand Up @@ -127,7 +135,13 @@ export const zEtablissementRoutes = {
securityScheme: {
auth: "cookie-session",
access: "admin",
ressources: {},
ressources: {
etablissement: [
{
_id: { type: "params", key: "id" },
},
],
},
},
},
"/etablissements/:id/appointments/:appointmentId": {
Expand Down
8 changes: 7 additions & 1 deletion shared/routes/formations.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ export const zFormationRoute = {
securityScheme: {
auth: "cookie-session",
access: "admin",
ressources: {},
ressources: {
formationCatalogue: [
{
cle_ministere_educatif: { type: "query", key: "search_item" },
},
],
},
},
},
},
Expand Down
14 changes: 14 additions & 0 deletions shared/security/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ export type AccessRessouces = {
opco: AccessResourcePath
}
>
eligibleTrainingsForAppointment?: ReadonlyArray<
| {
_id: AccessResourcePath
}
| {
etablissement_formateur_siret: AccessResourcePath
}
>
etablissement?: ReadonlyArray<{
_id: AccessResourcePath
}>
formationCatalogue?: ReadonlyArray<{
cle_ministere_educatif: AccessResourcePath
}>
job?: ReadonlyArray<{
_id: AccessResourcePath
}>
Expand Down

0 comments on commit 070fec0

Please sign in to comment.