fix: #179 shared wishlist not accessible

This commit is contained in:
grandeljay 2023-11-12 12:11:48 +01:00
parent 87de601872
commit 2966a5c109
3 changed files with 60 additions and 29 deletions

View file

@ -104,7 +104,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
case 'GET': case 'GET':
$getWishlistCardsFromPriority = isset($_GET['wishlist_id'], $_GET['priority']); $getWishlistCardsFromPriority = isset($_GET['wishlist_id'], $_GET['priority']);
$getWishlistFromHash = isset($_GET['wishlist_hash']); $getWishlistFromHash = isset($_GET['wishlist_hash'], $_GET['priority']);
$getOwnWishlists = $user->isLoggedIn(); $getOwnWishlists = $user->isLoggedIn();
if ($getWishlistCardsFromPriority) { if ($getWishlistCardsFromPriority) {
@ -170,16 +170,30 @@ switch ($_SERVER['REQUEST_METHOD']) {
} elseif ($getWishlistFromHash) { } elseif ($getWishlistFromHash) {
$wishlist = Wishlist::getFromHash($_GET['wishlist_hash']); $wishlist = Wishlist::getFromHash($_GET['wishlist_hash']);
if ($wishlist instanceof Wishlist) { $priorityAll = -1;
$response['results'] = array( $priorityNone = 0;
'id' => $wishlist->getId(), $priority = (int) $_GET['priority'] ?? $priorityAll;
'hash' => $wishlist->getHash(),
'userId' => $wishlist->getUserId(), $options = array(
); 'style' => $_GET['style'],
; 'placeholders' => array(),
} else { );
http_response_code(404); $where = array(
'wishlist' => '`wishlist` = ' . $wishlist->getId(),
'priority' => '`priority` = ' . $priority,
);
if ($priorityAll === $priority) {
unset($where['priority']);
} }
if ($priorityNone === $priority) {
$where['priority'] = '`priority` IS NULL OR `priority` = 0';
}
$options['WHERE'] = '(' . implode(') AND (', $where) . ')';
$response['results'] = $wishlist->getCards($options);
} elseif ($getOwnWishlists) { } elseif ($getOwnWishlists) {
$wishlists = array(); $wishlists = array();
$wishlistsItems = array(); $wishlistsItems = array();

View file

@ -162,11 +162,12 @@ global $options;
*/ */
<?php <?php
$api_urls = array( $api_urls = array(
'get wishlists' => '/index.php?page=api&module=wishlists', 'get wishlists' => '/index.php?page=api&module=wishlists',
'get wishlists by priority' => '/index.php?page=api&module=wishlists&style={style}&wishlist_id={wishlistid}&priority={priority}', 'get wishes by wishlist id' => '/index.php?page=api&module=wishlists&style={style}&priority={priority}&wishlist_id={wishlistid}',
'delete wishlist' => '/index.php?page=api&module=wishlists', 'get wishes by wishlist hash' => '/index.php?page=api&module=wishlists&style={style}&priority={priority}&wishlist_hash={wishlisthash}',
'update wish status' => '/index.php?page=api&module=wishes', 'delete wishlist' => '/index.php?page=api&module=wishlists',
'delete wish' => '/index.php?page=api&module=wishes&wish_id={wishid}', 'update wish status' => '/index.php?page=api&module=wishes',
'delete wish' => '/index.php?page=api&module=wishes&wish_id={wishid}',
); );
?> ?>

View file

@ -3,26 +3,42 @@ $(function () {
/** /**
* Filter wishes * Filter wishes
*/ */
var apiGetWishesByWishlistId = function (settings) {
var wishlistId = $('.wishlist-cards[data-wishlist]').attr('data-wishlist');
if (undefined === wishthis.$_GET.id && undefined !== wishlistId && wishlistId.length > 0) {
wishthis.$_GET.id = wishlistId;
}
settings.urlData.style = $('input[name="style"]').val();
settings.urlData.priority = $('.ui.dropdown.filter.priority').dropdown('get value');
settings.urlData.wishlistid = wishthis.$_GET.id;
return settings;
};
var apiGetWishesByWishlistHash = function (settings) {
settings.urlData.style = $('input[name="style"]').val();
settings.urlData.priority = $('.ui.dropdown.filter.priority').dropdown('get value');
settings.urlData.wishlisthash = wishthis.$_GET.hash;
return settings;
};
var action = 'get wishes by wishlist id';
var apiGetWishes = apiGetWishesByWishlistId;
if (wishthis.$_GET.hash) {
var action = 'get wishes by wishlist hash';
var apiGetWishes = apiGetWishesByWishlistHash;
}
$('.ui.dropdown.filter.priority') $('.ui.dropdown.filter.priority')
.dropdown({ .dropdown({
'match' : 'text', 'match' : 'text',
'fullTextSearch' : true, 'fullTextSearch' : true,
}) })
.api({ .api({
'action' : 'get wishlists by priority', 'action' : action,
'beforeSend' : function (settings) { 'beforeSend' : apiGetWishes,
var wishlistId = $('.wishlist-cards[data-wishlist]').attr('data-wishlist');
if (undefined === wishthis.$_GET.id && undefined !== wishlistId && wishlistId.length > 0) {
wishthis.$_GET.id = wishlistId;
}
settings.urlData.style = $('input[name="style"]').val();
settings.urlData.priority = $('.ui.dropdown.filter.priority').dropdown('get value');
settings.urlData.wishlistid = wishthis.$_GET.id;
return settings;
},
'onSuccess' : function (response, dropdown_wishlists, xhr) { 'onSuccess' : function (response, dropdown_wishlists, xhr) {
var html = response.results ? response.results : ''; var html = response.results ? response.results : '';