From 840da9b34ec1ccc55d8dcb028e2b618003d35c9a Mon Sep 17 00:00:00 2001 From: ismay Date: Tue, 29 Aug 2023 15:56:51 +0200 Subject: [PATCH] fix: ensure queues uri encode name before using in a url --- i18n/en.pot | 23 ++++++++++++++++------- src/hooks/queues/use-queue-by-name.js | 7 ++++--- src/hooks/queues/use-submit-queue.js | 7 ++++--- src/hooks/queues/use-update-queue.js | 7 ++++--- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index a5a5b38ac..b38f17f9c 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -5,8 +5,8 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" -"POT-Creation-Date: 2023-08-23T09:22:37.116Z\n" -"PO-Revision-Date: 2023-08-23T09:22:37.116Z\n" +"POT-Creation-Date: 2023-08-29T11:34:50.926Z\n" +"PO-Revision-Date: 2023-08-29T11:34:50.926Z\n" msgid "Something went wrong" msgstr "Something went wrong" @@ -33,9 +33,6 @@ msgstr "Delete job" msgid "Delete queue" msgstr "Delete queue" -msgid "Something went wrong whilst creating your job" -msgstr "Something went wrong whilst creating your job" - msgid "Please select data exchange ids." msgstr "Please select data exchange ids." @@ -132,12 +129,24 @@ msgstr "Jobs in this queue" msgid "There was a problem fetching the required job type" msgstr "There was a problem fetching the required job type" +msgid "Something went wrong whilst creating your job" +msgstr "Something went wrong whilst creating your job" + msgid "Save" msgstr "Save" msgid "Cancel" msgstr "Cancel" +msgid "Something went wrong whilst updating your job" +msgstr "Something went wrong whilst updating your job" + +msgid "Something went wrong whilst creating your queue" +msgstr "Something went wrong whilst creating your queue" + +msgid "Something went wrong whilst updating your queue" +msgstr "Something went wrong whilst updating your queue" + msgid "Job details" msgstr "Job details" @@ -280,8 +289,8 @@ msgstr "System job: {{ name }}" msgid "Back to all jobs" msgstr "Back to all jobs" -msgid "New Queue" -msgstr "New Queue" +msgid "New queue" +msgstr "New queue" msgid "" "A queue is a collection of jobs that are executed in order, one after " diff --git a/src/hooks/queues/use-queue-by-name.js b/src/hooks/queues/use-queue-by-name.js index 6857e4154..a387bdcc8 100644 --- a/src/hooks/queues/use-queue-by-name.js +++ b/src/hooks/queues/use-queue-by-name.js @@ -1,9 +1,9 @@ import { useDataQuery } from '@dhis2/app-runtime' const key = 'queue' -const createQuery = (name) => ({ +const createQuery = (encodedName) => ({ [key]: { - resource: `scheduler/queues/${name}`, + resource: `scheduler/queues/${encodedName}`, params: { fields: ['cronExpression', 'sequence', 'name'], }, @@ -11,7 +11,8 @@ const createQuery = (name) => ({ }) const useQueueByName = (name) => { - const fetch = useDataQuery(createQuery(name)) + const encodedName = encodeURIComponent(name) + const fetch = useDataQuery(createQuery(encodedName)) // Remove nesting from data if (fetch.data) { diff --git a/src/hooks/queues/use-submit-queue.js b/src/hooks/queues/use-submit-queue.js index 7631b71c5..1ebf0b9b0 100644 --- a/src/hooks/queues/use-submit-queue.js +++ b/src/hooks/queues/use-submit-queue.js @@ -1,8 +1,8 @@ import { useDataEngine } from '@dhis2/app-runtime' import formatError from '../../services/format-error' -const createMutation = (name) => ({ - resource: `scheduler/queues/${name}`, +const createMutation = (encodedName) => ({ + resource: `scheduler/queues/${encodedName}`, type: 'create', data: ({ queue }) => queue, }) @@ -10,7 +10,8 @@ const createMutation = (name) => ({ const useSubmitQueue = ({ onSuccess } = {}) => { const engine = useDataEngine() const submitQueue = (queue) => { - const mutation = createMutation(queue.name) + const encodedName = encodeURIComponent(queue.name) + const mutation = createMutation(encodedName) return engine .mutate(mutation, { variables: { queue } }) .then(() => { diff --git a/src/hooks/queues/use-update-queue.js b/src/hooks/queues/use-update-queue.js index 1634c79e7..6d42827c9 100644 --- a/src/hooks/queues/use-update-queue.js +++ b/src/hooks/queues/use-update-queue.js @@ -1,8 +1,8 @@ import { useDataEngine } from '@dhis2/app-runtime' import formatError from '../../services/format-error' -const createMutation = (name) => ({ - resource: `scheduler/queues/${name}`, +const createMutation = (encodedInitialName) => ({ + resource: `scheduler/queues/${encodedInitialName}`, type: 'update', data: ({ queue }) => queue, }) @@ -10,7 +10,8 @@ const createMutation = (name) => ({ const useUpdateQueue = ({ onSuccess, initialName } = {}) => { const engine = useDataEngine() const updateQueue = (queue) => { - const mutation = createMutation(initialName) + const encodedInitialName = encodeURIComponent(initialName) + const mutation = createMutation(encodedInitialName) return engine .mutate(mutation, { variables: { queue } }) .then(() => {