check pinning for unknow item type and path (#9087)

This commit is contained in:
negue
2017-09-27 23:25:34 +02:00
committed by GitHub
parent 76c3e51660
commit ee6ceecc35
2 changed files with 16 additions and 2 deletions

View File

@@ -68,6 +68,7 @@
"wishlist": "Wishlist",
"items": "Items",
"wrongItemType": "The item type \"<%= type %>\" is not valid.",
"wrongItemPath": "The item path \"<%= path %>\" is not valid.",
"unpinnedItem": "You unpinned <%= item %>! It will no longer display in your Rewards column.",
"cannotUnpinArmoirPotion": "The Health Potion and Enchanted Armoire cannot be unpinned.",
"purchasedItem": "You bought <%= itemName %>",

View File

@@ -122,11 +122,24 @@ function removePinnedItemsByOwnedGear (user) {
function togglePinnedItem (user, {item, type, path}, req = {}) {
let arrayToChange;
if (!path) { // If path isn't passed it means an item was passed
if (!path) {
// If path isn't passed it means an item was passed
path = getItemInfo(user, type, item, req.language).path;
} else {
if (!item) {
item = get(content, path);
}
if (!item) {
// path not exists in our content structure
throw new BadRequest(i18n.t('wrongItemPath', {path}, req.language));
}
// check if item exists & valid to be pinned
getItemInfo(user, type, item, req.language);
}
if (!item) item = get(content, path);
if (path === 'armoire' || path === 'potion') {
throw new BadRequest(i18n.t('cannotUnpinArmoirPotion', req.language));