Skip to content
This repository has been archived by the owner on Oct 8, 2019. It is now read-only.

Roles & Permissions

Pascal Boucher edited this page Jun 11, 2018 · 1 revision

Shortcuts

Creating a Role - Get Roles - Deleting a Role - Setting a User Role - Get User Roles - Delete User Role - Get Role Permissions - Add Role Permissions - Remove Role Permissions

Sudo token required

Access to the Roles and Permissions API requires a sudo token.

Creating a Role

@param  array $role
@return bool

Chatkit::roles()->store($role);

scope (string|required): Scope of the new role; one of global or room.

name (string|required): Name of the new role.

permissions (array|required): Permissions assigned to the role.

Example

$created = Chatkit::roles()->store([
    'name' => 'Test role',
    'scope' => 'global',
    'permissions' => ['room:join', 'room:leave']
]);

Api reference

Get Roles

@return \Illuminate\Support\Collection

Example

$roles = Chatkit::roles()->index();

Api reference

Deleting a Role

@param  string $roleName
@param  string $scopeName
@return \Illuminate\Support\Collection

scopeName (string|required): Scope of the role; one of global or room.

Example

$role = new \Chess\Chatkit\Models\Role($roleName);

$deleted = $role->scope($scopeName)->delete();

Api reference

Setting a User Role

@param  string $userId
@param  array $role
@param  int|optional $roomId
@return bool

$user->roles()->assign($role);

name (string|required): Name of the role.

room_id (integer|optional): The ID of the room you want to set the user role for. If no room_id value is provided then the scope will be global.

Example

$user = new \Chess\Chatkit\Models\User($userId);

$assigned = $user->roles()->assign([
    'name' => 'Super Test',
    'room_id' => $roomId
]);

Api reference

Get User Roles

@param  string $userId
@return \Illuminate\Support\Collection

Example

$user = new \Chess\Chatkit\Models\User($userId);

$roles = $user->roles()->get();

Api reference

Delete User Role

@param  string $userId
@param  int|optional $roomId
@return bool

roomId (integer|optional): The ID of the room you want to delete the user role for. If not provided then if the userId has an associated (non-default) user role at the global scope, that will be deleted.

Example

$user = new \Chess\Chatkit\Models\User($userId);

$deleted = $user->roles()->delete(); // global scope

OR with room scope

$user = new \Chess\Chatkit\Models\User($userId);

$deleted = $user->roles()->delete($roomId); // room scope

Api reference

Get Role Permissions

@param  string $roleName
@param  string $scopeName
@return array

scopeName (string|required): Scope of the role; one of global or room.

Example

$role = new \Chess\Chatkit\Models\Role($roleName);

$permissions = $role->scope($scopeName)->permissions()->get();

Api reference

Add Role Permissions

@param  string $roleName
@param  string $scopeName
@param  array $permissions
@return bool

$role->scope($scopeName)->permissions()->add($permissions);

scopeName (string|required): Scope of the role; one of global or room.

Example

$role = new \Chess\Chatkit\Models\Role($roleName);

$added = $role->scope($scopeName)->permissions()->add([
    'room:typing_indicator:create',
    'room:update'
]);

Available permissions

Api reference

Remove Role Permissions

@param  string $roleName
@param  string $scopeName
@param  array $permissions
@return bool

$role->scope($scopeName)->permissions()->remove($permissions);

scopeName (string|required): Scope of the role; one of global or room.

Example

$role = new \Chess\Chatkit\Models\Role($roleName);

$removed = $role->scope($scopeName)->permissions()->remove([
    'room:typing_indicator:create',
    'room:update'
]);

Available permissions

Api reference