Files
directus/docs/reference/system/roles.md
Bevis Halsey-Perry 0c54f5a9ef Introduce SnippetToggler and New SDK Reference (#19110)
* items semi complete

* updated items page to use snippet toggler and migrated endpoint docs to use it

* updated files page to use snippet toggler and migrated REST and GraphQL endpoint docs to it

* updated activity page to use snippet toggler and migrated REST and GraphQL endpoint doc to it

* updated collections page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* updated dashboards page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated extensions page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated fields page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated flows page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated folders page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated notifications page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated operations page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated panels page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated permissions page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated presets page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated relations page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated revisions page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated roles page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Made headlines consistant with the rest of the doc pages

* Updated server page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated settings page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated shares page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated translations page to use snippet togglers and migrated REST endpoint docs to them

* Updated users page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated utilities page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated webhooks page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated authentication page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* Updated Global Parameters page to use snippet togglers where there are adjacent REST and GraphQL Examples

* Added SDK code snippets to items page and made generic variables consistant

* Added SDK code snippets to files  page and made generic variables consistant

* Few lang changes for files page

* Added SDK code snippets to activity page and made generic variables consistant

* Added SDK code snippets to collections page and made generic variables consistant

* Added SDK code snippets to dashboards page and made generic variables consistant

* removed query word from query parameter objects

* Added SDK code snippets to fields page and made generic variables consistant

* SnippetToggler border

* Used dynamic border color for snippettoggler heading

* Spacing top and bottom of snippet toggler in docs

* Removed extra HRs

* Remove manual TOC in query reference

* Small code styling change in items page

* Updated users page to use snippet togglers and migrated REST and GraphQL endpoint docs to them

* dashboards fixed up property names

* Small copy update on extensions page

* Updated keys in delete mult notifications REST

* Updated keys in operations

* Update keys in panel delete many

* Update keys in permissions

* Added quotes around generic example ID strings

* Added code formatting to final example in share public info

* Format files

* Refined sidebar

* Insert newline before ending template tags

* Fixed extra closing tags, causing an error, un users ref

* Text Formatting Users

* Put GQL related notes inside toggler

* Added SDK code snippets to flows page and made generic variables consistant

* Added SDK code snippets to folder page and made generic variables consistant

* fixing whitepsace for flows and folders page

* Consistent newlines in SnippetToggler usages

* Run prettier

* Fix 'alwaysDark' definition

* Home page snippet toggler style fixes

* Fix snippet toggler lang hover color in light mode

* Introduce different code theme for light mode

* Added SDK code snippets to notifications page and made generic variables consistant

* Switch to 'material-theme-lighter'

* Format file

* Fix tip

* Fix tip in sdk ref

* Consistent spacing for custom containers

* Added SDK code snippets to operations page and made generic variables consistant

* Lint & format code blocks

* Lint & format operations

* Added SDK code snippets to panels page and made generic variables consistant

* Added SDK code snippets to permissions page and made generic variables consistant

* Added SDK code snippets to presets page and made generic variables consistant

* Added SDK code snippets to relations page and made generic variables consistant

* Added SDK code snippets to revisions page and made generic variables consistant

* Added SDK code snippets to roles page and made generic variables consistant

* Added SDK code snippets to server page and made generic variables consistant

* Added SDK code snippets to settings page and made generic variables consistant

* app_url -> directus_project_url

* Omitted auth details in delete multiple files

* Added quotes to values in roles

* Upload a file snippets

* Pluralization for upload/import files

* More files functions typos

* Added SDK code snippets to shares page (still missing createShare(s) as endpoint not functioning currently) and made generic variables consistant

* Added SDK code snippets to translations page (missing delete endponts because not working) and made generic variables consistant

* Added SDK code snippets to users page and made generic variables consistant

* Added SDK code snippets to webhooks page and made generic variables consistant

* Added SDK code snippets to utilites page (except cleaning cache, will be tested and added in later commit) and made generic variables consistant

* Added SDK code snippets to auth page (not login, refresh, and logout though due to errors)

* Added SDK code snippets for utilsExport and clearCache

* added github username be7DOTis to contributors

* Omit auth commands in updateComment

* utilsImport

* rename app_url generic value

* changed instances of updated*operation* to update*Operation*

* missed some 'updated' changse

* Added SDK Snippets to Query Parameters page

* Add section on file security

* added create(s)Shares SDK snippet to shares page

* added console.log to create snippets

* Added delete(s)Webhook SDK snippet to webhooks page

* Added SDK snippets to extensions page

* Added create/updateSingleton section to items page

* Links in files security

* Added SDK Snippets to Schema page

* Added GQL Generic examples to snippet togglers and removed snippet toggler from Login Using SSO Providers

* Added create(s)Presets SDK Snippets to presets page

* replaced fields query in generics snippets for a more generic

* replaced fields query in generics snippets for a more generic

* Use storage value only if valid choice

* Sync snippet togglers across page

* Update docs/reference/system/activity.md

* Update docs/reference/system/activity.md

* Update docs/reference/system/extensions.md

* Update docs/reference/system/revisions.md

* Update docs/reference/system/settings.md

* Update docs/reference/system/revisions.md

* Update docs/reference/system/settings.md

* Update docs/reference/system/activity.md

* Update docs/reference/system/roles.md

* Update docs/reference/system/roles.md

* Update docs/reference/system/roles.md

* Update docs/reference/system/roles.md

* Update docs/reference/system/schema.md

* Update docs/reference/system/server.md

* Update docs/reference/system/shares.md

* Replace all directus_project_url placeholders

* Revert "Sync snippet togglers across page"

This reverts commit 8b36f0d778.

* Update docs/reference/system/shares.md

* Update docs/reference/system/webhooks.md

* Clarify singleton section

* Consistent newlines between SnippetToggler templates

* Format files

* Remove console.log(result) statements from snippet

* Add examples for shares & users

Co-authored-by: Brainslug <tim@brainslug.nl>

* Fix hash GraphQL example

* Clarify update singleton section

* Add auth examples

Co-authored-by: Brainslug <tim@brainslug.nl>

* Final run on consistent newlines between SnippetToggler

* Switch to github themes

* The "Last One"

Co-authored-by: Brainslug <tim@brainslug.nl>

* The "Big One"

* Fix dead links

---------

Co-authored-by: Bevis Halsey-Perry <hi@be7.is>
Co-authored-by: Kevin Lewis <kvn@lws.io>
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
Co-authored-by: Brainslug <tim@brainslug.nl>
2023-07-25 17:30:37 -04:00

16 KiB

description, readTime, pageClass
description readTime pageClass
REST and GraphQL API documentation on the Roles collection in Directus. 5 min read page-reference

Roles

Roles define a specific set of access permissions, and are the primary organizational structure for Users within the platform. Learn more about Roles.

The Role Object

id uuid
Primary key of the role.

name string
Name of the role.

icon string
Icon for the role. Displayed in the Admin App.

description string
Description for the role. Displayed in the Admin App.

ip_access csv
A CSV of IP addresses that have access to this role. Allows you to configure an allowlist of IP addresses.

enforce_tfa boolean
Whether or not Two-Factor Authentication is required for users in this role.

admin_access boolean
If this role is considered an admin role. This means that users in this role have full permissions to everything.

app_access boolean
Whether or not users in this role have access to use the Admin App.

users one-to-many
The users in this role. One-to-many to users.

{
	"id": "653925a9-970e-487a-bfc0-ab6c96affcdc",
	"name": "Admin",
	"icon": "supervised_user_circle",
	"description": null,
	"ip_access": null,
	"enforce_tfa": false,
	"admin_access": true,
	"app_access": true,
	"users": ["0bc7b36a-9ba9-4ce0-83f0-0a526f354e07"]
}

List Roles

List all roles that exist in Directus.

Request

GET /roles

SEARCH /roles

POST /graphql/system

type Query {
	roles: [directus_roles]
}
import { createDirectus } from '@directus/sdk';
import { rest, readRoles } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	readRoles({
		fields: ['*'],
	})
);

