mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
feat: user edit functionality (managing permissions)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Router } from 'express';
|
||||
import { getRepository } from 'typeorm';
|
||||
import { User } from '../entity/User';
|
||||
import { hasPermission, Permission } from '../lib/permissions';
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -50,6 +51,36 @@ router.put<{ id: string }>('/:id', async (req, res, next) => {
|
||||
where: { id: Number(req.params.id) },
|
||||
});
|
||||
|
||||
// Only let the owner user modify themselves
|
||||
if (user.id === 1 && req.user?.id !== 1) {
|
||||
return next({
|
||||
status: 403,
|
||||
message: 'You do not have permission to modify this user',
|
||||
});
|
||||
}
|
||||
|
||||
// Only let the owner grant admin privileges
|
||||
if (
|
||||
hasPermission(Permission.ADMIN, req.body.permissions) &&
|
||||
req.user?.id !== 1
|
||||
) {
|
||||
return next({
|
||||
status: 403,
|
||||
message: 'You do not have permission to grant this level of access',
|
||||
});
|
||||
}
|
||||
|
||||
// Only let users with the manage settings permission, grant the same permission
|
||||
if (
|
||||
hasPermission(Permission.MANAGE_SETTINGS, req.body.permissions) &&
|
||||
!hasPermission(Permission.MANAGE_SETTINGS, req.user?.permissions ?? 0)
|
||||
) {
|
||||
return next({
|
||||
status: 403,
|
||||
message: 'You do not have permission to grant this level of access',
|
||||
});
|
||||
}
|
||||
|
||||
Object.assign(user, req.body);
|
||||
await userRepository.save(user);
|
||||
|
||||
|
Reference in New Issue
Block a user