From 6948d6f1b7dc8500b07bf7af54d8925f3ea6a12c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 1 Mar 2024 09:50:33 +0100 Subject: [PATCH] fix: Make sure that nodeType is called using numeric values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- appinfo/routes.php | 4 ++-- lib/Controller/ApiFavoriteController.php | 2 ++ src/shared/constants.js | 23 +++++++++++++++++++++++ src/store/store.js | 9 +++++---- 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/shared/constants.js diff --git a/appinfo/routes.php b/appinfo/routes.php index 5f733dfbc..f3c58beb5 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -126,7 +126,7 @@ ['name' => 'ApiColumns#createSelectionColumn', 'url' => '/api/2/columns/selection', 'verb' => 'POST'], ['name' => 'ApiColumns#createDatetimeColumn', 'url' => '/api/2/columns/datetime', 'verb' => 'POST'], - ['name' => 'ApiFavorite#create', 'url' => '/api/2/favorites/{nodeType}/{nodeId}', 'verb' => 'POST'], - ['name' => 'ApiFavorite#destroy', 'url' => '/api/2/favorites/{nodeType}/{nodeId}', 'verb' => 'DELETE'], + ['name' => 'ApiFavorite#create', 'url' => '/api/2/favorites/{nodeType}/{nodeId}', 'verb' => 'POST', 'requirements' => ['nodeType' => '(\d+)', 'nodeId' => '(\d+)']], + ['name' => 'ApiFavorite#destroy', 'url' => '/api/2/favorites/{nodeType}/{nodeId}', 'verb' => 'DELETE', 'requirements' => ['nodeType' => '(\d+)', 'nodeId' => '(\d+)']], ] ]; diff --git a/lib/Controller/ApiFavoriteController.php b/lib/Controller/ApiFavoriteController.php index 6c08cec6a..372b45892 100644 --- a/lib/Controller/ApiFavoriteController.php +++ b/lib/Controller/ApiFavoriteController.php @@ -1,5 +1,7 @@ + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +export const NODE_TYPE_TABLE = 0 +export const NODE_TYPE_VIEW = 1 diff --git a/src/store/store.js b/src/store/store.js index 9e9a7240a..8245baba1 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -6,6 +6,7 @@ import { showError } from '@nextcloud/dialogs' import '@nextcloud/dialogs/dist/index.css' import data from './data.js' import displayError from '../shared/utils/displayError.js' +import { NODE_TYPE_TABLE, NODE_TYPE_VIEW } from '../shared/constants.js' Vue.use(Vuex) @@ -236,7 +237,7 @@ export default new Vuex.Store({ }, async favoriteView({ state, commit, dispatch }, { id }) { try { - await axios.post(generateOcsUrl('/apps/tables/api/2/favorites/views/' + id)) + await axios.post(generateOcsUrl(`/apps/tables/api/2/favorites/${NODE_TYPE_VIEW}/${id}`)) } catch (e) { displayError(e, t('tables', 'Could not favorite view')) return false @@ -251,7 +252,7 @@ export default new Vuex.Store({ }, async removeFavoriteView({ state, commit, dispatch }, { id }) { try { - await axios.delete(generateOcsUrl('/apps/tables/api/2/favorites/views/' + id)) + await axios.delete(generateOcsUrl(`/apps/tables/api/2/favorites/${NODE_TYPE_VIEW}/${id}`)) } catch (e) { displayError(e, t('tables', 'Could not remove view from favorites')) return false @@ -266,7 +267,7 @@ export default new Vuex.Store({ }, async favoriteTable({ state, commit, dispatch }, { id }) { try { - await axios.post(generateOcsUrl('/apps/tables/api/2/favorites/tables/' + id)) + await axios.post(generateOcsUrl(`/apps/tables/api/2/favorites/${NODE_TYPE_TABLE}/${id}`)) } catch (e) { displayError(e, t('tables', 'Could not favorite table')) return false @@ -281,7 +282,7 @@ export default new Vuex.Store({ }, async removeFavoriteTable({ state, commit, dispatch }, { id }) { try { - await axios.delete(generateOcsUrl('/apps/tables/api/2/favorites/tables/' + id)) + await axios.delete(generateOcsUrl(`/apps/tables/api/2/favorites/${NODE_TYPE_TABLE}/${id}`)) } catch (e) { displayError(e, t('tables', 'Could not remove table from favorites')) return false