Learn more about SEARCH ->

Query Parameters

Supports all global query parameters.

Response

An array of up to limit role objects. If no items are available, data will be an empty array.

Example

GET /roles

SEARCH /roles

POST /graphql/system

query {
	roles {
		id
		name
		users {
			email
		}
	}
}
import { createDirectus } from '@directus/sdk';
import { rest, readRoles } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	readRoles({
		fields: ['*'],
	})
);

Retrieve a Role

List an existing role by primary key.

GET /roles/:id

POST /graphql/system

type Query {
	roles_by_id(id: ID!): directus_roles
}
import { createDirectus } from '@directus/sdk';
import { rest, readRole } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	readRole('role_id', {
		fields: ['*'],
	})
);

Query Parameters

Supports all global query parameters.

Response

Returns the requested role object.

Example

GET /roles/b4cb3b64-8580-4ad9-a099-eade6da24302

POST /graphql/system

query {
	roles_by_id(id: 2) {
		id
		name
		users {
			email
		}
	}
}
import { createDirectus } from '@directus/sdk';
import { rest, readRole } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	readRole('39a178f6-d4d6-40e1-b0e7-ec6daaac8747', {
		fields: ['*'],
	})
);

Create a Role

Create a new role.

Request

POST /roles

{
	"role_field_1": "value_1",
	"role_field_2": "value_2",
	"role_field_3": "value_3",
	"role_field_4": "value_4",
	"role_field_5": "value_5"
}

