UserService Class
Creates an instance of user service object. Should be retrieved from CAPI instance (see example).
Note on the callbacks usage
The callback argument of the service methods always take 2 arguments:
Example:
userService.loadRootUserGroup(function (error, response) {
if (error) {
console.log('An error occurred', error);
} else {
console.log('Success!', response);
}
});
Constructor
UserService
-
connectionManager -
discoveryService
Parameters:
-
connectionManagerConnectionManagerconnection manager that will be used to send requests to REST service
-
discoveryServiceDiscoveryServicediscovery service is used for urls auto-discovery automation
Example:
var userService = jsCAPI.getUserService();
Item Index
Methods
- addPolicy
- assignRoleToUser
- assignRoleToUserGroup
- createRole
- createSession
- createUser
- createUserGroup
- deletePolicy
- deleteRole
- deleteSession
- deleteUser
- deleteUserGroup
- getRoleAssignments
- getRoleAssignmentsForUser
- getRoleAssignmentsForUserGroup
- getUserAssignmentObject
- getUserGroupAssignmentObject
- isLoginAvailable
- loadPolicies
- loadPoliciesByUserId
- loadPolicy
- loadRole
- loadRoles
- loadRootUserGroup
- loadSubUserGroups
- loadUser
- loadUser
- loadUserGroup
- loadUserGroupByRemoteId
- loadUserGroupsOfUser
- loadUsersOfUserGroup
- moveUserGroup
- newPolicyCreateStruct
- newPolicyUpdateStruct
- newRoleAssignInputStruct
- newRoleInputStruct
- newSessionCreateStruct
- newUserCreateStruct
- newUserGroupCreateStruct
- newUserGroupUpdateStruct
- newUserUpdateStruct
- refreshSession
- unassignRoleFromUser
- unassignRoleFromUserGroup
- unassignUserFromUserGroup
- updatePolicy
- updateRole
- updateUser
- updateUserGroup
Methods
addPolicy
-
roleId -
policyCreateStruct -
callback
Add the new policy to the target role
Parameters:
-
roleIdStringtarget role identifier (e.g. "/api/ezp/v2/user/roles/7")
-
policyCreateStructPolicyCreateStructobject describing new policy to be created
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
Example:
var policyCreateStruct = userService.newPolicyCreateStruct(
"content",
"create",
[{ _identifier: "Class",
values: {
ref: [{
_href: "18"
}]
}
}]);
userService.addPolicy(
"/api/ezp/v2/user/roles/7",
policyCreateStruct,
callback);
assignRoleToUser
-
userId -
roleAssignInputStruct -
callback
Assign a role to user
Parameters:
-
userIdStringtarget user identifier (e.g. "/api/ezp/v2/user/users/8")
-
roleAssignInputStructRoleAssignInputStructobject describing the new role assignment (see "newRoleAssignInputStruct")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
assignRoleToUserGroup
-
userGroupId -
roleAssignInputStruct -
callback
Assign a role to user group
Parameters:
-
userGroupIdStringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/2")
-
roleAssignInputStructRoleAssignInputStructobject describing the new role assignment (see "newRoleAssignInputStruct")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
createRole
-
roleCreateStruct -
callback
Create a new role
Parameters:
-
roleCreateStructRoleCreateStructobject describing new role to be created
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
createSession
-
sessionCreateStruct -
callback
Creates a session. This method only creates a session, for a complete
and correct authentication from CAPI point of view, you need to use
the logIn method of the CAPI
object
Parameters:
-
sessionCreateStructSessionCreateStructobject describing new session to be created (see "newSessionCreateStruct")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
createUser
-
userGroupId -
userCreateStruct -
callback
Create a new user
Parameters:
-
userGroupIdStringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
userCreateStructUserCreateStructobject describing new user to be created
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
createUserGroup
-
parentGroupId -
userGroupCreateStruct -
callback
Create a new user group in the provided parent user group
Parameters:
-
parentGroupIdStringtarget parent user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
userGroupCreateStructUserGroupCreateStructobject describing new user group to be created
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
deletePolicy
-
policyId -
callback
Delete the target policy
Parameters:
-
policyIdStringtarget policy identifier (e.g. "/api/ezp/v2/user/roles/7/policies/1")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
deleteRole
-
roleId -
callback
Delete the target role
Parameters:
-
roleIdStringtarget role identifier (e.g. "/api/ezp/v2/user/roles/5")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
deleteSession
-
sessionId -
callback
Delete the target session. For a complete and correct de-authentifcation,
you need to use the logOut method of
the CAPI object
Parameters:
-
sessionIdStringtarget session identifier (e.g. "/api/ezp/v2/user/sessions/o7i8r1sapfc9r84ae53bgq8gp4")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
deleteUser
-
userId -
callback
Delete the target user
Parameters:
-
userIdStringtarget user identifier (e.g. "/api/ezp/v2/user/users/144")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
deleteUserGroup
-
userGroupId -
callback
Delete the target user group
Parameters:
-
userGroupIdStringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
getRoleAssignments
-
roleId -
callback
Load users and usergroups for the target roleId
Parameters:
-
roleIdStringtarget role identifier (e.g. "/api/ezp/v2/user/roles/5")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
getRoleAssignmentsForUser
-
userId -
callback
Get role assignments for the target user
Parameters:
-
userIdStringtarget user identifier (e.g. "/api/ezp/v2/user/users/8")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
getRoleAssignmentsForUserGroup
-
userGroupId -
callback
Get role assignments for the target user group
Parameters:
-
userGroupIdStringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/2")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
getUserAssignmentObject
-
userAssignmentId -
callback
Get RoleAssignment object for the target assignment (of a user to a role)
Parameters:
-
userAssignmentIdStringtarget role assignment identifier (e.g. "/api/ezp/v2/user/13/roles/7")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
getUserGroupAssignmentObject
-
userGroupAssignmentId -
callback
Get RoleAssignment object for the target assignment (of a user group to a role)
Parameters:
-
userGroupAssignmentIdStringtarget role assignment identifier (e.g. "/api/ezp/v2/user/groups/1/5/110/roles/7")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
isLoginAvailable
-
login -
callback
Checks if the given login is available.
Parameters:
-
loginString -
callbackFunction-
availableCAPIError | Boolean
-
loadPolicies
-
roleId -
callback
Load policies of the target role
Parameters:
-
roleIdStringtarget role identifier (e.g. "/api/ezp/v2/user/roles/7")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadPoliciesByUserId
-
userPolicies -
userId -
callback
Load policies for the target user
Parameters:
-
userPoliciesStringlink to root UserPolicies resource (should be auto-discovered)
-
userIdStringtarget user numerical identifier (e.g. 110)
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadPolicy
-
policyId -
callback
Load the target policy
Parameters:
-
policyIdStringtarget policy identifier (e.g. "/api/ezp/v2/user/roles/7/policies/1")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadRole
-
roleId -
callback
Load the target role
Parameters:
-
roleIdStringtarget role identifier (e.g. "/api/ezp/v2/user/roles/5")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadRoles
-
[identifier] -
[limit=-1] -
[offset=0] -
callback
Search roles by string identifier and apply certain limit and offset on the result set
Parameters:
-
[identifier]String optionalstring identifier of the roles to search (e.g. "admin")
-
[limit=-1]Number optionalthe limit of the result set
-
[offset=0]Number optionalthe offset of the result set
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
Example:
userService.loadRoles("admin", 5, 5, callback);
loadRootUserGroup
-
callback
Load the root user group
Parameters:
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadSubUserGroups
-
userGroupId -
callback
Load subgroups of the target user group
Parameters:
-
userGroupIdStringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadUser
-
userId -
userGroupId -
callback
Assign the target user to the target user group
Parameters:
-
userIdStringtarget user identifier (e.g. "/api/ezp/v2/user/users/144")
-
userGroupIdStringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/2")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadUser
-
userId -
callback
Load the target user
Parameters:
-
userIdStringtarget user identifier (e.g. "/api/ezp/v2/user/users/144")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadUserGroup
-
userGroupId -
callback
Load the target user group
Parameters:
-
userGroupIdStringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadUserGroupByRemoteId
-
userGroups -
remoteId -
callback
Load the target user group by remoteId
Parameters:
-
userGroupsStringlink to root UserGroups resource (should be auto-discovered)
-
remoteIdStringtarget user group remote identifier (e.g. "f5c88a2209584891056f987fd965b0ba")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadUserGroupsOfUser
-
userId -
callback
Load user groups for the target user
Parameters:
-
userIdStringtarget user identifier (e.g. "/api/ezp/v2/user/users/14")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadUsersOfUserGroup
-
userGroupId -
callback
Load users of the target user group
Parameters:
-
userGroupIdStringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
moveUserGroup
-
userGroupId -
destination -
callback
Move the target user group to the destination
Parameters:
-
userGroupIdStringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
destinationStringdestination identifier (e.g. "/api/ezp/v2/user/groups/1/5/110")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
newPolicyCreateStruct
-
module -
theFunction -
limitations
Returns policy create structure
Parameters:
-
moduleStringname of the module for which new policy should be active
-
theFunctionStringname of the function for which the new policy should be active
-
limitationsObjectobject describing limitations for new policy
Returns:
Example:
var policyCreateStruct = userService.newPolicyCreateStruct(
"content", "publish", [{
limitation: [{
"_identifier": "Section",
"values": {
"ref": [{
"_href": "5"
}, {
"_href": "4"
}]
}
}]
}]
);
newPolicyUpdateStruct
-
limitations
Policy update structure
Parameters:
-
limitationsObjectobject describing limitations change for the policy (see "newPolicyCreateStruct" example)
Returns:
newRoleAssignInputStruct
-
role -
limitation
Returns target role assignment input structure
Parameters:
-
roleObjectobject representing the target role (see example)
-
limitationObjectobject representing limitations for assignment (see example)
Returns:
Example:
var roleAssignCreateStruct = userService.newRoleAssignInputStruct(
{
"_href": "/api/ezp/v2/user/roles/7",
"_media-type": "application/vnd.ez.api.RoleAssignInput+json"
}, {
"_identifier": "Section",
"values": {
"ref": [{
"_href": "/api/ezp/v2/content/sections/1",
"_media-type": "application/vnd.ez.api.Section+json"
}, {
"_href": "/api/ezp/v2/content/sections/4",
"_media-type": "application/vnd.ez.api.Section+json"
}]
}
});
newRoleInputStruct
-
identifier
Returns role input structure
Parameters:
-
identifierStringunique identifier for the new role (e.g. "editor")
Returns:
newSessionCreateStruct
-
login -
password
Returns session create structure
Parameters:
-
loginStringuser's login
-
passwordStringuser's password
Returns:
newUserCreateStruct
-
languageCode -
login -
email -
password -
fields
User create structure
Parameters:
-
languageCodeStringThe language code (eng-GB, fre-FR, ...)
-
loginStringlogin for a new user
-
emailStringemail for a new user
-
passwordStringpassword for a new user
-
fieldsArrayfields array (see example for UserService.newUserGroupCreateStruct)
Returns:
newUserGroupCreateStruct
-
language -
fields
Returns user group create structure
Parameters:
-
languageStringThe language code (eng-GB, fre-FR, ...)
-
fieldsArrayfields array (see example)
Returns:
Example:
var userGroupCreateStruct = userService.newUserGroupCreateStruct(
"eng-US",[{
fieldDefinitionIdentifier: "name",
languageCode: "eng-US",
fieldValue: "UserGroup"
}, {
fieldDefinitionIdentifier: "description",
languageCode: "eng-US",
fieldValue: "This is the description of the user group"
}]
);
refreshSession
-
sessionId -
callback
Calls the refresh session resource to check whether the current session is valid. For a complete and correct is logged in check, you need to use CAPI.isLoggedIn
Parameters:
-
sessionIdStringthe session identifier (e.g. "o7i8r1sapfc9r84ae53bgq8gp4")
-
callbackFunction
unassignRoleFromUser
-
userRoleId -
callback
Remove target assignment (of a user to a role)
Parameters:
-
userRoleIdStringtarget role assignment identifier (e.g. "/api/ezp/v2/user/users/110/roles/7")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
unassignRoleFromUserGroup
-
userGroupRoleId -
callback
Remove target assignment (of a user group to a role)
Parameters:
-
userGroupRoleIdStringtarget role assignment identifier (e.g. "/api/ezp/v2/user/groups/2/roles/7")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
unassignUserFromUserGroup
-
userAssignedGroupId -
callback
Remove target assignment (of a user to a user group)
Parameters:
-
userAssignedGroupIdStringtarget assignment identifier (e.g. "/api/ezp/v2/user/users/146/groups/1")
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
updatePolicy
-
policyId -
policyUpdateStruct -
callback
Update the target policy
Parameters:
-
policyIdStringtarget policy identifier (e.g. "/api/ezp/v2/user/roles/7/policies/1")
-
policyUpdateStructPolicyUpdateStructobject describing changes to the policy
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
updateRole
-
roleId -
roleUpdateStruct -
callback
Update the target role
Parameters:
-
roleIdStringtarget role identifier (e.g. "/api/ezp/v2/user/roles/5")
-
roleUpdateStructRoleUpdateStructobject describing changes to the role
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
updateUser
-
userId -
userUpdateStruct -
callback
Update the target user
Parameters:
-
userIdStringtarget user identifier (e.g. "/api/ezp/v2/user/users/144")
-
userUpdateStructUserUpdateStructobject describing changes to the user
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
Example:
var userUpdateStruct = userService.newUserUpdateStruct();
userUpdateStruct.body.UserUpdate.email = "somenewemail@nowhere.no";
userService.updateUser(
"/api/ezp/v2/user/users/144",
userUpdateStruct,
callback
);
updateUserGroup
-
userGroupId -
userGroupUpdateStruct -
callback
Update the target user group
Parameters:
-
userGroupIdStringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
userGroupUpdateStructUserGroupUpdateStructobject describing changes to the target user group
-
callbackFunctioncallback executed after performing the request (see Note on the callbacks usage for more info)
