# Roles / Permissions

Just putting this here for now\...

***

**Overview**

* **Current**
  * **"role.name"-based authorization**
* **Future**
  * **"role.permissions"-based authorization**
    * Example setup
      * [**Frontend**](#frontend)
      * [**Backend** ](#backend)
    * Implementation versions:
      * [**Single role per user**](#single-role-per-user) (user.role)
      * [**Many roles per user**](#many-roles-per-user) (user.roles)

***

## Example Setup

### Frontend (e.g. allowing custom roles per company)

{% hint style="info" %}
Custom roles like this could be in addition to our "default roles": Admin, Project Manager, Read-only, etc.
{% endhint %}

<figure><img src="/files/QtxSrg8odxwn32kGt8Me" alt=""><figcaption></figcaption></figure>

### Backend

<figure><img src="/files/a8tZlXLdPfqIJvFJpZ6Z" alt=""><figcaption></figcaption></figure>

```ruby
## example implementation of limited / field supervisor-type role ("canOnlyIfOriginatedData")
## (Admin 'canOnlyIfOriginatedData' fields would be 'false')
{
    "name": 'Field Supervisor',
    "description": 'This role can view all data, and can conditionally create, update, and delete data',
    "permissions": {
        'projects': {
            'canCreate': false,
            'canRead': false,
            'canUpdate': false,
            'canDelete': false,
            'canUpdateRelationships': false
        },
        'equipment': {
            'canCreate': true,
            'canRead': true,
            'canUpdate': true,
            'canDelete': true,
            'canOnlyIfOriginatedData': true,
        },
        'production_goals': {
            'canCreate': true,
            'canRead': true,
            'canUpdate': true,
            'canDelete': true,
            'canOnlyIfOriginatedData': true
        },
        # ...
    }
}
```

***

## Single role per user

<figure><img src="/files/XmDnjscdvBS8Rozry3dr" alt=""><figcaption></figcaption></figure>

*^ ...validating the 'permissions' structure to maintain integrity*

## Many roles per user

<figure><img src="/files/DIEycRSXwvZf0ZTijbyd" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/HZRIDkVA6FkzbjXBq8IT" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pavewise.gitbook.io/pavewise-style-guide-and-more/backend/database-tables/roles-permissions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
