feat: Add Licensed decorator (no-changelog) (#7828)

Github issue / Community forum post (link here to close automatically):
This commit is contained in:
Val
2023-11-27 13:46:18 +00:00
committed by GitHub
parent d667bca658
commit 27e048c201
6 changed files with 54 additions and 13 deletions

View File

@@ -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') {