- Source:
A role is a collection of permissions that will be applicable to all the users who are assigned this role. Read more about Roles.
Methods
(static) update() → {Promise.<Role.Role>}
- Source:
The Update role call lets you modify an existing role of your stack.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).role('role_uid').fetch({ include_rules: true, include_permissions: true})
.then((role) => {
role.name = 'My New Role'
role.description = 'Role description'
role.rules = [
{
module: 'asset',
assets: ['$all'],
acl: {
read: true,
create: true,
update: true,
publish: true,
delete: true
}
},
{
module: 'environment',
environments: [],
acl: { read: true }
},
{
module: 'locale',
locales: [Array],
acl: { read: true }
}]
return role.update()
})
.then((role) => console.log(role))
Returns:
Promise for Role instance
- Type
- Promise.<Role.Role>
(static) delete() → {Object}
- Source:
The Delete role call deletes an existing role from your stack.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).role('role_uid').delete()
.then((response) => console.log(response.notice))
Returns:
Response Object.
- Type
- Object
(static) fetch(include_permissions, include_rules) → {Promise.<Role.Role>}
- Source:
The Get a single role request returns comprehensive information on a specific role.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).role('role_uid').fetch()
.then((role) => console.log(role))
Parameters:
Name | Type | Description |
---|---|---|
include_permissions |
Boolean | Set this parameter to 'true' to include the details of the permissions assigned to a particular role. |
include_rules |
Boolean | Set this to ‘true’ to include the details of the rules assigned to a role. |
Returns:
Promise for Role instance
- Type
- Promise.<Role.Role>
(static) create() → {Promise.<Role.Role>}
- Source:
The Create a role call creates a new role in a stack.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
const role = {
name: 'Role Name',
description: 'From CMA Js',
rules:
[
{
module: 'environment',
environments: [],
acl: { read: true }
},
{
module: 'locale',
locales: [],
acl: { read: true }
}
],
uid: 'uid'
}
client.stack().role().create({ role })
.then((role) => console.log(role))
Returns:
Promise for Role instance
- Type
- Promise.<Role.Role>
(static) findAll(include_permissions, include_rules) → {ContentstackCollection}
- Source:
The ‘Get all roles’ request returns comprehensive information about all roles created in a stack.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack().role().findAll()
.then((collection) => console.log(collection))
Parameters:
Name | Type | Description |
---|---|---|
include_permissions |
Boolean | Set this parameter to 'true' to include the details of the permissions assigned to a particular role. |
include_rules |
Boolean | Set this to ‘true’ to include the details of the rules assigned to a role. |
Returns:
Instance of ContentstackCollection.
- Type
- ContentstackCollection
(static) query(include_permissions, include_rules) → {ContentstackCollection}
- Source:
The Query on Role will allow to fetch details of all or specific role.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).role().query({ query: { filename: 'Asset Name' } }).find()
.then((role) => console.log(role))
Parameters:
Name | Type | Description |
---|---|---|
include_permissions |
Boolean | Set this parameter to 'true' to include the details of the permissions assigned to a particular role. |
include_rules |
Boolean | Set this to ‘true’ to include the details of the rules assigned to a role. |
Returns:
Instance of ContentstackCollection.
- Type
- ContentstackCollection