-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGIFX] Corriger le téléchargement du profil cible lors du télécharg…
- Loading branch information
Showing
61 changed files
with
845 additions
and
510 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
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
5 changes: 0 additions & 5 deletions
5
api/lib/domain/usecases/get-learning-content-by-target-profile.js
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
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
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
49 changes: 49 additions & 0 deletions
49
api/src/prescription/target-profile/application/admin-target-profile-controller.js
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,49 @@ | ||
import { usecases } from '../domain/usecases/index.js'; | ||
import { tokenService } from '../../../shared/domain/services/token-service.js'; | ||
import { escapeFileName } from '../../../../lib/infrastructure/utils/request-response-utils.js'; | ||
import * as learningContentPDFPresenter from './presenter/pdf/learning-content-pdf-presenter.js'; | ||
import dayjs from 'dayjs'; | ||
|
||
const getContentAsJsonFile = async function (request, h, dependencies = { tokenService }) { | ||
const targetProfileId = request.params.id; | ||
const token = request.query.accessToken; | ||
const userId = dependencies.tokenService.extractUserId(token); | ||
|
||
const { jsonContent, fileName } = await usecases.getTargetProfileContentAsJson({ userId, targetProfileId }); | ||
const escapedFilename = escapeFileName(fileName); | ||
|
||
return h | ||
.response(jsonContent) | ||
.header('Content-Type', 'text/json;charset=utf-8') | ||
.header('Content-Disposition', `attachment; filename=${escapedFilename}`); | ||
}; | ||
|
||
const getLearningContentAsPdf = async function (request, h, dependencies = { learningContentPDFPresenter }) { | ||
const targetProfileId = request.params.id; | ||
const { language } = request.query; | ||
|
||
const { learningContent, targetProfileName } = await usecases.getLearningContentByTargetProfile({ | ||
targetProfileId, | ||
language, | ||
}); | ||
|
||
const filename = `${dayjs().format('YYYYMMDD')}_profil_cible_${targetProfileName}.pdf`; | ||
|
||
const pdfBuffer = await dependencies.learningContentPDFPresenter.present( | ||
learningContent, | ||
targetProfileName, | ||
language, | ||
); | ||
|
||
return h | ||
.response(pdfBuffer) | ||
.header('Content-Disposition', `attachment; filename=${filename}`) | ||
.header('Content-Type', 'application/pdf'); | ||
}; | ||
|
||
const targetProfileController = { | ||
getContentAsJsonFile, | ||
getLearningContentAsPdf, | ||
}; | ||
|
||
export { targetProfileController }; |
62 changes: 62 additions & 0 deletions
62
api/src/prescription/target-profile/application/admin-target-profile-route.js
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,62 @@ | ||
import Joi from 'joi'; | ||
|
||
import { securityPreHandlers } from '../../../../lib/application/security-pre-handlers.js'; | ||
import { targetProfileController } from './admin-target-profile-controller.js'; | ||
import { identifiersType } from '../../../../lib/domain/types/identifiers-type.js'; | ||
|
||
const register = async function (server) { | ||
server.route([ | ||
{ | ||
method: 'GET', | ||
path: '/api/admin/target-profiles/{id}/learning-content-pdf', | ||
config: { | ||
pre: [ | ||
{ | ||
method: (request, h) => | ||
securityPreHandlers.adminMemberHasAtLeastOneAccessOf([ | ||
securityPreHandlers.checkAdminMemberHasRoleSuperAdmin, | ||
securityPreHandlers.checkAdminMemberHasRoleSupport, | ||
securityPreHandlers.checkAdminMemberHasRoleMetier, | ||
])(request, h), | ||
assign: 'hasAuthorizationToAccessAdminScope', | ||
}, | ||
], | ||
validate: { | ||
params: Joi.object({ | ||
id: identifiersType.targetProfileId, | ||
}), | ||
query: Joi.object({ | ||
language: Joi.string().valid('fr', 'en').required(), | ||
}), | ||
}, | ||
handler: targetProfileController.getLearningContentAsPdf, | ||
notes: [ | ||
"- **Cette route est restreinte aux utilisateurs authentifiés ayant les droits d'accès**\n" + | ||
'- Elle permet de récupérer le référentiel du profil cible en version pdf', | ||
], | ||
tags: ['api', 'learning-content', 'target-profile', 'PDF'], | ||
}, | ||
}, | ||
{ | ||
method: 'GET', | ||
path: '/api/admin/target-profiles/{id}/content-json', | ||
config: { | ||
auth: false, | ||
validate: { | ||
params: Joi.object({ | ||
id: identifiersType.targetProfileId, | ||
}), | ||
}, | ||
handler: targetProfileController.getContentAsJsonFile, | ||
tags: ['api', 'admin', 'target-profiles', 'json'], | ||
notes: [ | ||
"- **Cette route est restreinte aux utilisateurs authentifiés ayant les droits d'accès**\n" + | ||
'- Elle permet de récupérer le profil cible dans un fichier json', | ||
], | ||
}, | ||
}, | ||
]); | ||
}; | ||
|
||
const name = 'admin-target-profiles-api'; | ||
export { register, name }; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
...src/prescription/target-profile/domain/usecases/get-learning-content-by-target-profile.js
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 @@ | ||
const getLearningContentByTargetProfile = async function ({ | ||
targetProfileId, | ||
language, | ||
learningContentRepository, | ||
targetProfileForAdminRepository, | ||
}) { | ||
const targetProfileForAdmin = await targetProfileForAdminRepository.get({ id: targetProfileId }); | ||
const learningContent = await learningContentRepository.findByTargetProfileId(targetProfileId, language); | ||
return { learningContent, targetProfileName: targetProfileForAdmin.name }; | ||
}; | ||
|
||
export { getLearningContentByTargetProfile }; |
2 changes: 1 addition & 1 deletion
2
...ses/get-target-profile-content-as-json.js → ...ses/get-target-profile-content-as-json.js
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
29 changes: 29 additions & 0 deletions
29
api/src/prescription/target-profile/domain/usecases/index.js
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,29 @@ | ||
import { fileURLToPath } from 'node:url'; | ||
import { dirname, join } from 'node:path'; | ||
|
||
import * as targetProfileForAdminRepository from '../../../../shared/infrastructure/repositories/target-profile-for-admin-repository.js'; | ||
import * as learningContentConversionService from '../../../../../lib/domain/services/learning-content/learning-content-conversion-service.js'; | ||
import * as learningContentRepository from '../../../../../lib/infrastructure/repositories/learning-content-repository.js'; | ||
import * as adminMemberRepository from '../../../../shared/infrastructure/repositories/admin-member-repository.js'; | ||
import { importNamedExportsFromDirectory } from '../../../../shared/infrastructure/utils/import-named-exports-from-directory.js'; | ||
import { injectDependencies } from '../../../../shared/infrastructure/utils/dependency-injection.js'; | ||
|
||
const dependencies = { | ||
targetProfileForAdminRepository, | ||
learningContentConversionService, | ||
learningContentRepository, | ||
adminMemberRepository, | ||
}; | ||
|
||
const path = dirname(fileURLToPath(import.meta.url)); | ||
|
||
const usecasesWithoutInjectedDependencies = { | ||
...(await importNamedExportsFromDirectory({ | ||
path: join(path, './'), | ||
ignoredFileNames: ['index.js'], | ||
})), | ||
}; | ||
|
||
const usecases = injectDependencies(usecasesWithoutInjectedDependencies, dependencies); | ||
|
||
export { usecases }; |
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,5 @@ | ||
import * as adminTargetProfileRoutes from './application/admin-target-profile-route.js'; | ||
|
||
const targetProfileRoutes = [adminTargetProfileRoutes]; | ||
|
||
export { targetProfileRoutes }; |
Oops, something went wrong.