# Permissions System

## Overview

The mg-dojscript permission system allows granular access control for each service. It uses a **bit flags** system to optimize storage and permission checks.

## Accessing the Permissions Page

<figure><img src="https://1860794455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCvAynUdbw9243yqwmbdR%2Fuploads%2Fgit-blob-536c6ef69957e5b4340db7bcf1700fc7bef2463b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

The permissions management page is accessible via:

* Open your service page
* Click on role management button

## Available Permissions List

The system has **10 distinct permissions**:

| Permission            | Description                                     |
| --------------------- | ----------------------------------------------- |
| `MANAGE_FOLDERS`      | Create and edit investigations                  |
| `MANAGE_DOCUMENTS`    | Create and edit documents                       |
| `MANAGE_WARRANTS`     | Create and edit warrants                        |
| `ISSUE_WARRANTS`      | Issue/send warrants (Justice only)              |
| `MANAGE_EXAMINATIONS` | Create and edit examinations                    |
| `MANAGE_REQUESTS`     | Manage requests (currently disabled)            |
| `MANAGE_RECORDS`      | Edit criminal records                           |
| `MANAGE_SERVICES`     | Manage membership requests and service settings |
| `MANAGE_VIOLATIONS`   | Create and edit violations                      |
| `ARCHIVE_FOLDERS`     | Archive investigations (Justice only)           |

{% hint style="danger" %}
DON'T FORGET TO SAVE

<img src="https://1860794455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCvAynUdbw9243yqwmbdR%2Fuploads%2Fgit-blob-1cb7f9654ec7cb0a6c774e8d5a833d20d8173b3e%2Fimage%20(47).png?alt=media" alt="" data-size="original">
{% endhint %}

## Management Interface

### Features

#### 1. Adding Roles

* Maximum **6 custom roles** per service
* The `USER` role is permanent and cannot be deleted
* Unique name validation

#### 2. Editing Roles

* Rename existing roles (except `USER`)
* Modify permissions via checkboxes
* Deletion possible (except `USER`)

#### 3. Permission Management

* Table interface with:
  * **Rows**: List of 10 permissions
  * **Columns**: Service roles
* Checkboxes to enable/disable each permission

#### 4. Smart Save

During save:

**a) Automatic User Synchronization**

* Users whose role was deleted are demoted to `USER` role
* Users keep their role if it still exists
* Automatic update of permission values if modified

**b) Service Chiefs Update**

* Chiefs automatically receive the **highest role** (highest permission value)
* Ensures chiefs always have maximum access

**c) Change Propagation**

* Changes are sent to the server
* Cascading update of service, users, and chiefs
