mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
refactor(core): Use @Licensed()
in event bus controller (no-changelog) (#9687)
This commit is contained in:
parent
ae00b446a7
commit
74b6215df5
|
@ -5,7 +5,7 @@ import type {
|
|||
} from 'n8n-workflow';
|
||||
import { MessageEventBusDestinationTypeNames } from 'n8n-workflow';
|
||||
|
||||
import { RestController, Get, Post, Delete, GlobalScope } from '@/decorators';
|
||||
import { RestController, Get, Post, Delete, GlobalScope, Licensed } from '@/decorators';
|
||||
import { AuthenticatedRequest } from '@/requests';
|
||||
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
||||
|
||||
|
@ -20,7 +20,6 @@ import {
|
|||
} from './MessageEventBusDestination/MessageEventBusDestinationSyslog.ee';
|
||||
import { MessageEventBusDestinationWebhook } from './MessageEventBusDestination/MessageEventBusDestinationWebhook.ee';
|
||||
import type { MessageEventBusDestination } from './MessageEventBusDestination/MessageEventBusDestination.ee';
|
||||
import { logStreamingLicensedMiddleware } from './middleware/logStreamingEnabled.middleware.ee';
|
||||
|
||||
// ----------------------------------------
|
||||
// TypeGuards
|
||||
|
@ -60,7 +59,8 @@ export class EventBusControllerEE {
|
|||
// Destinations
|
||||
// ----------------------------------------
|
||||
|
||||
@Get('/destination', { middlewares: [logStreamingLicensedMiddleware] })
|
||||
@Licensed('feat:logStreaming')
|
||||
@Get('/destination')
|
||||
@GlobalScope('eventBusDestination:list')
|
||||
async getDestination(req: express.Request): Promise<MessageEventBusDestinationOptions[]> {
|
||||
if (isWithIdString(req.query)) {
|
||||
|
@ -70,7 +70,8 @@ export class EventBusControllerEE {
|
|||
}
|
||||
}
|
||||
|
||||
@Post('/destination', { middlewares: [logStreamingLicensedMiddleware] })
|
||||
@Licensed('feat:logStreaming')
|
||||
@Post('/destination')
|
||||
@GlobalScope('eventBusDestination:create')
|
||||
async postDestination(req: AuthenticatedRequest): Promise<any> {
|
||||
let result: MessageEventBusDestination | undefined;
|
||||
|
@ -114,7 +115,8 @@ export class EventBusControllerEE {
|
|||
throw new BadRequestError('Body is not configuring MessageEventBusDestinationOptions');
|
||||
}
|
||||
|
||||
@Get('/testmessage', { middlewares: [logStreamingLicensedMiddleware] })
|
||||
@Licensed('feat:logStreaming')
|
||||
@Get('/testmessage')
|
||||
@GlobalScope('eventBusDestination:test')
|
||||
async sendTestMessage(req: express.Request): Promise<boolean> {
|
||||
if (isWithIdString(req.query)) {
|
||||
|
@ -123,7 +125,8 @@ export class EventBusControllerEE {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Delete('/destination', { middlewares: [logStreamingLicensedMiddleware] })
|
||||
@Licensed('feat:logStreaming')
|
||||
@Delete('/destination')
|
||||
@GlobalScope('eventBusDestination:delete')
|
||||
async deleteDestination(req: AuthenticatedRequest) {
|
||||
if (isWithIdString(req.query)) {
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
import type { RequestHandler } from 'express';
|
||||
import Container from 'typedi';
|
||||
import { License } from '../../License';
|
||||
|
||||
export function islogStreamingLicensed(): boolean {
|
||||
return Container.get(License).isLogStreamingEnabled();
|
||||
}
|
||||
|
||||
export const logStreamingLicensedMiddleware: RequestHandler = (_req, res, next) => {
|
||||
if (islogStreamingLicensed()) {
|
||||
next();
|
||||
} else {
|
||||
res.status(403).json({ status: 'error', message: 'Unauthorized' });
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue