-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TECH] Migrer la route DELETE /api/admin/certification-centers/{id}/i…
- Loading branch information
Showing
18 changed files
with
372 additions
and
277 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
78 changes: 78 additions & 0 deletions
78
...pplication/certification-center-invitation/certification-center-invitation.admin.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,78 @@ | ||
import Joi from 'joi'; | ||
|
||
import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js'; | ||
import { identifiersType } from '../../../shared/domain/types/identifiers-type.js'; | ||
import { certificationCenterInvitationAdminController } from './certification-center-invitation.admin.controller.js'; | ||
|
||
export const certificationCenterInvitationAdminRoutes = [ | ||
{ | ||
method: 'POST', | ||
path: '/api/admin/certification-centers/{certificationCenterId}/invitations', | ||
config: { | ||
pre: [ | ||
{ | ||
method: (request, h) => | ||
securityPreHandlers.hasAtLeastOneAccessOf([ | ||
securityPreHandlers.checkAdminMemberHasRoleSuperAdmin, | ||
securityPreHandlers.checkAdminMemberHasRoleCertif, | ||
securityPreHandlers.checkAdminMemberHasRoleSupport, | ||
securityPreHandlers.checkAdminMemberHasRoleMetier, | ||
])(request, h), | ||
assign: 'hasAuthorizationToAccessAdminScope', | ||
}, | ||
], | ||
handler: certificationCenterInvitationAdminController.sendInvitationForAdmin, | ||
validate: { | ||
params: Joi.object({ | ||
certificationCenterId: identifiersType.certificationCenterId, | ||
}), | ||
options: { | ||
allowUnknown: true, | ||
}, | ||
payload: Joi.object({ | ||
data: { | ||
attributes: { | ||
email: Joi.string().email().required(), | ||
language: Joi.string().valid('fr-fr', 'fr', 'en'), | ||
role: Joi.string().valid('ADMIN', 'MEMBER').allow(null), | ||
}, | ||
}, | ||
}), | ||
}, | ||
notes: [ | ||
"- **Cette route est restreinte aux utilisateurs authentifiés ayant les droits d'accès**\n" + | ||
"- Elle permet à un administrateur d'inviter des personnes, déjà utilisateurs de Pix ou non, à être membre d'un centre de certification, via leur **email**", | ||
], | ||
tags: ['api', 'admin', 'invitations', 'certification-center'], | ||
}, | ||
}, | ||
{ | ||
method: 'DELETE', | ||
path: '/api/admin/certification-center-invitations/{certificationCenterInvitationId}', | ||
config: { | ||
pre: [ | ||
{ | ||
method: (request, h) => | ||
securityPreHandlers.hasAtLeastOneAccessOf([ | ||
securityPreHandlers.checkAdminMemberHasRoleSuperAdmin, | ||
securityPreHandlers.checkAdminMemberHasRoleCertif, | ||
securityPreHandlers.checkAdminMemberHasRoleSupport, | ||
securityPreHandlers.checkAdminMemberHasRoleMetier, | ||
])(request, h), | ||
assign: 'hasAuthorizationToAccessAdminScope', | ||
}, | ||
], | ||
validate: { | ||
params: Joi.object({ | ||
certificationCenterInvitationId: identifiersType.certificationCenterInvitationId, | ||
}), | ||
}, | ||
handler: certificationCenterInvitationAdminController.cancelCertificationCenterInvitation, | ||
tags: ['api', 'admin', 'invitations', 'certification-center', 'cancel'], | ||
notes: [ | ||
"- **Cette route est restreinte aux utilisateurs authentifiés ayant les droits d'accès**\n" + | ||
"- Elle permet d'annuler une invitation envoyée mais non acceptée encore.", | ||
], | ||
}, | ||
}, | ||
]; |
20 changes: 20 additions & 0 deletions
20
...application/certification-center-invitation/certification-center-invitation.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,20 @@ | ||
import { extractLocaleFromRequest } from '../../../../lib/infrastructure/utils/request-response-utils.js'; | ||
import { usecases } from '../../domain/usecases/index.js'; | ||
|
||
/** | ||
* @callback sendInvitations | ||
* @param request | ||
* @param h | ||
* @returns {Promise<void>} | ||
*/ | ||
const sendInvitations = async function (request, h) { | ||
const certificationCenterId = request.params.certificationCenterId; | ||
const emails = request.payload.data.attributes.emails; | ||
const locale = extractLocaleFromRequest(request); | ||
|
||
await usecases.createOrUpdateCertificationCenterInvitation({ certificationCenterId, emails, locale }); | ||
|
||
return h.response().code(204); | ||
}; | ||
|
||
export const certificationCenterInvitationController = { sendInvitations }; |
38 changes: 38 additions & 0 deletions
38
...team/application/certification-center-invitation/certification-center-invitation.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,38 @@ | ||
import Joi from 'joi'; | ||
|
||
import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js'; | ||
import { identifiersType } from '../../../shared/domain/types/identifiers-type.js'; | ||
import { certificationCenterInvitationController } from './certification-center-invitation.controller.js'; | ||
|
||
export const certificationCenterInvitationRoutes = [ | ||
{ | ||
method: 'POST', | ||
path: '/api/certification-centers/{certificationCenterId}/invitations', | ||
config: { | ||
pre: [ | ||
{ | ||
method: securityPreHandlers.checkUserIsAdminOfCertificationCenter, | ||
assign: 'isAdminOfCertificationCenter', | ||
}, | ||
], | ||
validate: { | ||
params: Joi.object({ | ||
certificationCenterId: identifiersType.certificationCenterId, | ||
}), | ||
payload: Joi.object({ | ||
data: { | ||
attributes: { | ||
emails: Joi.array().items(Joi.string().email()).required(), | ||
}, | ||
}, | ||
}), | ||
}, | ||
handler: certificationCenterInvitationController.sendInvitations, | ||
notes: [ | ||
'- **Cette route est restreinte aux utilisateurs authentifiés en tant que responsables à un centre de certification**\n' + | ||
"- Elle permet d'inviter des personnes, déjà utilisateurs de Pix ou non, à être membre d'un centre de certification via leur **email**", | ||
], | ||
tags: ['api', 'certification-center', 'invitations'], | ||
}, | ||
}, | ||
]; |
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,10 @@ | ||
import { DomainError } from '../../shared/domain/errors.js'; | ||
|
||
export class UncancellableCertificationCenterInvitationError extends DomainError { | ||
constructor( | ||
message = "L'invitation à ce centre de certification ne peut pas être annulée.", | ||
code = 'UNCANCELLABLE_CERTIFICATION_CENTER_INVITATION_CODE', | ||
) { | ||
super(message, code); | ||
} | ||
} |
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
Oops, something went wrong.