From 7a74647d3e5b5681b9d5d3fa9b6e12d062232683 Mon Sep 17 00:00:00 2001 From: Pitu Date: Tue, 26 Feb 2019 23:13:24 +0900 Subject: User management --- src/api/routes/admin/userDisable.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/api/routes/admin/userDisable.js (limited to 'src/api/routes/admin/userDisable.js') diff --git a/src/api/routes/admin/userDisable.js b/src/api/routes/admin/userDisable.js new file mode 100644 index 0000000..c7dffa8 --- /dev/null +++ b/src/api/routes/admin/userDisable.js @@ -0,0 +1,27 @@ +const Route = require('../../structures/Route'); + +class userDisable extends Route { + constructor() { + super('/admin/users/disable', 'post', { adminOnly: true }); + } + + async run(req, res, db) { + if (!req.body) return res.status(400).json({ message: 'No body provided' }); + const { id } = req.body; + if (!id) return res.status(400).json({ message: 'No id provided' }); + + try { + await db.table('users') + .where({ id }) + .update({ enabled: false }); + } catch (error) { + return super.error(res, error); + } + + return res.json({ + message: 'Successfully disabled user' + }); + } +} + +module.exports = userDisable; -- cgit v1.2.3 From 197e69f2f2194df4ad23bb913c9efd39e1501b96 Mon Sep 17 00:00:00 2001 From: Pitu Date: Tue, 12 Mar 2019 05:48:01 +0000 Subject: Prevent snowflakes from demoting/disabling themselves --- src/api/routes/admin/userDisable.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/api/routes/admin/userDisable.js') diff --git a/src/api/routes/admin/userDisable.js b/src/api/routes/admin/userDisable.js index c7dffa8..65bcf4e 100644 --- a/src/api/routes/admin/userDisable.js +++ b/src/api/routes/admin/userDisable.js @@ -9,6 +9,7 @@ class userDisable extends Route { if (!req.body) return res.status(400).json({ message: 'No body provided' }); const { id } = req.body; if (!id) return res.status(400).json({ message: 'No id provided' }); + if (id === user.id) return res.status(400).json({ message: 'You can\'t apply this action to yourself' }); try { await db.table('users') -- cgit v1.2.3 From 79eb00f71cc18dbb195a29bd79871d35176f33d1 Mon Sep 17 00:00:00 2001 From: Pitu Date: Thu, 14 Mar 2019 23:14:24 +0900 Subject: Small fixes --- src/api/routes/admin/userDisable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/api/routes/admin/userDisable.js') diff --git a/src/api/routes/admin/userDisable.js b/src/api/routes/admin/userDisable.js index 65bcf4e..e39c811 100644 --- a/src/api/routes/admin/userDisable.js +++ b/src/api/routes/admin/userDisable.js @@ -5,7 +5,7 @@ class userDisable extends Route { super('/admin/users/disable', 'post', { adminOnly: true }); } - async run(req, res, db) { + async run(req, res, db, user) { if (!req.body) return res.status(400).json({ message: 'No body provided' }); const { id } = req.body; if (!id) return res.status(400).json({ message: 'No id provided' }); -- cgit v1.2.3