-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(api): move DELETE organization invitations admin route
Co-authored-by: Eric Lim <eric.lim@pix.fr>
- Loading branch information
Showing
6 changed files
with
72 additions
and
57 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
37 changes: 37 additions & 0 deletions
37
api/src/team/application/organization-invitations/organization-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,37 @@ | ||
import Joi from 'joi'; | ||
|
||
import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js'; | ||
import { identifiersType } from '../../../shared/domain/types/identifiers-type.js'; | ||
import { organizationInvitationController } from './organization-invitation.controller.js'; | ||
|
||
export const organizationInvitationAdminRoutes = [ | ||
{ | ||
method: 'DELETE', | ||
path: '/api/admin/organizations/{id}/invitations/{organizationInvitationId}', | ||
config: { | ||
pre: [ | ||
{ | ||
method: (request, h) => | ||
securityPreHandlers.hasAtLeastOneAccessOf([ | ||
securityPreHandlers.checkAdminMemberHasRoleSuperAdmin, | ||
securityPreHandlers.checkAdminMemberHasRoleSupport, | ||
securityPreHandlers.checkAdminMemberHasRoleMetier, | ||
])(request, h), | ||
assign: 'hasAuthorizationToAccessAdminScope', | ||
}, | ||
], | ||
validate: { | ||
params: Joi.object({ | ||
id: identifiersType.organizationId, | ||
organizationInvitationId: identifiersType.organizationInvitationId, | ||
}), | ||
}, | ||
handler: (request, h) => organizationInvitationController.cancelOrganizationInvitation(request, h), | ||
tags: ['team', 'api', 'admin', 'invitations', '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.", | ||
], | ||
}, | ||
}, | ||
]; |
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
8 changes: 4 additions & 4 deletions
8
...el-organization-invitation-delete_test.js → ...ganization-invitation.admin.route.test.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
...tegration/application/organization-invitation/organization-invitation.admin.route.test.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 { securityPreHandlers } from '../../../../../src/shared/application/security-pre-handlers.js'; | ||
import { organizationInvitationController } from '../../../../../src/team/application/organization-invitations/organization-invitation.controller.js'; | ||
import { teamRoutes } from '../../../../../src/team/application/routes.js'; | ||
import { expect, HttpTestServer, sinon } from '../../../../test-helper.js'; | ||
|
||
describe('Integration | Team | Application | Route | Admin | organization-invitations', function () { | ||
describe('DELETE /api/admin/organizations/:organizationId/invitations/:organizationInvitationId', function () { | ||
it('returns an HTTP status code 204', async function () { | ||
// given | ||
const method = 'DELETE'; | ||
const url = '/api/admin/organizations/1/invitations/1'; | ||
|
||
sinon.stub(securityPreHandlers, 'hasAtLeastOneAccessOf').returns(() => true); | ||
sinon | ||
.stub(organizationInvitationController, 'cancelOrganizationInvitation') | ||
.returns((request, h) => h.response().code(204)); | ||
|
||
const httpTestServer = new HttpTestServer(); | ||
await httpTestServer.register(teamRoutes[0]); | ||
|
||
// when | ||
const { statusCode } = await httpTestServer.request(method, url); | ||
|
||
// then | ||
expect(statusCode).to.equal(204); | ||
expect(organizationInvitationController.cancelOrganizationInvitation).to.have.been.calledOnce; | ||
}); | ||
}); | ||
}); |