mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-31 08:46:58 +02:00
Co-authored-by: Declan Carroll <declan@n8n.io> Co-authored-by: Milorad FIlipović <milorad@n8n.io> Co-authored-by: Ricardo Espinoza <ricardo@n8n.io> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: Charlie Kolb <charlie@n8n.io> Co-authored-by: Mutasem Aldmour <4711238+mutdmour@users.noreply.github.com> Co-authored-by: Ali Elkhateeb <ali.elkhateeb@n8n.io> Co-authored-by: Matsu <huhta.matias@gmail.com> Co-authored-by: Guillaume Jacquart <jacquart.guillaume@gmail.com> Co-authored-by: yehorkardash <yehor.kardash@n8n.io> Co-authored-by: Rob Hough <robhough180@gmail.com> Co-authored-by: Svetoslav Dekov <svetoslav.dekov@n8n.io> Co-authored-by: James Gee <1285296+geemanjs@users.noreply.github.com> Co-authored-by: Alex Grozav <alex@grozav.com> Co-authored-by: Dawid Myslak <dawid.myslak@gmail.com> Co-authored-by: Stephen Wright <sjw948@gmail.com> Co-authored-by: Andreas Fitzek <andreas.fitzek@n8n.io> Co-authored-by: Albert Alises <albert.alises@gmail.com> Co-authored-by: Dimitri Lavrenük <20122620+dlavrenuek@users.noreply.github.com> Co-authored-by: Danny Martini <danny@n8n.io> Co-authored-by: Daria <daria.staferova@n8n.io> Co-authored-by: peteawood <pete.a.wood@gmail.com> Co-authored-by: Roman Davydchuk <roman.davydchuk@n8n.io> Co-authored-by: Jaakko Husso <jaakko@n8n.io> Co-authored-by: Elias Meire <elias@meire.dev> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Eugene <eugene@n8n.io> Co-authored-by: Benjamin Schroth <benjamin@n8n.io> Co-authored-by: Sandra Zollner <sandra.zollner@n8n.io> Co-authored-by: Irénée <irenee.ajeneza@n8n.io> Co-authored-by: Benjamin Schroth <68321970+schrothbn@users.noreply.github.com> Co-authored-by: oleg <me@olegivaniv.com> Co-authored-by: Konstantin Tieber <46342664+konstantintieber@users.noreply.github.com> Co-authored-by: Nikhil Kuriakose <nikhilkuria@gmail.com> Co-authored-by: Romeo Balta <7095569+romeobalta@users.noreply.github.com> Co-authored-by: Tuukka Kantola <Tuukkaa@users.noreply.github.com> Co-authored-by: Kaito Horiuchi <horiyee.ka@gmail.com> Co-authored-by: Michael Drury <me@michaeldrury.co.uk> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
114 lines
3.0 KiB
TypeScript
114 lines
3.0 KiB
TypeScript
import {
|
|
CreateRoleDto,
|
|
RoleAssignmentsResponseDto,
|
|
RoleGetQueryDto,
|
|
RoleListQueryDto,
|
|
RoleProjectMembersResponseDto,
|
|
UpdateRoleDto,
|
|
} from '@n8n/api-types';
|
|
import type { RoleAssignmentsResponse, RoleProjectMembersResponse } from '@n8n/api-types';
|
|
import { LICENSE_FEATURES } from '@n8n/constants';
|
|
import { AuthenticatedRequest } from '@n8n/db';
|
|
import {
|
|
Body,
|
|
Delete,
|
|
Get,
|
|
GlobalScope,
|
|
Licensed,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
RestController,
|
|
} from '@n8n/decorators';
|
|
import { Role as RoleDTO } from '@n8n/permissions';
|
|
|
|
import { RoleService } from '@/services/role.service';
|
|
|
|
@RestController('/roles')
|
|
export class RoleController {
|
|
constructor(private readonly roleService: RoleService) {}
|
|
|
|
@Get('/')
|
|
async getAllRoles(
|
|
_req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Query query: RoleListQueryDto,
|
|
): Promise<Record<string, RoleDTO[]>> {
|
|
const allRoles = await this.roleService.getAllRoles(query.withUsageCount);
|
|
return {
|
|
global: allRoles.filter((r) => r.roleType === 'global'),
|
|
project: allRoles.filter((r) => r.roleType === 'project'),
|
|
credential: allRoles.filter((r) => r.roleType === 'credential'),
|
|
workflow: allRoles.filter((r) => r.roleType === 'workflow'),
|
|
};
|
|
}
|
|
|
|
@Get('/:slug/assignments/:projectId/members')
|
|
@GlobalScope('role:manage')
|
|
async getRoleProjectMembers(
|
|
_req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Param('slug') slug: string,
|
|
@Param('projectId') projectId: string,
|
|
): Promise<RoleProjectMembersResponse> {
|
|
const result = await this.roleService.getRoleProjectMembers(slug, projectId);
|
|
return RoleProjectMembersResponseDto.parse(result);
|
|
}
|
|
|
|
@Get('/:slug/assignments')
|
|
@GlobalScope('role:manage')
|
|
async getRoleAssignments(
|
|
_req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Param('slug') slug: string,
|
|
): Promise<RoleAssignmentsResponse> {
|
|
const result = await this.roleService.getRoleAssignments(slug);
|
|
return RoleAssignmentsResponseDto.parse(result);
|
|
}
|
|
|
|
@Get('/:slug')
|
|
async getRoleBySlug(
|
|
_req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Param('slug') slug: string,
|
|
@Query query: RoleGetQueryDto,
|
|
): Promise<RoleDTO> {
|
|
return await this.roleService.getRole(slug, query.withUsageCount);
|
|
}
|
|
|
|
@Patch('/:slug')
|
|
@GlobalScope('role:manage')
|
|
@Licensed(LICENSE_FEATURES.CUSTOM_ROLES)
|
|
async updateRole(
|
|
_req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Param('slug') slug: string,
|
|
@Body updateRole: UpdateRoleDto,
|
|
): Promise<RoleDTO> {
|
|
return await this.roleService.updateCustomRole(slug, updateRole);
|
|
}
|
|
|
|
@Delete('/:slug')
|
|
@GlobalScope('role:manage')
|
|
@Licensed(LICENSE_FEATURES.CUSTOM_ROLES)
|
|
async deleteRole(
|
|
_req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Param('slug') slug: string,
|
|
): Promise<RoleDTO> {
|
|
return await this.roleService.removeCustomRole(slug);
|
|
}
|
|
|
|
@Post('/')
|
|
@GlobalScope('role:manage')
|
|
@Licensed(LICENSE_FEATURES.CUSTOM_ROLES)
|
|
async createRole(
|
|
_req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Body createRole: CreateRoleDto,
|
|
): Promise<RoleDTO> {
|
|
return await this.roleService.createCustomRole(createRole);
|
|
}
|
|
}
|