SINGLE_LIST mode

This commit is contained in:
Sam Wing 2019-11-18 13:57:47 -05:00
parent ff2de11c5c
commit c42b202a85
2 changed files with 17 additions and 0 deletions

View file

@ -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
```

View file

@ -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));