fix(auth): prevent system roles from being updated
- throw error in updateRole when role is system-protected - hide edit button in roles table for system roles - update README to reflect roles cannot be modified (not just renamed)
This commit is contained in:
@@ -214,7 +214,7 @@ await assignUserRole(userId, roleId);
|
|||||||
await revokeUserRole(userId, roleId);
|
await revokeUserRole(userId, roleId);
|
||||||
```
|
```
|
||||||
|
|
||||||
Les rôles système (`is_system = true`) ne peuvent pas être renommés ni supprimés.
|
Les rôles système (`is_system = true`) ne peuvent pas être modifiés ni supprimés.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export async function updateRole(roleId, { name, description, color, permissionK
|
|||||||
if (role.rows.length === 0) throw new Error('Role not found');
|
if (role.rows.length === 0) throw new Error('Role not found');
|
||||||
|
|
||||||
const isSystem = role.rows[0].is_system;
|
const isSystem = role.rows[0].is_system;
|
||||||
|
if (isSystem) throw new Error('Cannot update a system role');
|
||||||
|
|
||||||
return transaction(async (client) => {
|
return transaction(async (client) => {
|
||||||
const updateFields = [];
|
const updateFields = [];
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ const RolesPageClient = ({ canManage }) => {
|
|||||||
align: 'right',
|
align: 'right',
|
||||||
render: (role) => (
|
render: (role) => (
|
||||||
<div className="flex items-center justify-end gap-2">
|
<div className="flex items-center justify-end gap-2">
|
||||||
|
{!role.is_system && (
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
onClick={() => openEdit(role.id)}
|
onClick={() => openEdit(role.id)}
|
||||||
@@ -88,6 +89,7 @@ const RolesPageClient = ({ canManage }) => {
|
|||||||
>
|
>
|
||||||
Modifier
|
Modifier
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
{!role.is_system && (
|
{!role.is_system && (
|
||||||
<Button
|
<Button
|
||||||
variant="danger"
|
variant="danger"
|
||||||
|
|||||||
Reference in New Issue
Block a user