POST /graphql/system

type Mutation {
	create_roles_item(data: create_directus_roles_input!): directus_roles
}
import { createDirectus } from '@directus/sdk';
import { rest, createRole } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	createRole({
		role_field_1: 'value_1',
		role_field_2: 'value_2',
		role_field_3: 'value_3',
		role_field_4: 'value_4',
		role_field_5: 'value_5',
	})
);

Query Parameters

Supports all global query parameters.

Request Body

A partial role object.

Response

Returns the role object for the created role.

Example

POST /roles

{
	"name": "Interns",
	"icon": "verified_user",
	"description": null,
	"admin_access": false,
	"app_access": true
}

POST /graphql/system

mutation {
	create_roles_item(
		data: { name: "Interns", icon: "verified_user", description: null, admin_access: false, app_access: true }
	) {
		id
		name
		users {
			email
		}
	}
}
import { createDirectus } from '@directus/sdk';
import { rest, createRole } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	createRole({
		name: 'Interns',
		icon: 'verified_user',
		description: null,
		admin_access: false,
		app_access: true,
	})
);

Create Multiple Roles

Create multiple new roles.

Request

POST /roles

[
	{
		"role_object_1_field_1": "value_1",
		"role_object_1_field_2": "value_2",
		"role_object_1_field_3": "value_3",
		"role_object_1_field_4": "value_4",
		"role_object_1_field_5": "value_5"
	},
	{
		"role_object_2_field_1": "value_6",
		"role_object_2_field_2": "value_7",
		"role_object_2_field_3": "value_8",
		"role_object_2_field_4": "value_9",
		"role_object_2_field_5": "value_10"
	}
]

POST /graphql/system

type Mutation {
	create_roles_items(data: [create_directus_roles_input!]!): [directus_roles]
}
import { createDirectus } from '@directus/sdk';
import { rest, createRoles } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	createRoles([
		{
			role_object_1_field_1: 'value_1',
			role_object_1_field_2: 'value_2',
			role_object_1_field_3: 'value_3',
			role_object_1_field_4: 'value_4',
			role_object_1_field_5: 'value_5',
		},
		{
			role_object_2_field_1: 'value_6',
			role_object_2_field_2: 'value_7',
			role_object_2_field_3: 'value_8',
			role_object_2_field_4: 'value_9',
			role_object_2_field_5: 'value_10',
		},
	])
);

Query Parameters

Supports all global query parameters.

Request Body

An array of partial role objects.

Response

Returns the role objects for the created roles.

Example

POST /roles

[
	{
		"name": "Interns",
		"icon": "verified_user",
		"description": null,
		"admin_access": false,
		"app_access": true
	},
	{
		"name": "Customers",
		"icon": "person",
		"description": null,
		"admin_access": false,
		"app_access": false
	}
]

POST /graphql/system

mutation {
	create_roles_items(
		data: [
			{ name: "Interns", icon: "verified_user", description: null, admin_access: false, app_access: true }
			{ name: "Customers", icon: "person", description: null, admin_access: false, app_access: false }
		]
	) {
		id
		name
		users {
			email
		}
	}
}
import { createDirectus } from '@directus/sdk';
import { rest, createRoles } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	createRoles([
		{
			name: 'Interns',
			icon: 'verified_user',
			description: null,
			admin_access: false,
			app_access: true,
		},
		{
			name: 'Customers',
			icon: 'person',
			description: null,
			admin_access: false,
			app_access: false,
		},
	])
);

Update a Role

Update an existing role.

Request

PATCH /roles/:id

{
	"roles_object_field": "value_1"
}

POST /graphql/system

