Files
Automata/packages/cli/src/environments/variables.controller.ee.ts
Val 1bb987140a feat: Add variables feature (#5602)
* feat: add variables db models and migrations

* feat: variables api endpoints

* feat: add $variables to expressions

* test: fix ActiveWorkflowRunner tests failing

* test: a different fix for the tests broken by $variables

* feat: variables licensing

* fix: could create one extra variable than licensed for

* feat: Add Variables UI page and $vars global property (#5750)

* feat: add support for row slot to datatable

* feat: add variables create, read, update, delete

* feat: add vars autocomplete

* chore: remove alert

* feat: add variables autocomplete for code and expressions

* feat: add tests for variable components

* feat: add variables search and sort

* test: update tests for variables view

* chore: fix test and linting issue

* refactor: review changes

* feat: add variable creation telemetry

* fix: Improve variables listing and disabled case, fix resource sorting (no-changelog) (#5903)

* fix: Improve variables disabled experience and fix sorting

* fix: update action box margin

* test: update tests for variables row and datatable

* fix: Add ee controller to base controller

* fix: variables.ee routes not being added

* feat: add variables validation

* fix: fix vue-fragment bug that breaks everything

* chore: Update lock

* feat: Add variables input validation and permissions (no-changelog) (#5910)

* feat: add input validation

* feat: handle variables view for non-instance-owner users

* test: update variables tests

* fix: fix data-testid pattern

* feat: improve overflow styles

* test: fix variables row snapshot

* feat: update sorting to take newly created variables into account

* fix: fix list layout overflow

* fix: fix adding variables on page other than 1. fix validation

* feat: add docs link

* fix: fix default displayName function for resource-list-layout

* feat: improve vars expressions ux, cm-tooltip

* test: fix datatable test

* feat: add MATCH_REGEX validation rule

* fix: overhaul how datatable pagination selector works

* feat: update  completer description

* fix: conditionally update usage syntax based on key validation

* test: update datatable snapshot

* fix: fix variables-row button margins

* fix: fix pagination overflow

* test: Fix broken test

* test: Update snapshot

* fix: Remove duplicate declaration

* feat: add custom variables icon

---------

Co-authored-by: Alex Grozav <alex@grozav.com>
Co-authored-by: Omar Ajoue <krynble@gmail.com>
2023-04-18 12:41:55 +02:00

80 lines
2.2 KiB
TypeScript

import express from 'express';
import { LoggerProxy } from 'n8n-workflow';
import * as ResponseHelper from '@/ResponseHelper';
import type { VariablesRequest } from '@/requests';
import {
VariablesLicenseError,
EEVariablesService,
VariablesValidationError,
} from './variables.service.ee';
import { isVariablesEnabled } from './enviromentHelpers';
// eslint-disable-next-line @typescript-eslint/naming-convention
export const EEVariablesController = express.Router();
/**
* Initialize Logger if needed
*/
EEVariablesController.use((req, res, next) => {
if (!isVariablesEnabled()) {
next('router');
return;
}
next();
});
EEVariablesController.post(
'/',
ResponseHelper.send(async (req: VariablesRequest.Create) => {
if (req.user.globalRole.name !== 'owner') {
LoggerProxy.info('Attempt to update a variable blocked due to lack of permissions', {
userId: req.user.id,
});
throw new ResponseHelper.AuthError('Unauthorized');
}
const variable = req.body;
delete variable.id;
try {
return await EEVariablesService.create(variable);
} catch (error) {
if (error instanceof VariablesLicenseError) {
throw new ResponseHelper.BadRequestError(error.message);
} else if (error instanceof VariablesValidationError) {
throw new ResponseHelper.BadRequestError(error.message);
}
throw error;
}
}),
);
EEVariablesController.patch(
'/:id(\\d+)',
ResponseHelper.send(async (req: VariablesRequest.Update) => {
const id = parseInt(req.params.id);
if (isNaN(id)) {
throw new ResponseHelper.BadRequestError('Invalid variable id ' + req.params.id);
}
if (req.user.globalRole.name !== 'owner') {
LoggerProxy.info('Attempt to update a variable blocked due to lack of permissions', {
id,
userId: req.user.id,
});
throw new ResponseHelper.AuthError('Unauthorized');
}
const variable = req.body;
delete variable.id;
try {
return await EEVariablesService.update(id, variable);
} catch (error) {
if (error instanceof VariablesLicenseError) {
throw new ResponseHelper.BadRequestError(error.message);
} else if (error instanceof VariablesValidationError) {
throw new ResponseHelper.BadRequestError(error.message);
}
throw error;
}
}),
);