mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
refactor: /users/{delete,disable,edit} API routes
simplify self.assertPermission function to only assert permission fixed hard-coded "root" user protection not being asserted first
This commit is contained in:
parent
0a62002a6e
commit
8142eae9df
@ -230,12 +230,10 @@ self.changePassword = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.assertPermission = (user, target) => {
|
self.assertPermission = (user, target) => {
|
||||||
if (!target) {
|
if (target.username === 'root') {
|
||||||
throw new ClientError('Could not get user with the specified ID.')
|
throw new ClientError('User "root" may not be tampered with.', { statusCode: 403 })
|
||||||
} else if (!perms.higher(user, target)) {
|
} else if (!perms.higher(user, target)) {
|
||||||
throw new ClientError('The user is in the same or higher group as you.', { statusCode: 403 })
|
throw new ClientError('The user is in the same or higher group as you.', { statusCode: 403 })
|
||||||
} else if (target.username === 'root') {
|
|
||||||
throw new ClientError('Root user may not be tampered with.', { statusCode: 403 })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,6 +317,10 @@ self.editUser = async (req, res) => {
|
|||||||
.where('id', id)
|
.where('id', id)
|
||||||
.first()
|
.first()
|
||||||
|
|
||||||
|
if (!target) {
|
||||||
|
throw new ClientError('Could not get user with the specified ID.')
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure this user has permission to tamper with target user
|
// Ensure this user has permission to tamper with target user
|
||||||
self.assertPermission(req.locals.user, target)
|
self.assertPermission(req.locals.user, target)
|
||||||
|
|
||||||
@ -387,6 +389,10 @@ self.deleteUser = async (req, res) => {
|
|||||||
.where('id', id)
|
.where('id', id)
|
||||||
.first()
|
.first()
|
||||||
|
|
||||||
|
if (!target) {
|
||||||
|
throw new ClientError('Could not get user with the specified ID.')
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure this user has permission to tamper with target user
|
// Ensure this user has permission to tamper with target user
|
||||||
self.assertPermission(req.locals.user, target)
|
self.assertPermission(req.locals.user, target)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user