From 6a3fbdd6ad445b43af6be72ff3db1327a2a44d25 Mon Sep 17 00:00:00 2001 From: nscuro Date: Sat, 6 Jul 2024 21:17:12 +0200 Subject: [PATCH 1/2] Fix CEL errors not being visualized when creating a new policy condition Error markers were only displayed in the expression editor when *updating* an existing condition, but not when creating a new one. Signed-off-by: nscuro --- src/views/policy/PolicyCondition.vue | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/views/policy/PolicyCondition.vue b/src/views/policy/PolicyCondition.vue index 92a4d277..1476c70f 100644 --- a/src/views/policy/PolicyCondition.vue +++ b/src/views/policy/PolicyCondition.vue @@ -522,7 +522,27 @@ export default { this.$toastr.s(this.$t('message.updated')); }) .catch((error) => { - this.$toastr.w(this.$t('condition.unsuccessful_action')); + if ( + this.subject === 'EXPRESSION' && + error.response && + error.response.data && + error.response.data.celErrors + ) { + this.editorMarkers = error.response.data.celErrors.map( + (celErr) => { + return { + startLineNumber: celErr.line, + startColumn: celErr.column, + endLineNumber: celErr.line, + endColumn: celErr.column + 3, // Add a few columns to make it more visible + message: celErr.message, + severity: 8, + }; + }, + ); + } else { + this.$toastr.w(this.$t('condition.unsuccessful_action')); + } }); } }, @@ -540,7 +560,7 @@ export default { this.$toastr.s(this.$t('message.condition_deleted')); this.$emit('conditionRemoved'); }) - .catch((error) => { + .catch(() => { this.$toastr.w(this.$t('condition.unsuccessful_action')); }); } else { From 8cbdf83bfeaf796bced6997ac2beb18526be84d1 Mon Sep 17 00:00:00 2001 From: nscuro Date: Sat, 6 Jul 2024 22:24:44 +0200 Subject: [PATCH 2/2] Handle expression condition errors from problem details Signed-off-by: nscuro --- src/views/policy/PolicyCondition.vue | 48 +++++++++++++--------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/views/policy/PolicyCondition.vue b/src/views/policy/PolicyCondition.vue index 1476c70f..8234b9db 100644 --- a/src/views/policy/PolicyCondition.vue +++ b/src/views/policy/PolicyCondition.vue @@ -485,20 +485,18 @@ export default { this.subject === 'EXPRESSION' && error.response && error.response.data && - error.response.data.celErrors + error.response.data.errors ) { - this.editorMarkers = error.response.data.celErrors.map( - (celErr) => { - return { - startLineNumber: celErr.line, - startColumn: celErr.column, - endLineNumber: celErr.line, - endColumn: celErr.column + 3, // Add a few columns to make it more visible - message: celErr.message, - severity: 8, - }; - }, - ); + this.editorMarkers = error.response.data.errors.map((celErr) => { + return { + startLineNumber: celErr.line, + startColumn: celErr.column, + endLineNumber: celErr.line, + endColumn: celErr.column + 3, // Add a few columns to make it more visible + message: celErr.message, + severity: 8, + }; + }); } else { this.$toastr.w(this.$t('condition.unsuccessful_action')); } @@ -526,20 +524,18 @@ export default { this.subject === 'EXPRESSION' && error.response && error.response.data && - error.response.data.celErrors + error.response.data.errors ) { - this.editorMarkers = error.response.data.celErrors.map( - (celErr) => { - return { - startLineNumber: celErr.line, - startColumn: celErr.column, - endLineNumber: celErr.line, - endColumn: celErr.column + 3, // Add a few columns to make it more visible - message: celErr.message, - severity: 8, - }; - }, - ); + this.editorMarkers = error.response.data.errors.map((celErr) => { + return { + startLineNumber: celErr.line, + startColumn: celErr.column, + endLineNumber: celErr.line, + endColumn: celErr.column + 3, // Add a few columns to make it more visible + message: celErr.message, + severity: 8, + }; + }); } else { this.$toastr.w(this.$t('condition.unsuccessful_action')); }