Navigation Menu

Skip to content
This repository has been archived by the owner on Oct 3, 2021. It is now read-only.

Commit

Permalink
let moderators edit and delete bots
Browse files Browse the repository at this point in the history
  • Loading branch information
jellz committed May 8, 2019
1 parent 860e473 commit b6857ac
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions server/routes/bots.js
Expand Up @@ -97,8 +97,8 @@ router.delete('/:id', async (req, res) => {
.get(req.params.id)
.run();
if (!bot) return res.status(404).json({ error: 'Invalid bot' });
// TODO: allow moderators to delete bots (i need to make a permission system first)
if (bot.ownerId !== req.user.id) return res.status(403).json({ error: 'You can only delete bots you own' })
if (!(bot.ownerId == req.user.id || !req.user.flags.includes('moderator')))
return res.status(403).json({ error: 'You can only delete bots you own' });

await r
.table('bots')
Expand Down Expand Up @@ -153,8 +153,8 @@ router.patch('/:id', editBotLimiter, async (req, res) => {
.get(req.params.id)
.run();
if (!bot) return res.status(404).json({ error: 'Invalid bot' });
if (bot.ownerId !== req.user.id) return res.status(403).json({ error: 'You can only edit bots you own' });

if (!(bot.ownerId == req.user.id || !req.user.flags.includes('moderator')))
return res.status(403).json({ error: 'You can only edit bots you own' });
let data = filterUnexpectedData(req.body, { verified: false }, editBotSchema);

if (
Expand Down Expand Up @@ -250,7 +250,8 @@ router.post('/:id/stats', async (req, res) => {
.run();
if (!bot) return res.status(404).json({ error: 'Invalid bot' });

if (!req.headers.authorization) return res.header('WWW-Authenticate', 'API-Key').sendStatus(401);
if (!req.headers.authorization)
return res.header('WWW-Authenticate', 'API-Key').sendStatus(401);
if (bot.apiKey !== req.headers.authorization.split(' ')[1])
return res.status(403).json({ error: 'Invalid API key' });

Expand Down

0 comments on commit b6857ac

Please sign in to comment.