diff --git a/README.md b/README.md index b14f315..14ad3b0 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,10 @@ services: SMILE: 'true' # Table mode, set to 'false' to revert to box mode TABLE: 'true' + # Single list mode + # (for weddings, birthdays, etc. only the admin account's list is accessible) + # Set to 'true' to enable + SINGLE_LIST: 'false' restart: always ``` diff --git a/routes/wishlist/index.js b/routes/wishlist/index.js index b565c21..567c46f 100644 --- a/routes/wishlist/index.js +++ b/routes/wishlist/index.js @@ -31,12 +31,25 @@ module.exports = (db) => { router.get('/', verifyAuth(), async (req, res) => { const docs = await db.allDocs({ include_docs: true }) + if (process.env.SINGLE_LIST === 'true') { + for (row of docs.rows) { + if (row.doc.admin) return res.redirect(`/wishlist/${row.doc._id}`) + } + } res.render('wishlists', { title: 'Wishlists', users: docs.rows, totals}) }); router.get('/:user', verifyAuth(), async (req, res) => { try { const dbUser = await db.get(req.params.user); + if (process.env.SINGLE_LIST === 'true') { + if (!dbUser.admin) { + const docs = await db.allDocs({ include_docs: true }) + for (row of docs.rows) { + if (row.doc.admin) return res.redirect(`/wishlist/${row.doc._id}`) + } + } + } const firstCanSee = dbUser.wishlist.findIndex(element => (element.addedBy === req.params.user)); const wishlistReverse = [...dbUser.wishlist].reverse(); const lastCanSeeValue = wishlistReverse.find(element => (element.addedBy === req.params.user));