API Docs for: 1.5.0
Show:

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:

  • **error** either false or CAPIError object when an error occurred
    
  • **response** the Response object
    

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 ConnectionManager

    connection manager that will be used to send requests to REST service

  • discoveryService DiscoveryService

    discovery service is used for urls auto-discovery automation

Example:

var userService = jsCAPI.getUserService();

Methods

addPolicy

(
  • roleId
  • policyCreateStruct
  • callback
)

Add the new policy to the target role

Parameters:

  • roleId String

    target role identifier (e.g. "/api/ezp/v2/user/roles/7")

  • policyCreateStruct PolicyCreateStruct

    object describing new policy to be created

  • callback Function

    callback 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 String

    target user identifier (e.g. "/api/ezp/v2/user/users/8")

  • roleAssignInputStruct RoleAssignInputStruct

    object describing the new role assignment (see "newRoleAssignInputStruct")

  • callback Function

    callback 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 String

    target user group identifier (e.g. "/api/ezp/v2/user/groups/2")

  • roleAssignInputStruct RoleAssignInputStruct

    object describing the new role assignment (see "newRoleAssignInputStruct")

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

createRole

(
  • roleCreateStruct
  • callback
)

Create a new role

Parameters:

  • roleCreateStruct RoleCreateStruct

    object describing new role to be created

  • callback Function

    callback 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:

createUser

(
  • userGroupId
  • userCreateStruct
  • callback
)

Create a new user

Parameters:

  • userGroupId String

    target user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")

  • userCreateStruct UserCreateStruct

    object describing new user to be created

  • callback Function

    callback 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 String

    target parent user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")

  • userGroupCreateStruct UserGroupCreateStruct

    object describing new user group to be created

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

deletePolicy

(
  • policyId
  • callback
)

Delete the target policy

Parameters:

  • policyId String

    target policy identifier (e.g. "/api/ezp/v2/user/roles/7/policies/1")

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

deleteRole

(
  • roleId
  • callback
)

Delete the target role

Parameters:

  • roleId String

    target role identifier (e.g. "/api/ezp/v2/user/roles/5")

  • callback Function

    callback 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 String

    target session identifier (e.g. "/api/ezp/v2/user/sessions/o7i8r1sapfc9r84ae53bgq8gp4")

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

deleteUser

(
  • userId
  • callback
)

Delete the target user

Parameters:

  • userId String

    target user identifier (e.g. "/api/ezp/v2/user/users/144")

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

deleteUserGroup

(
  • userGroupId
  • callback
)

Delete the target user group

Parameters:

  • userGroupId String

    target user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")

  • callback Function

    callback 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 String

    target role identifier (e.g. "/api/ezp/v2/user/roles/5")

  • callback Function

    callback 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 String

    target user identifier (e.g. "/api/ezp/v2/user/users/8")

  • callback Function

    callback 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 String

    target user group identifier (e.g. "/api/ezp/v2/user/groups/2")

  • callback Function

    callback 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 String

    target role assignment identifier (e.g. "/api/ezp/v2/user/13/roles/7")

  • callback Function

    callback 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 String

    target role assignment identifier (e.g. "/api/ezp/v2/user/groups/1/5/110/roles/7")

  • callback Function

    callback 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

loadPolicies

(
  • roleId
  • callback
)

Load policies of the target role

Parameters:

  • roleId String

    target role identifier (e.g. "/api/ezp/v2/user/roles/7")

  • callback Function

    callback 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 String

    link to root UserPolicies resource (should be auto-discovered)

  • userId String

    target user numerical identifier (e.g. 110)

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

loadPolicy

(
  • policyId
  • callback
)

Load the target policy

Parameters:

  • policyId String

    target policy identifier (e.g. "/api/ezp/v2/user/roles/7/policies/1")

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

loadRole

(
  • roleId
  • callback
)

Load the target role

Parameters:

  • roleId String

    target role identifier (e.g. "/api/ezp/v2/user/roles/5")

  • callback Function

    callback 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 optional

    string identifier of the roles to search (e.g. "admin")

  • [limit=-1] Number optional

    the limit of the result set

  • [offset=0] Number optional

    the offset of the result set

  • callback Function

    callback 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:

loadSubUserGroups

(
  • userGroupId
  • callback
)

Load subgroups of the target user group

Parameters:

  • userGroupId String

    target user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")

  • callback Function

    callback 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 String

    target user identifier (e.g. "/api/ezp/v2/user/users/144")

  • userGroupId String

    target user group identifier (e.g. "/api/ezp/v2/user/groups/2")

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

loadUser

(
  • userId
  • callback
)

Load the target user

Parameters:

  • userId String

    target user identifier (e.g. "/api/ezp/v2/user/users/144")

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

