fix the TODO

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-09-19 17:58:55 +02:00
parent eb6a74fa24
commit d2e178a677
No known key found for this signature in database
GPG key ID: 9300FF7CDEA1FBAA
2 changed files with 37 additions and 3 deletions

View file

@ -1,4 +1,4 @@
import type { RoleChangeRequestDTO } from '@n8n/api-types';
import { RoleChangeRequestDTO } from '@n8n/api-types';
import type express from 'express';
import type { Response } from 'express';
import { Container } from 'typedi';
@ -99,8 +99,19 @@ export = {
isLicensed('feat:advancedPermissions'),
globalScope('user:changeRole'),
async (req: ChangeRole, res: Response) => {
// TODO: validate req.body
await Container.get(UsersController).changeGlobalRole(req, res, req.body, req.params.id);
const validation = RoleChangeRequestDTO.safeParse(req.body);
if (validation.error) {
return res.status(400).json({
message: validation.error.errors[0],
});
}
await Container.get(UsersController).changeGlobalRole(
req,
res,
validation.data,
req.params.id,
);
return res.status(204).send();
},

View file

@ -225,6 +225,29 @@ describe('Users in Public API', () => {
expect(response.body).toHaveProperty('message', 'Forbidden');
});
it('should return a 400 on invalid payload', async () => {
/**
* Arrange
*/
testServer.license.enable('feat:advancedPermissions');
const owner = await createOwner({ withApiKey: true });
const member = await createMember();
const payload = { newRoleName: 'invalid' };
/**
* Act
*/
const response = await testServer
.publicApiAgentFor(owner)
.patch(`/users/${member.id}/role`)
.send(payload);
/**
* Assert
*/
expect(response.status).toBe(400);
});
it("should change a user's role", async () => {
/**
* Arrange