Skip to content

Commit

Permalink
fix(editor): Throw expression error on attempting to set variables at…
Browse files Browse the repository at this point in the history
… runtime (#9229)
  • Loading branch information
ivov authored Apr 26, 2024
1 parent b694e77 commit fec04d5
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/editor-ui/src/stores/environments.ee.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit fec04d5

Please sign in to comment.