type Mutation {
	update_roles_item(id: ID!, data: update_directus_roles_input): directus_roles
}
import { createDirectus } from '@directus/sdk';
import { rest, updateRole } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	updateRole('role_id', {
		role_field: 'value',
	})
);

Query Parameters

Supports all global query parameters.

Request Body

A partial role object.

Response

Returns the role object for the updated role.

Example

PATCH /roles/c86c2761-65d3-43c3-897f-6f74ad6a5bd7

{
	"icon": "attractions"
}

POST /graphql/system

mutation {
	update_roles_item(id: "c86c2761-65d3-43c3-897f-6f74ad6a5bd7", data: { icon: "attractions" }) {
		id
		name
		users {
			email
		}
	}
}
import { createDirectus } from '@directus/sdk';
import { rest, updateRole } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	updateRole('a262a7f6-9ed4-423d-8cd2-3ee3b2d2a658', {
		admin_access: true,
	})
);

Update Multiple Roles

Update multiple existing roles.

Request

PATCH /roles

{
	"keys": ["role_1_key", "role_2_key"],
	"data": {
		"role_object_field": "value_1"
	}
}

POST /graphql/system

type Mutation {
	update_roles_items(ids: [ID!]!, data: update_directus_roles_input): [directus_roles]
}
import { createDirectus } from '@directus/sdk';
import { rest, updateRoles } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	updateRoles(['role_1_id', 'role_2_id'], {
		field: 'value',
	})
);

Query Parameters

Supports all global query parameters.

Request Body

keys Required
Array of primary keys of the roles you'd like to update.

data Required
Any of the role object's properties.

Response

Returns the role objects for the updated roles.

Example

PATCH /roles

{
	"keys": ["c86c2761-65d3-43c3-897f-6f74ad6a5bd7", "6fc3d5d3-a37b-4da8-a2f4-ed62ad5abe03"],
	"data": {
		"icon": "attractions"
	}
}

POST /graphql/system

mutation {
	update_roles_items(
		ids: ["c86c2761-65d3-43c3-897f-6f74ad6a5bd7", "6fc3d5d3-a37b-4da8-a2f4-ed62ad5abe03"]
		data: { icon: "attractions" }
	) {
		id
		name
		users {
			email
		}
	}
}
import { createDirectus } from '@directus/sdk';
import { rest, updateRoles } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	updateRoles(['a262a7f6-9ed4-423d-8cd2-3ee3b2d2a658', '1792dc2c-6142-4723-ae40-698d082ddc5e'], {
		admin_access: true,
	})
);

Delete a Role

Delete an existing role.

Request

DELETE /roles/:id

POST /graphql/system

type Mutation {
	delete_roles_item(id: ID!): delete_one
}
import { createDirectus } from '@directus/sdk';
import { rest, deleteRole } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(deleteRole('role_id'));

Response

Empty body.

Example

DELETE /roles/c86c2761-65d3-43c3-897f-6f74ad6a5bd7

POST /graphql/system

mutation {
	delete_roles_item(id: "c86c2761-65d3-43c3-897f-6f74ad6a5bd7") {
		id
	}
}
import { createDirectus } from '@directus/sdk';
import { rest, deleteRole } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(deleteRole('1792dc2c-6142-4723-ae40-698d082ddc5e'));

Delete Multiple Roles

Delete multiple existing roles.

Request

DELETE /roles

["role_1_key", "role_2_key"]

POST /graphql/system

type Mutation {
	delete_roles_items(ids: [ID!]!): delete_many
}
import { createDirectus } from '@directus/sdk';
import { rest, deleteRoles } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(deleteRoles(['role_1_id', 'role_2_id']));

Request Body

An array of role primary keys

Response

Empty body.

Example

DELETE /roles

["653925a9-970e-487a-bfc0-ab6c96affcdc", "c86c2761-65d3-43c3-897f-6f74ad6a5bd7"]

POST /graphql/system

mutation {
	delete_roles_items(ids: ["653925a9-970e-487a-bfc0-ab6c96affcdc", "c86c2761-65d3-43c3-897f-6f74ad6a5bd7"]) {
		ids
	}
}
import { createDirectus } from '@directus/sdk';
import { rest, deleteRoles } from '@directus/sdk/rest';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	deleteRoles(['a262a7f6-9ed4-423d-8cd2-3ee3b2d2a658', '1792dc2c-6142-4723-ae40-698d082ddc5e'])
);