mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 18:41:14 +00:00
feat: Add Licensed decorator (no-changelog) (#7828)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
@@ -2,23 +2,13 @@ import { Container, Service } from 'typedi';
|
||||
|
||||
import * as ResponseHelper from '@/ResponseHelper';
|
||||
import { VariablesRequest } from '@/requests';
|
||||
import { Authorized, Delete, Get, Patch, Post, RestController } from '@/decorators';
|
||||
import { Authorized, Delete, Get, Licensed, Patch, Post, RestController } from '@/decorators';
|
||||
import {
|
||||
VariablesService,
|
||||
VariablesLicenseError,
|
||||
VariablesValidationError,
|
||||
} from './variables.service.ee';
|
||||
import { isVariablesEnabled } from './enviromentHelpers';
|
||||
import { Logger } from '@/Logger';
|
||||
import type { RequestHandler } from 'express';
|
||||
|
||||
const variablesLicensedMiddleware: RequestHandler = (req, res, next) => {
|
||||
if (isVariablesEnabled()) {
|
||||
next();
|
||||
} else {
|
||||
res.status(403).json({ status: 'error', message: 'Unauthorized' });
|
||||
}
|
||||
};
|
||||
|
||||
@Service()
|
||||
@Authorized()
|
||||
@@ -34,7 +24,8 @@ export class VariablesController {
|
||||
return Container.get(VariablesService).getAllCached();
|
||||
}
|
||||
|
||||
@Post('/', { middlewares: [variablesLicensedMiddleware] })
|
||||
@Post('/')
|
||||
@Licensed('feat:variables')
|
||||
async createVariable(req: VariablesRequest.Create) {
|
||||
if (req.user.globalRole.name !== 'owner') {
|
||||
this.logger.info('Attempt to update a variable blocked due to lack of permissions', {
|
||||
@@ -66,7 +57,8 @@ export class VariablesController {
|
||||
return variable;
|
||||
}
|
||||
|
||||
@Patch('/:id', { middlewares: [variablesLicensedMiddleware] })
|
||||
@Patch('/:id')
|
||||
@Licensed('feat:variables')
|
||||
async updateVariable(req: VariablesRequest.Update) {
|
||||
const id = req.params.id;
|
||||
if (req.user.globalRole.name !== 'owner') {
|
||||
|
||||
Reference in New Issue
Block a user