# Case Management Permissions Migration

The case and matter management module adds new API resources for tracking legal matters and their related activities. Recent additions include `case_communications` and `case_instructions` tables. To control access, update the `roles_permissions` table with the following recommendations.

## Recommended Permissions

| Role | Permissions |
|------|-------------|
| **Legal Admin** | `cases.*`, `matters.*`, `case_documents.*`, `case_events.*`, `case_communications.*`, `case_instructions.*` |
| **Super Admin** | already covered by wildcard `*.*` |

Use SQL similar to the snippet below to grant full access to the Legal Admin role. Adjust the `createdBy` value for your environment.

```sql
UPDATE roles_permissions
SET permissions = JSON_SET(
    permissions,
    '$.cases', JSON_ARRAY('*'),
    '$.matters', JSON_ARRAY('*'),
    '$.case_documents', JSON_ARRAY('*'),
    '$.case_events', JSON_ARRAY('*'),
    '$.case_communications', JSON_ARRAY('*'),
    '$.case_instructions', JSON_ARRAY('*')
)
WHERE role = 'Legal Admin';
```

If the Legal Admin role does not yet exist, insert a new row:

```sql
INSERT INTO roles_permissions (role, inheritedFrom, permissions, createdAt, createdBy)
VALUES (
    'Legal Admin',
    NULL,
    '{"cases": ["*"], "matters": ["*"], "case_documents": ["*"], "case_events": ["*"], "case_communications": ["*"], "case_instructions": ["*"]}',
    NOW(),
    1
);
```
