Role

View as Markdown

Role

A role is a collection of permissions that will be applicable to all the users who are assigned this role.

update

The Update role call lets you modify an existing role of your stack.

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


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))

delete

The Delete role call deletes an existing role from your stack.

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


client.stack({ api_key: 'api_key'}).role('role_uid').delete()

.then((response) => console.log(response.notice))

create

The Create call creates a new role in a particular stack of your Contentstack account.

NameTypeDescription
params.roleobject

The role details with name, description and rules to be created.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })

const role = {
    "name": "Role Name",
    "description": "From CMA Js",
    "rules": [
        {
            "module": "environment",
            "environments": [],
            "acl": {
                "read": true
            }
        },
        {
            "module": "locale",
            "locales": [],
            "acl": {
                "read": true
            }
        },
        {
            "module": "taxonomy",
            "taxonomies": [
                "taxonomy_UID"
            ],
            "terms": [
                "taxonomy_UID.term_UID"
            ],
            "content_types": [
                {
                    "uid": "$all",
                    "acl": {}
                }
            ]
        }
    ]
}

client.stack({ api_key: 'api_key'}).role()
.create({ role })
.then((role) => console.log(role))

fetch

The Get a single role request returns comprehensive information on a specific role.

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


client.stack({ api_key: 'api_key'}).role('role_uid').fetch()

.then((role) => console.log(role))

fetchAll

The ‘Get all roles’ request returns comprehensive information about all roles created in a stack.

NameTypeDescription
params.include_countboolean

The `include_count’ parameter includes the count of total number of role in your stack, along with the details of each role.

params.include_permissionsboolean

Set this parameter to 'true' to include the details of the permissions assigned to a particular role.

params.limitnumber

The ‘limit’ parameter will return a specific number of role in the output.

params.skipnumber

The ‘skip’ parameter will skip a specific number of role in the response.

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


client.stack({ api_key: 'api_key'}).role()

.fetchAll()

.then((role) => console.log(role))

query

The Query on Role will allow to fetch details of all or specific role.

NameTypeDescription
params.include_countboolean

The `include_count’ parameter includes the count of total number of role in your stack, along with the details of each role.

params.include_permissionsboolean

Set this parameter to 'true' to include the details of the permissions assigned to a particular role.

params.limitnumber

The ‘limit’ parameter will return a specific number of role in the output.

params.skipnumber

The ‘skip’ parameter will skip a specific number of role in the response.

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


client.stack({ api_key: 'api_key'}).role()

.query({ query: { filename: 'Asset Name' } })

.find()

.then((role) => console.log(role))