Methods
(static) actionableScopes(user, action, definition, type, options)
- Source:
Return an array of all scopes that a given user can perform a specified action in
Example
const user = sdk.auth.getCurrentUser();
const canCreateInScopes = sdk.access.actionableScopes(user, 'create', 'car', 'article');
const canDeleteInScopes = sdk.access.actionableScopes(user, 'delete', 'profile');
// Would result in something like:
['61eca4746971e75c1fc670cf', '61eca4746971e75c1fc670ca', '77eca4746971e75c1fc670cf'],
Parameters:
| Name |
Type |
Description |
user |
Object
|
A user session object |
action |
String
|
The action |
definition |
String
|
The defined type of item the action will be performed on |
type |
String
|
The basic type of item the action will be performed on |
options |
Object
|
Additional options and parameters |
(static) allPermissions(user)
- Source:
Returns an array of all permissions a given user has access to
Example
const user = sdk.auth.getCurrentUser();
const permissions = sdk.access.allPermissions(user);
// Returns
['image.viewany', 'testimonial.viewany', 'testimonial.viewfield.title', ...]
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
(static) allPermissionTypes(user, asHash)
- Source:
Returns an array of content types a given user has permission to interact with
Example
const user = sdk.auth.getCurrentUser();
// Returns ['image', 'testimonial']
const types = sdk.access.allPermissionTypes(user);
// Returns {image:true, testimonial:true}
const types = sdk.access.allPermissionTypes(user, true);
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
asHash |
Boolean
|
Whether to retrieve the result as a keyed object hash, by default
the response will be an array |
(static) allUserScopes(user)
- Source:
Return an array of ids of all scopes that a given user has been granted a permission in
Example
const permissions = sdk.access.allUserScopes({firstName:'Mighty', lastName:'Mouse', permissionSets:[...], ...});
// Would result in:
['61eca4746971e75c1fc670cf', '61eca4746971e75c1fc670ca', '77eca4746971e75c1fc670cf'],
Parameters:
| Name |
Type |
Description |
user |
Object
|
A user session object |
(static) canCreate(user, definition, type, options)
- Source:
Helpful function for checking whether a given user can create a specified type of item
Example
const user = sdk.auth.getCurrentUser();
const userCanCreateShortFilms = sdk.access.canCreate(user, 'shortFilm', 'video');
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
definition |
String
|
The defined type key |
type |
String
|
The basic type key |
options |
Object
|
Additional options and parameters
Properties
| Name |
Type |
Description |
cache |
Object
|
Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop |
|
(static) canDeleteItem(user, item, options)
- Source:
Helpful function for checking whether a given user can delete a specified item
Example
const user = sdk.auth.getCurrentUser();
// Example of looping through a large array of items
const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
// Create an in memory cache object outside of the loop
const cache = {}
const filtered = largeArrayOfItems.filter(function(item) {
return sdk.access.canDeleteItem(user, item, {cache});
})
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
item |
Object
|
The item to check |
options |
Object
|
Additional options and parameters
Properties
| Name |
Type |
Description |
cache |
Object
|
Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop |
|
(static) canEditItem(user, item, options)
- Source:
Helpful function for checking whether a given user can edit a specified item
Example
const user = sdk.auth.getCurrentUser();
// Example of looping through a large array of items
const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
// Create an in memory cache object outside of the loop
const cache = {}
const filtered = largeArrayOfItems.filter(function(item) {
return sdk.access.canEditItem(user, item, {cache});
})
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
item |
Object
|
The item to check |
options |
Object
|
Additional options and parameters
Properties
| Name |
Type |
Description |
cache |
Object
|
Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop |
|
(static) canEraseItem(user, item, options)
- Source:
Helpful function for checking whether a given user can erase a specified item
Example
const user = sdk.auth.getCurrentUser();
// Example of looping through a large array of items
const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
// Create an in memory cache object outside of the loop
const cache = {}
const filtered = largeArrayOfItems.filter(function(item) {
return sdk.access.canEraseItem(user, item, {cache});
})
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
item |
Object
|
The item to check |
options |
Object
|
Additional options and parameters
Properties
| Name |
Type |
Description |
cache |
Object
|
Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop |
|
(static) canKnowOf(user, typeKey, options)
- Source:
Checks if a user has any permissions relating to a specified type of content
Example
const user = sdk.auth.getCurrentUser();
const canAccessImageSection = sdk.access.canKnowOf(user, 'image');
const canAccessCustomerUploadSection = sdk.access.canKnowOf(user, 'customerUpload');
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
typeKey |
String
|
The type or definition to check |
options |
Object
|
Additional options and parameters
Properties
| Name |
Type |
Description |
cache |
Object
|
Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop |
|
(static) canListItem(user, item, options)
- Source:
Helpful function for checking whether a given user can list a specified item
Example
const user = sdk.auth.getCurrentUser();
// Example of looping through a large array of items
const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
// Create an in memory cache object outside of the loop
const cache = {}
const filtered = largeArrayOfItems.filter(function(item) {
return sdk.access.canListItem(user, item, {cache});
})
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
item |
Object
|
The item to check |
options |
Object
|
Additional options and parameters
Properties
| Name |
Type |
Description |
cache |
Object
|
Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop |
|
(static) canRestoreItem(user, item, options)
- Source:
Helpful function for checking whether a given user can restore a specified item
Example
const user = sdk.auth.getCurrentUser();
// Example of looping through a large array of items
const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
// Create an in memory cache object outside of the loop
const cache = {}
const filtered = largeArrayOfItems.filter(function(item) {
return sdk.access.canRestoreItem(user, item, {cache});
})
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
item |
Object
|
The item to check |
options |
Object
|
Additional options and parameters
Properties
| Name |
Type |
Description |
cache |
Object
|
Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop |
|
(static) canViewItem(user, item, options)
- Source:
Helpful function for checking whether a given user can view a specified item
Example
const user = sdk.auth.getCurrentUser();
// Example of looping through a large array of items
const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
// Create an in memory cache object outside of the loop
const cache = {}
const filtered = largeArrayOfItems.filter(function(item) {
return sdk.access.canViewItem(user, item, {cache});
})
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
item |
Object
|
The item to check |
options |
Object
|
Additional options and parameters
Properties
| Name |
Type |
Description |
cache |
Object
|
Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop |
|
(static) checkActionAccess(user, item, ANY_ACTION, OWN_ACTION, options)
- Source:
Helpful function for checking whether a given user has access to do a given action on a specified item
Example
const user = sdk.auth.getCurrentUser();
const canEditItem = sdk.access.checkActionAccess(user, {_id:'61eca4746971e75c1fc670ca', meta:{...}}, 'editany', 'editown');
const canViewItem = sdk.access.checkActionAccess(user, {_id:'61eca4746971e75c1fc670ca', meta:{...}}, 'viewany', 'viewown');
// Example of looping through a large array of items
const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
// Create an in memory cache object outside of the loop
const cache = {}
const filtered = largeArrayOfItems.filter(function(item) {
return sdk.access.checkActionAccess(user, item, 'editany', 'editown', {cache});
})
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
item |
Object
|
The item to check |
ANY_ACTION |
String
|
The 'any' action to check |
OWN_ACTION |
String
|
The 'owned' action to check |
options |
Object
|
Additional options and parameters
Properties
| Name |
Type |
Description |
cache |
Object
|
Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop |
|
(static) getAllDescendants(scope)
- Source:
Get all children of a specified scope
Example
const childScopes = sdk.access.getAllDescendants({title:'Global', children:[{title:'Australia', ...}, {title:'New Zealand', ...}]});
Parameters:
| Name |
Type |
Description |
scope |
Object
|
A scope object with child scopes |
(static) has(user, permission)
- Source:
Helpful function for checking whether a given user has a specified permission
Example
const user = sdk.auth.getCurrentUser();
const isAllowedToCreateItems = sdk.access.has(user, 'video.create');
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
permission |
String
|
The permission the user may have been granted |
(static) hashPermissions(user)
- Source:
Get a lookup of all permissions a user has been granted
Example
const permissions = sdk.access.hashPermissions({firstName:'Mighty', lastName:'Mouse', permissionSets:[...], ...});
Parameters:
| Name |
Type |
Description |
user |
Object
|
A user session object |
(static) isAdministrator(user)
- Source:
Check if a user object is an administrator
Example
const userIsAnAdministrator = sdk.access.isAdministrator({firstName:'Jeffrey', lastName:'Winger', ...});
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user session to check |
(static) isOwner(user, item)
- Source:
Return whether or not a user is considered an Owner of a specified item
Example
const user = sdk.auth.getCurrentUser();
const item = {title:'A piece of content', meta:{personaAuthor:'61eca4746971e75c1fc670ca'}, ...}
// Returns true if the user owns the item
const isTheOwner = sdk.access.isOwner(user, item);
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user to check |
item |
Object
|
The item |