#31 - Allow removing an item from others' wishlist if you added it (#40)

This commit is contained in:
Coal 2022-10-11 06:44:14 -06:00 committed by GitHub
parent e5330d678f
commit 51842add77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View file

@ -161,13 +161,14 @@ module.exports = (db) => {
}) })
router.post('/:user/remove/:itemId', verifyAuth(), async (req, res) => { router.post('/:user/remove/:itemId', verifyAuth(), async (req, res) => {
if (req.user._id !== req.params.user) { const doc = await db.get(req.params.user)
req.flash('error', _CC.lang('WISHLIST_REMOVE_GUARD'))
return res.redirect(`/wishlist/${req.params.user}`)
}
const doc = await db.get(req.user._id)
for (let i = 0; i < doc.wishlist.length; i++) { for (let i = 0; i < doc.wishlist.length; i++) {
if (doc.wishlist[i].id === req.params.itemId) { if (doc.wishlist[i].id === req.params.itemId) {
if (req.user._id !== req.params.user && doc.wishlist[i].addedBy !== req.user._id) {
req.flash('error', _CC.lang('WISHLIST_REMOVE_GUARD'))
return res.redirect(`/wishlist/${req.params.user}`)
}
doc.wishlist.splice(i, 1) doc.wishlist.splice(i, 1)
await db.put(doc) await db.put(doc)
req.flash('success', _CC.lang('WISHLIST_REMOVE_SUCCESS')) req.flash('success', _CC.lang('WISHLIST_REMOVE_SUCCESS'))

View file

@ -120,7 +120,7 @@ block content
td(data-label='Delete Item') td(data-label='Delete Item')
form.inline( form.inline(
method='POST', method='POST',
action=`${_CC.config.base}wishlist/${req.params.user}/${req.user._id === req.params.user ? 'remove' : 'unpledge'}/${item.id}` action=`${_CC.config.base}wishlist/${req.params.user}/remove/${item.id}`
) )
.field.inline .field.inline
.control.inline .control.inline