loadUserGroup

(
  • userGroupId
  • callback
)

Load the target user group

Parameters:

  • userGroupId String

    target user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")

  • callback Function

    callback 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 String

    link to root UserGroups resource (should be auto-discovered)

  • remoteId String

    target user group remote identifier (e.g. "f5c88a2209584891056f987fd965b0ba")

  • callback Function

    callback 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 String

    target user identifier (e.g. "/api/ezp/v2/user/users/14")

  • callback Function

    callback 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 String

    target user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")

  • callback Function

    callback 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 String

    target user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")

  • destination String

    destination identifier (e.g. "/api/ezp/v2/user/groups/1/5/110")

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

newPolicyCreateStruct

(
  • module
  • theFunction
  • limitations
)
PolicyCreateStruct

Returns policy create structure

Parameters:

  • module String

    name of the module for which new policy should be active

  • theFunction String

    name of the function for which the new policy should be active

  • limitations Object

    object describing limitations for new policy

Returns:

Example:

var policyCreateStruct = userService.newPolicyCreateStruct(
    "content", "publish", [{
        limitation: [{
            "_identifier": "Section",
            "values": {
                "ref": [{
                    "_href": "5"
                }, {
                    "_href": "4"
                }]
            }
        }]
    }]
);

newPolicyUpdateStruct

(
  • limitations
)
PolicyUpdateStruct

Policy update structure

Parameters:

  • limitations Object

    object describing limitations change for the policy (see "newPolicyCreateStruct" example)

Returns:

newRoleAssignInputStruct

(
  • role
  • limitation
)
RoleAssignInputStruct

Returns target role assignment input structure

Parameters:

  • role Object

    object representing the target role (see example)

  • limitation Object

    object representing limitations for assignment (see example)

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
)
RoleInputStruct

Returns role input structure

Parameters:

  • identifier String

    unique identifier for the new role (e.g. "editor")

Returns:

newSessionCreateStruct

(
  • login
  • password
)
SessionCreateStruct

Returns session create structure

Parameters:

  • login String

    user's login

  • password String

    user's password

newUserCreateStruct

(
  • languageCode
  • login
  • email
  • password
  • fields
)
UserCreateStruct

User create structure

Parameters:

  • languageCode String

    The language code (eng-GB, fre-FR, ...)

  • login String

    login for a new user

  • email String

    email for a new user

  • password String

    password for a new user

  • fields Array

    fields array (see example for UserService.newUserGroupCreateStruct)

Returns:

newUserGroupCreateStruct

(
  • language
  • fields
)
UserGroupCreateStruct

Returns user group create structure

Parameters:

  • language String

    The language code (eng-GB, fre-FR, ...)

  • fields Array

    fields array (see example)

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"
    }]
);

newUserGroupUpdateStruct

() UserGroupCreateStruct

User group update structure

newUserUpdateStruct

() UserUpdateStruct

Returns user update structure

Returns:

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 String

    the session identifier (e.g. "o7i8r1sapfc9r84ae53bgq8gp4")

  • callback Function

unassignRoleFromUser

(
  • userRoleId
  • callback
)

Remove target assignment (of a user to a role)

Parameters:

  • userRoleId String

    target role assignment identifier (e.g. "/api/ezp/v2/user/users/110/roles/7")

  • callback Function

    callback 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 String

    target role assignment identifier (e.g. "/api/ezp/v2/user/groups/2/roles/7")

  • callback Function

    callback 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 String

    target assignment identifier (e.g. "/api/ezp/v2/user/users/146/groups/1")

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

updatePolicy

(
  • policyId
  • policyUpdateStruct
  • callback
)

Update the target policy

Parameters:

  • policyId String

    target policy identifier (e.g. "/api/ezp/v2/user/roles/7/policies/1")

  • policyUpdateStruct PolicyUpdateStruct

    object describing changes to the policy

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

updateRole

(
  • roleId
  • roleUpdateStruct
  • callback
)

Update the target role

Parameters:

  • roleId String

    target role identifier (e.g. "/api/ezp/v2/user/roles/5")

  • roleUpdateStruct RoleUpdateStruct

    object describing changes to the role

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)

updateUser

(
  • userId
  • userUpdateStruct
  • callback
)

Update the target user

Parameters:

  • userId String

    target user identifier (e.g. "/api/ezp/v2/user/users/144")

  • userUpdateStruct UserUpdateStruct

    object describing changes to the user

  • callback Function

    callback 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 String

    target user group identifier (e.g. "/api/ezp/v2/user/groups/1/5")

  • userGroupUpdateStruct UserGroupUpdateStruct

    object describing changes to the target user group

  • callback Function

    callback executed after performing the request (see Note on the callbacks usage for more info)