mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
feat(API): Allow deletion of users from projects
This commit is contained in:
parent
bbc2fc98dd
commit
5a5ce6e273
|
@ -196,14 +196,7 @@ export class ProjectController {
|
||||||
await this.projectsService.updateProject(req.body.name, req.params.projectId);
|
await this.projectsService.updateProject(req.body.name, req.params.projectId);
|
||||||
}
|
}
|
||||||
if (req.body.relations) {
|
if (req.body.relations) {
|
||||||
try {
|
await this.syncProjectRelations(req.params.projectId, req.body.relations);
|
||||||
await this.projectsService.syncProjectRelations(req.params.projectId, req.body.relations);
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof UnlicensedProjectRoleError) {
|
|
||||||
throw new BadRequestError(e.message);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.eventService.emit('team-project-updated', {
|
this.eventService.emit('team-project-updated', {
|
||||||
userId: req.user.id,
|
userId: req.user.id,
|
||||||
|
@ -214,6 +207,20 @@ export class ProjectController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async syncProjectRelations(
|
||||||
|
projectId: string,
|
||||||
|
relations: ProjectRequest.ProjectRelationPayload[],
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
await this.projectsService.syncProjectRelations(projectId, relations);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof UnlicensedProjectRoleError) {
|
||||||
|
throw new BadRequestError(e.message);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Delete('/:projectId')
|
@Delete('/:projectId')
|
||||||
@ProjectScope('project:delete')
|
@ProjectScope('project:delete')
|
||||||
async deleteProject(req: ProjectRequest.Delete) {
|
async deleteProject(req: ProjectRequest.Delete) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { encodeNextCursor } from '../../shared/services/pagination.service';
|
||||||
type Create = ProjectRequest.Create;
|
type Create = ProjectRequest.Create;
|
||||||
type Update = ProjectRequest.Update;
|
type Update = ProjectRequest.Update;
|
||||||
type Delete = ProjectRequest.Delete;
|
type Delete = ProjectRequest.Delete;
|
||||||
|
type DeleteUser = ProjectRequest.DeleteUser;
|
||||||
type GetAll = PaginatedRequest;
|
type GetAll = PaginatedRequest;
|
||||||
|
|
||||||
export = {
|
export = {
|
||||||
|
@ -64,4 +65,26 @@ export = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
deleteUserFromProject: [
|
||||||
|
isLicensed('feat:projectRole:admin'),
|
||||||
|
globalScope('project:update'),
|
||||||
|
async (req: DeleteUser, res: Response) => {
|
||||||
|
const { projectId, id: userId } = req.params;
|
||||||
|
|
||||||
|
const project = await Container.get(ProjectRepository).findOne({
|
||||||
|
where: { id: projectId },
|
||||||
|
relations: { projectRelations: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!project) {
|
||||||
|
return res.status(404).send({ message: 'Not found' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const relations = project.projectRelations.filter((relation) => relation.userId !== userId);
|
||||||
|
|
||||||
|
await Container.get(ProjectController).syncProjectRelations(projectId, relations);
|
||||||
|
|
||||||
|
return res.status(204).send();
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
delete:
|
||||||
|
x-eov-operation-id: deleteUserFromProject
|
||||||
|
x-eov-operation-handler: v1/handlers/projects/projects.handler
|
||||||
|
tags:
|
||||||
|
- Projects
|
||||||
|
summary: Delete a user from a project
|
||||||
|
description: Delete a user from a project from your instance.
|
||||||
|
parameters:
|
||||||
|
- $ref: '../schemas/parameters/projectId.yml'
|
||||||
|
- $ref: '../../../users/spec/schemas/parameters/userIdentifier.yml'
|
||||||
|
responses:
|
||||||
|
'204':
|
||||||
|
description: Operation successful.
|
||||||
|
'401':
|
||||||
|
$ref: '../../../../shared/spec/responses/unauthorized.yml'
|
||||||
|
'403':
|
||||||
|
$ref: '../../../../shared/spec/responses/forbidden.yml'
|
||||||
|
'404':
|
||||||
|
$ref: '../../../../shared/spec/responses/notFound.yml'
|
||||||
|
# put:
|
||||||
|
# x-eov-operation-id: updateProject
|
||||||
|
# x-eov-operation-handler: v1/handlers/projects/projects.handler
|
||||||
|
# tags:
|
||||||
|
# - Project
|
||||||
|
# summary: Update a project
|
||||||
|
# description: Update a project.
|
||||||
|
# requestBody:
|
||||||
|
# description: Updated project object.
|
||||||
|
# content:
|
||||||
|
# application/json:
|
||||||
|
# schema:
|
||||||
|
# $ref: '../schemas/project.yml'
|
||||||
|
# required: true
|
||||||
|
# responses:
|
||||||
|
# '204':
|
||||||
|
# description: Operation successful.
|
||||||
|
# '400':
|
||||||
|
# $ref: '../../../../shared/spec/responses/badRequest.yml'
|
||||||
|
# '401':
|
||||||
|
# $ref: '../../../../shared/spec/responses/unauthorized.yml'
|
||||||
|
# '403':
|
||||||
|
# $ref: '../../../../shared/spec/responses/forbidden.yml'
|
||||||
|
# '404':
|
||||||
|
# $ref: '../../../../shared/spec/responses/notFound.yml'
|
|
@ -82,6 +82,8 @@ paths:
|
||||||
$ref: './handlers/projects/spec/paths/projects.yml'
|
$ref: './handlers/projects/spec/paths/projects.yml'
|
||||||
/projects/{projectId}:
|
/projects/{projectId}:
|
||||||
$ref: './handlers/projects/spec/paths/projects.projectId.yml'
|
$ref: './handlers/projects/spec/paths/projects.projectId.yml'
|
||||||
|
/projects/{projectId}/users/{id}:
|
||||||
|
$ref: './handlers/projects/spec/paths/projects.projectId.users.id.yml'
|
||||||
components:
|
components:
|
||||||
schemas:
|
schemas:
|
||||||
$ref: './shared/spec/schemas/_index.yml'
|
$ref: './shared/spec/schemas/_index.yml'
|
||||||
|
|
|
@ -563,6 +563,7 @@ export declare namespace ProjectRequest {
|
||||||
{ name?: string; relations?: ProjectRelationPayload[] }
|
{ name?: string; relations?: ProjectRelationPayload[] }
|
||||||
>;
|
>;
|
||||||
type Delete = AuthenticatedRequest<{ projectId: string }, {}, {}, { transferId?: string }>;
|
type Delete = AuthenticatedRequest<{ projectId: string }, {}, {}, { transferId?: string }>;
|
||||||
|
type DeleteUser = AuthenticatedRequest<{ projectId: string; id: string }, {}, {}, {}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
Loading…
Reference in a new issue