Skip to content

Roles

Introduction

Roles are used to manage Permissions in intratool.

The binding of Permissions to a Role is done by a pivot table called permission_role, in which each Permission of the unique Role is assigned.

Those Roles will then get assigned to a Department so that every member of a Department has the same Permissions unless the Permissions are not modified for a specific User .

All this data can then be retrieved/created or modified via the Roles API.

Model & Relations

Namespace

App\Role

Relations

RelationKeyTypeRelation Field(s)
UsersusersHas manyusers.role_id
DepartmentdepartmentBelongs todepartment_id
DepartmentsdepartmentsHas manydepartments.role_id
Departmentsinfoboard_departmentsBelongs to manyIntermediate table
PermissionspermissionsBelongs to manyIntermediate table

List

Get a list of all Roles.

Definition

GET /api/roles

Example Request

php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/roles', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);

Example Response

json
[
  {
    "id": 2,
    "name": "Usergroup-1",
    "active": 1,
    "department_id": 2,
    "sort_number": 1,
    "created_at": "2019-01-21 13:55:33",
    "updated_at": "2019-01-21 13:56:22",
    "deleted_at": null,
    "department": {
      "id": 2,
      "name": "Usergroup-1"
    },
    "permissions": [
      {
        "id": 1,
        "type": "infoboard",
        "name": "infoboard-administration-rights",
        "description": "Administrationsrechte",
        "sort_number": 2
      },
      {
        "id": 12,
        "type": "infoboard",
        "name": "infoboard-show",
        "description": "Infoboard anzeigen",
        "sort_number": 1
      },
      {
        "id": 100,
        "type": "manual",
        "name": "manual-administration-rights",
        "description": "Administrationsrechte",
        "sort_number": 101
      }
    ]
  }
]

Get

Get a single Role by id.

Definition

GET /api/roles/{id}

Example Request

php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/roles/3', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);

Example Response

json
{
  "id": 3,
  "name": "Usergroup-2",
  "active": 1,
  "department_id": 3,
  "sort_number": 2,
  "created_at": "2019-01-21 13:55:35",
  "updated_at": "2019-01-21 13:56:24",
  "deleted_at": null,
  "department": {
    "id": 3,
    "name": "Usergroup-2"
  },
  "permissions": [
    {
      "id": 12,
      "type": "infoboard",
      "name": "infoboard-show",
      "description": "Infoboard anzeigen",
      "sort_number": 1
    }
  ],
  "departments": [
    {
      "id": 3,
      "name": "Usergroup-2"
    }
  ],
  "infoboard_departments": [
    {
      "id": 3,
      "name": "Usergroup-2"
    }
  ]
}

Create

Create a new Role.

Definition

POST /api/roles

Request Keys

KeyTypeDefaultDescription
department_id *integer-Related Department
name *string-Name of the Role
activebooleantrueWhether the Role active
permissions_ids *string-The granted Permissions of the Role
department_idsstringRelated DepartmentThe Departments the Role has access to view content from
infoboard_department_idsstringRelated DepartmentThe Departments the Role is allowed to assign InfoboardPosts to
sort_numberintegerCurrent highest +1The index of the Role

Keys with * are required.

Example Request

php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/roles', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'department_id' => 7,
        'name' => 'Usergroup-4',
        'permission_ids' => '1'
    ]
]);

Example Response

json
{
  "status": "success",
  "data": {
    "department_id": 7,
    "name": "Usergroup-4",
    "sort_number": -1,
    "active": 1,
    "updated_at": "2019-01-24 15:58:18",
    "created_at": "2019-01-24 15:58:18",
    "id": 5
  }
}

Update

Update an existing Role by id.

Definition

PUT /api/roles/{id}

Request Keys

KeyTypeDescription
department_idintegerRelated Department
namestringName of the Role
activebooleanWhether the Role active
permissions_idsstringThe granted Permissions of the Role
department_idsstringThe Departments the Role has access to view content from
infoboard_department_idsstringThe Departments the Role is allowed to assign InfoboardPosts to
sort_numberintegerThe index of the Role

Example Request

php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('PUT', '/api/roles/5', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'department_ids' => '2'
    ]
]);

Example Response

json
{
  "status": "success",
  "data": {
    "id": 5,
    "name": "Usergroup-4",
    "active": 1,
    "department_id": 7,
    "sort_number": 4,
    "created_at": "2019-01-24 15:58:18",
    "updated_at": "2019-01-24 15:58:19",
    "deleted_at": null
  }
}

Delete

Delete an existing Role by id.

Definition

DELETE /api/roles/{id}

Example Request

php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('DELETE', '/api/roles/5', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);

Example Response

json
{
  "status": "success",
  "data": []
}