ContentModel
Summary
Defines a ContentModel class to manipulate content entities.
A content entity associate a user to the entity and add controls for CRUD operations.
ContentModel must not be used directly. Create a sub class instead.
Constructor
ContentModel
Syntax
ContentModel
-
user -
provider
Summary
Parameters:
-
userObjectThe user that will manipulate the entities
-
providerEntityProviderThe entity provider
Example:
// Example for implementing a new ContentModel named "CustomModel"
// CustomModel.js
var util = require('util');
var api = require('@openveo/api');
var CustomProvider = process.require('CustomProvider.js');
function CustomModel(user) {
// Initialize the content model with a dedicated provider
api.ContentModel.call(this, user, new CustomProvider(api.applicationStorage.getDatabase()));
}
// CustomModel must extends ContentModel
module.exports = CustomModel;
util.inherits(CustomModel, api.ContentModel);
// Example for how to use CustomModel defined in previous example
var api = require('@openveo/api');
var CustomModel = process.require('CustomModel.js');
var model = new CustomModel();
Item Index
Methods
add
Syntax
add
-
data -
callback
Summary
Adds a new content entity.
Information about the user (which becomes the owner) is added to the entity before recording.
addAccessFilter
Syntax
Summary
Adds access rule to the given filter reference.
Parameters:
-
filterObjectThe filter to add the access rule to
Returns:
The filter
get
Syntax
get
-
filter -
callback
Summary
Gets all content entities.
Only entities that the user can manipulate are returned.
getOne
Syntax
getOne
-
id -
filter -
callback
Summary
Gets a single content entity by its id.
If the user has not the necessary permissions, an error will be returned.
getPaginatedFilteredEntities
Syntax
getPaginatedFilteredEntities
-
[filter] -
[limit] -
[page] -
[sort] -
[populate] -
callback
Summary
Gets an ordered list of entities by page.
Only entities that the user can manipulate are returned.
Parameters:
-
[filter]Object optionalMongoDB filter
-
[limit]Number optionalThe maximum number of expected entities
-
[page]Number optionalThe expected page
-
[sort]Object optionalA sort object
-
[populate]Boolean optionaltrue to automatically populate results with additional information
-
callbackFunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Array The list of entities
- Object Pagination information
getUserAuthorizedGroups
Syntax
Summary
Gets the list of groups of a user, with authorization on a certain operation.
All user groups with authorization on the operation are returned.
Parameters:
-
operationStringThe operation (get, update or delete)
Returns:
The list of user group ids with authorization on the operation
getUserGroups
Syntax
Summary
Gets the list of groups from a user.
Parameters:
-
userObjectThe user to extract groups from
Returns:
Groups organized by ids
Example:
// Example of user permissions
['get-group-Jekrn20Rl', 'update-group-Jekrn20Rl', 'delete-group-YldO3Jie3', 'some-other-permission']
// Example of returned groups
{
'Jekrn20Rl': ['get', 'update'], // User only has get / update permissions on group 'Jekrn20Rl'
'YldO3Jie3': ['delete'], // User only has delete permission on group 'YldO3Jie3'
...
}
isUserAdmin
Syntax
Summary
Tests if user is the administrator.
Returns:
true if the user is the administrator, false otherwise
isUserAuthorized
Syntax
Summary
Validates that the user is authorized to manipulate a content entity.
User is authorized to manipulate the entity if one of the following conditions is met :
- No user is associated to the model
- The entity belongs to the anonymous user
- User is the super administrator
- User is the owner of the entity
- Entity has associated groups and user has permission to perform the operation on the group
Parameters:
Returns:
true if the user can manipulate the entity, false otherwise
remove
Syntax
remove
-
ids -
callback
Summary
Removes one or several entities.
User must have permission to remove the entity.
update
Syntax
update
-
id -
data -
callback
Summary
Updates an entity.
User must have permission to update the entity.