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:
-
connectionManager
ConnectionManagerconnection manager that will be used to send requests to REST service
-
discoveryService
DiscoveryServicediscovery 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:
-
roleId
Stringtarget role identifier (e.g. "/api/ezp/v2/user/roles/7")
-
policyCreateStruct
PolicyCreateStructobject describing new policy to be created
-
callback
Functioncallback 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:
-
userId
Stringtarget user identifier (e.g. "/api/ezp/v2/user/users/8")
-
roleAssignInputStruct
RoleAssignInputStructobject describing the new role assignment (see "newRoleAssignInputStruct")
-
callback
Functioncallback 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:
-
userGroupId
Stringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/2")
-
roleAssignInputStruct
RoleAssignInputStructobject describing the new role assignment (see "newRoleAssignInputStruct")
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
createRole
-
roleCreateStruct
-
callback
Create a new role
Parameters:
-
roleCreateStruct
RoleCreateStructobject describing new role to be created
-
callback
Functioncallback 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:
-
sessionCreateStruct
SessionCreateStructobject describing new session to be created (see "newSessionCreateStruct")
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
createUser
-
userGroupId
-
userCreateStruct
-
callback
Create a new user
Parameters:
-
userGroupId
Stringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
userCreateStruct
UserCreateStructobject describing new user to be created
-
callback
Functioncallback 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:
-
parentGroupId
Stringtarget parent user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
userGroupCreateStruct
UserGroupCreateStructobject describing new user group to be created
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
deletePolicy
-
policyId
-
callback
Delete the target policy
Parameters:
-
policyId
Stringtarget policy identifier (e.g. "/api/ezp/v2/user/roles/7/policies/1")
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
deleteRole
-
roleId
-
callback
Delete the target role
Parameters:
-
roleId
Stringtarget role identifier (e.g. "/api/ezp/v2/user/roles/5")
-
callback
Functioncallback 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:
-
sessionId
Stringtarget session identifier (e.g. "/api/ezp/v2/user/sessions/o7i8r1sapfc9r84ae53bgq8gp4")
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
deleteUser
-
userId
-
callback
Delete the target user
Parameters:
-
userId
Stringtarget user identifier (e.g. "/api/ezp/v2/user/users/144")
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
deleteUserGroup
-
userGroupId
-
callback
Delete the target user group
Parameters:
-
userGroupId
Stringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
callback
Functioncallback 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:
-
roleId
Stringtarget role identifier (e.g. "/api/ezp/v2/user/roles/5")
-
callback
Functioncallback 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:
-
userId
Stringtarget user identifier (e.g. "/api/ezp/v2/user/users/8")
-
callback
Functioncallback 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:
-
userGroupId
Stringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/2")
-
callback
Functioncallback 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:
-
userAssignmentId
Stringtarget role assignment identifier (e.g. "/api/ezp/v2/user/13/roles/7")
-
callback
Functioncallback 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:
-
userGroupAssignmentId
Stringtarget role assignment identifier (e.g. "/api/ezp/v2/user/groups/1/5/110/roles/7")
-
callback
Functioncallback 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:
-
login
String -
callback
Function-
available
CAPIError | Boolean
-
loadPolicies
-
roleId
-
callback
Load policies of the target role
Parameters:
-
roleId
Stringtarget role identifier (e.g. "/api/ezp/v2/user/roles/7")
-
callback
Functioncallback 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:
-
userPolicies
Stringlink to root UserPolicies resource (should be auto-discovered)
-
userId
Stringtarget user numerical identifier (e.g. 110)
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadPolicy
-
policyId
-
callback
Load the target policy
Parameters:
-
policyId
Stringtarget policy identifier (e.g. "/api/ezp/v2/user/roles/7/policies/1")
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadRole
-
roleId
-
callback
Load the target role
Parameters:
-
roleId
Stringtarget role identifier (e.g. "/api/ezp/v2/user/roles/5")
-
callback
Functioncallback 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
-
callback
Functioncallback 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:
-
callback
Functioncallback 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:
-
userGroupId
Stringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
callback
Functioncallback 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:
-
userId
Stringtarget user identifier (e.g. "/api/ezp/v2/user/users/144")
-
userGroupId
Stringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/2")
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadUser
-
userId
-
callback
Load the target user
Parameters:
-
userId
Stringtarget user identifier (e.g. "/api/ezp/v2/user/users/144")
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
loadUserGroup
-
userGroupId
-
callback
Load the target user group
Parameters:
-
userGroupId
Stringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
callback
Functioncallback 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:
-
userGroups
Stringlink to root UserGroups resource (should be auto-discovered)
-
remoteId
Stringtarget user group remote identifier (e.g. "f5c88a2209584891056f987fd965b0ba")
-
callback
Functioncallback 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:
-
userId
Stringtarget user identifier (e.g. "/api/ezp/v2/user/users/14")
-
callback
Functioncallback 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:
-
userGroupId
Stringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
callback
Functioncallback 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:
-
userGroupId
Stringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
destination
Stringdestination identifier (e.g. "/api/ezp/v2/user/groups/1/5/110")
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
newPolicyCreateStruct
-
module
-
theFunction
-
limitations
Returns policy create structure
Parameters:
-
module
Stringname of the module for which new policy should be active
-
theFunction
Stringname of the function for which the new policy should be active
-
limitations
Objectobject 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:
-
limitations
Objectobject describing limitations change for the policy (see "newPolicyCreateStruct" example)
Returns:
newRoleAssignInputStruct
-
role
-
limitation
Returns target role assignment input structure
Parameters:
-
role
Objectobject representing the target role (see example)
-
limitation
Objectobject 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:
-
identifier
Stringunique identifier for the new role (e.g. "editor")
Returns:
newSessionCreateStruct
-
login
-
password
Returns session create structure
Parameters:
-
login
Stringuser's login
-
password
Stringuser's password
Returns:
newUserCreateStruct
-
languageCode
-
login
-
email
-
password
-
fields
User create structure
Parameters:
-
languageCode
StringThe language code (eng-GB, fre-FR, ...)
-
login
Stringlogin for a new user
-
email
Stringemail for a new user
-
password
Stringpassword for a new user
-
fields
Arrayfields array (see example for UserService.newUserGroupCreateStruct)
Returns:
newUserGroupCreateStruct
-
language
-
fields
Returns user group create structure
Parameters:
-
language
StringThe language code (eng-GB, fre-FR, ...)
-
fields
Arrayfields 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:
-
sessionId
Stringthe session identifier (e.g. "o7i8r1sapfc9r84ae53bgq8gp4")
-
callback
Function
unassignRoleFromUser
-
userRoleId
-
callback
Remove target assignment (of a user to a role)
Parameters:
-
userRoleId
Stringtarget role assignment identifier (e.g. "/api/ezp/v2/user/users/110/roles/7")
-
callback
Functioncallback 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:
-
userGroupRoleId
Stringtarget role assignment identifier (e.g. "/api/ezp/v2/user/groups/2/roles/7")
-
callback
Functioncallback 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:
-
userAssignedGroupId
Stringtarget assignment identifier (e.g. "/api/ezp/v2/user/users/146/groups/1")
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
updatePolicy
-
policyId
-
policyUpdateStruct
-
callback
Update the target policy
Parameters:
-
policyId
Stringtarget policy identifier (e.g. "/api/ezp/v2/user/roles/7/policies/1")
-
policyUpdateStruct
PolicyUpdateStructobject describing changes to the policy
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
updateRole
-
roleId
-
roleUpdateStruct
-
callback
Update the target role
Parameters:
-
roleId
Stringtarget role identifier (e.g. "/api/ezp/v2/user/roles/5")
-
roleUpdateStruct
RoleUpdateStructobject describing changes to the role
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)
updateUser
-
userId
-
userUpdateStruct
-
callback
Update the target user
Parameters:
-
userId
Stringtarget user identifier (e.g. "/api/ezp/v2/user/users/144")
-
userUpdateStruct
UserUpdateStructobject describing changes to the user
-
callback
Functioncallback 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:
-
userGroupId
Stringtarget user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")
-
userGroupUpdateStruct
UserGroupUpdateStructobject describing changes to the target user group
-
callback
Functioncallback executed after performing the request (see Note on the callbacks usage for more info)