Skip to content

Commit

Permalink
fix: Make sure that nodeType is called using numeric values
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Mar 1, 2024
1 parent d38fd2b commit a50fca9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)']],
]
];
2 changes: 2 additions & 0 deletions lib/Controller/ApiFavoriteController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OCA\Tables\Controller;

use Exception;
Expand Down
23 changes: 23 additions & 0 deletions src/shared/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* @copyright Copyright (c) 2024 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>.
*/

export const NODE_TYPE_TABLE = 0
export const NODE_TYPE_VIEW = 1
9 changes: 5 additions & 4 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a50fca9

Please sign in to comment.