fix(editor): Throw expression error on attempting to set variables at runtime (#9229)

This commit is contained in:
Iván Ovejero 2024-04-26 14:03:27 +02:00 committed by GitHub
parent b694e7743e
commit fec04d5f79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,7 @@ import { computed, ref } from 'vue';
import type { EnvironmentVariable } from '@/Interface';
import * as environmentsApi from '@/api/environments.ee';
import { useRootStore } from '@/stores/n8nRoot.store';
import { ExpressionError } from 'n8n-workflow';
export const useEnvironmentsStore = defineStore('environments', () => {
const rootStore = useRootStore();
@ -43,12 +44,21 @@ export const useEnvironmentsStore = defineStore('environments', () => {
return data;
}
const variablesAsObject = computed(() =>
variables.value.reduce<Record<string, string | boolean | number>>((acc, variable) => {
acc[variable.key] = variable.value;
return acc;
}, {}),
);
const variablesAsObject = computed(() => {
const asObject = variables.value.reduce<Record<string, string | boolean | number>>(
(acc, variable) => {
acc[variable.key] = variable.value;
return acc;
},
{},
);
return new Proxy(asObject, {
set() {
throw new ExpressionError('Cannot assign values to variables at runtime');
},
});
});
return {
variables,