SDK
SDK Javascript v6.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

createOrReplaceRole #

Creates a new role or, if the provided role identifier already exists, replaces it.


createOrReplaceRole(id, body, [options]);

PropertyTypeDescription
id
string
Role identifier
body
object
Role definition content
options
object
Query options

body #

PropertyTypeDescription
controllers
object
Role definition

options #

PropertyType
(default)
Description
queuable
boolean

(true)
If true, queues the request during downtime, until connected to Kuzzle again
refresh
boolean

(false)
If set to wait_for, Kuzzle will not respond until the created/replaced role is indexed

Resolves #

A Role object representing the created/replaced role.

Usage #

try {
  const response = await kuzzle.security.createOrReplaceRole(
    'read-only',
    {
      controllers: {
        auth: {
          actions: {
            getCurrentUser: true,
            getMyCredentials: true,
            getMyRights: true,
            logout: true
          }
        },
        collection: {
          actions: {
            getMapping: true,
            list: true
          }
        },
        document: {
          actions: {
            count: true,
            get: true,
            mGet: true,
            scroll: true,
            search: true
          }
        },
        index: {
          actions: {
            list: true
          }
        }
      }
    }
  );
  console.log(response);
  /*
  Role {
    _id: 'read-only',
    controllers:
      { auth: { actions: [Object] },
        collection: { actions: [Object] },
        document: { actions: [Object] },
        index: { actions: [Object] }  } }
   */
  console.log('Role successfully updated');
} catch (e) {
  console.error(e);
}