mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merge branch 'feature-3-0/RM-6577_AutomatedRestApiTests' into 'release/V3.0'
Resolve RM-6577 "Feature 3 0/ automatedrestapitests" See merge request records-management/records-management!1199
This commit is contained in:
@@ -32,9 +32,16 @@ package org.alfresco.rest.rm.community.model.user;
|
|||||||
* @author Kristijan Conkas
|
* @author Kristijan Conkas
|
||||||
* @since 2.6
|
* @since 2.6
|
||||||
*/
|
*/
|
||||||
public class UserPermissions
|
public enum UserPermissions
|
||||||
{
|
{
|
||||||
public static final String PERMISSION_FILING = "Filing";
|
PERMISSION_FILING("Filing"),
|
||||||
public static final String PERMISSION_READ_RECORDS = "ReadRecords";
|
PERMISSION_READ_RECORDS("ReadRecords"),
|
||||||
public static final String PERMISSION_FILE_RECORDS = "FileRecords";
|
PERMISSION_FILE_RECORDS("FileRecords");
|
||||||
|
|
||||||
|
public final String permissionId;
|
||||||
|
|
||||||
|
UserPermissions(String permissionId)
|
||||||
|
{
|
||||||
|
this.permissionId = permissionId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -113,7 +113,7 @@ public class GSCoreAPI extends RMModelRequest
|
|||||||
/**
|
/**
|
||||||
* Provides DSL on all REST calls under <code>records/...</code> API path
|
* Provides DSL on all REST calls under <code>records/...</code> API path
|
||||||
*
|
*
|
||||||
* @return {@link FilePlanComponentAPI}
|
* @return {@link RecordsAPI}
|
||||||
*/
|
*/
|
||||||
public RecordsAPI usingRecords()
|
public RecordsAPI usingRecords()
|
||||||
{
|
{
|
||||||
|
@@ -84,11 +84,11 @@ public class RMUserAPI extends RMModelRequest
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign RM role to user
|
* Assign RM role to user
|
||||||
|
*
|
||||||
* @param userName User's username
|
* @param userName User's username
|
||||||
* @param userRole User's RM role, one of {@link UserRoles} roles
|
* @param userRole User's RM role, one of {@link UserRoles} roles
|
||||||
* @throws Exception for failed requests
|
|
||||||
*/
|
*/
|
||||||
public void assignRoleToUser(String userName, String userRole) throws Exception
|
public void assignRoleToUser(String userName, String userRole)
|
||||||
{
|
{
|
||||||
UserModel adminUser = getRmRestWrapper().getTestUser();
|
UserModel adminUser = getRmRestWrapper().getTestUser();
|
||||||
|
|
||||||
@@ -117,11 +117,11 @@ public class RMUserAPI extends RMModelRequest
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to add permission on a component to user
|
* Helper method to add permission on a component to user
|
||||||
* @param component The id of the file plan component on which permission should be given
|
* @param filePlanComponentId The id of the file plan component on which permission should be given
|
||||||
* @param user {@link UserModel} for a user to be granted permission
|
* @param user {@link UserModel} for a user to be granted permission
|
||||||
* @param permission {@link UserPermissions} to be granted
|
* @param permission {@link UserPermissions} to be granted
|
||||||
*/
|
*/
|
||||||
public void addUserPermission(String filePlanComponentId, UserModel user, String permission)
|
public void addUserPermission(String filePlanComponentId, UserModel user, UserPermissions permission)
|
||||||
{
|
{
|
||||||
UserModel adminUser = getRmRestWrapper().getTestUser();
|
UserModel adminUser = getRmRestWrapper().getTestUser();
|
||||||
|
|
||||||
@@ -131,8 +131,8 @@ public class RMUserAPI extends RMModelRequest
|
|||||||
JsonObject bodyJson = buildObject()
|
JsonObject bodyJson = buildObject()
|
||||||
.addArray("permissions")
|
.addArray("permissions")
|
||||||
.addObject()
|
.addObject()
|
||||||
.add("authority", user.getUsername())
|
.add("authority", (user != null ? user.getUsername() : null))
|
||||||
.add("role", permission)
|
.add("role", permission.permissionId)
|
||||||
.end()
|
.end()
|
||||||
.getJson();
|
.getJson();
|
||||||
|
|
||||||
@@ -157,6 +157,48 @@ public class RMUserAPI extends RMModelRequest
|
|||||||
getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
|
getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to set permission inheritance on a file plan component
|
||||||
|
*
|
||||||
|
* @param filePlanComponentId The id of the file plan component on which inherited permission should be set
|
||||||
|
* @param isInherited true if the permission is inherited
|
||||||
|
* false if the permission inheritance is disabled
|
||||||
|
*/
|
||||||
|
public void setUserPermissionInheritance(String filePlanComponentId, Boolean isInherited)
|
||||||
|
{
|
||||||
|
final UserModel adminUser = getRmRestWrapper().getTestUser();
|
||||||
|
|
||||||
|
// get an "old-style" REST API client
|
||||||
|
final AlfrescoHttpClient client = getAlfrescoHttpClient();
|
||||||
|
|
||||||
|
final JsonObject bodyJson = buildObject()
|
||||||
|
.addArray("permissions")
|
||||||
|
.end()
|
||||||
|
.add("isInherited", isInherited)
|
||||||
|
.getJson();
|
||||||
|
|
||||||
|
// override v1 baseURI and basePath
|
||||||
|
RequestSpecification spec = new RequestSpecBuilder()
|
||||||
|
.setBaseUri(client.getApiUrl())
|
||||||
|
.setBasePath("/")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// execute an "old-style" API call
|
||||||
|
final Response response = given()
|
||||||
|
.spec(spec)
|
||||||
|
.auth().basic(adminUser.getUsername(), adminUser.getPassword())
|
||||||
|
.contentType(ContentType.JSON)
|
||||||
|
.body(bodyJson.toString())
|
||||||
|
.pathParam("nodeId", filePlanComponentId)
|
||||||
|
.log().all()
|
||||||
|
.when()
|
||||||
|
.post("/node/workspace/SpacesStore/{nodeId}/rmpermissions")
|
||||||
|
.prettyPeek()
|
||||||
|
.andReturn();
|
||||||
|
getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a user with the given name using the old APIs
|
* Creates a user with the given name using the old APIs
|
||||||
*
|
*
|
||||||
@@ -168,7 +210,7 @@ public class RMUserAPI extends RMModelRequest
|
|||||||
public boolean createUser(String userName, String userPassword, String userEmail)
|
public boolean createUser(String userName, String userPassword, String userEmail)
|
||||||
{
|
{
|
||||||
UserModel adminUser = getRmRestWrapper().getTestUser();
|
UserModel adminUser = getRmRestWrapper().getTestUser();
|
||||||
AlfrescoHttpClient client = getAlfrescoHttpClient();
|
final AlfrescoHttpClient client = getAlfrescoHttpClient();
|
||||||
|
|
||||||
JsonObject body = buildObject()
|
JsonObject body = buildObject()
|
||||||
.add("userName", userName)
|
.add("userName", userName)
|
||||||
@@ -178,7 +220,7 @@ public class RMUserAPI extends RMModelRequest
|
|||||||
.add("email", userEmail)
|
.add("email", userEmail)
|
||||||
.getJson();
|
.getJson();
|
||||||
|
|
||||||
RequestSpecification spec = new RequestSpecBuilder()
|
final RequestSpecification spec = new RequestSpecBuilder()
|
||||||
.setBaseUri(client.getApiUrl())
|
.setBaseUri(client.getApiUrl())
|
||||||
.setBasePath("/")
|
.setBasePath("/")
|
||||||
.setAuth(basic(adminUser.getUsername(), adminUser.getPassword()))
|
.setAuth(basic(adminUser.getUsername(), adminUser.getPassword()))
|
||||||
|
@@ -47,6 +47,7 @@ import org.alfresco.dataprep.AlfrescoHttpClientFactory;
|
|||||||
import org.alfresco.dataprep.UserService;
|
import org.alfresco.dataprep.UserService;
|
||||||
import org.alfresco.rest.core.v0.BaseAPI;
|
import org.alfresco.rest.core.v0.BaseAPI;
|
||||||
import org.alfresco.rest.core.v0.RMEvents;
|
import org.alfresco.rest.core.v0.RMEvents;
|
||||||
|
import org.alfresco.utility.Utility;
|
||||||
import org.apache.chemistry.opencmis.client.api.CmisObject;
|
import org.apache.chemistry.opencmis.client.api.CmisObject;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
@@ -72,6 +73,8 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component
|
@Component
|
||||||
public class RMRolesAndActionsAPI extends BaseAPI
|
public class RMRolesAndActionsAPI extends BaseAPI
|
||||||
{
|
{
|
||||||
|
public static final String HOLDS_CONTAINER = "Holds";
|
||||||
|
|
||||||
/** The URI to view the configured roles and capabilities. */
|
/** The URI to view the configured roles and capabilities. */
|
||||||
private static final String RM_ROLES = "{0}rma/admin/rmroles";
|
private static final String RM_ROLES = "{0}rma/admin/rmroles";
|
||||||
/** The URI for REST requests about a particular configured role. */
|
/** The URI for REST requests about a particular configured role. */
|
||||||
@@ -82,6 +85,8 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(RMRolesAndActionsAPI.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(RMRolesAndActionsAPI.class);
|
||||||
private static final String MOVE_ACTIONS_API = "action/rm-move-to/site/rm/documentLibrary/{0}";
|
private static final String MOVE_ACTIONS_API = "action/rm-move-to/site/rm/documentLibrary/{0}";
|
||||||
private static final String CREATE_HOLDS_API = "{0}type/rma:hold/formprocessor";
|
private static final String CREATE_HOLDS_API = "{0}type/rma:hold/formprocessor";
|
||||||
|
/** The URI to add items to hold.*/
|
||||||
|
private static final String RM_HOLDS_API = "{0}rma/holds";
|
||||||
|
|
||||||
/** http client factory */
|
/** http client factory */
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -101,7 +106,8 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
public Set<String> getConfiguredRoles(String adminUser, String adminPassword)
|
public Set<String> getConfiguredRoles(String adminUser, String adminPassword)
|
||||||
{
|
{
|
||||||
// Using "is=true" includes the in-place readers and writers.
|
// Using "is=true" includes the in-place readers and writers.
|
||||||
JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES + "?is=true").getJSONObject("data");
|
final JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES + "?is=true").getJSONObject
|
||||||
|
("data");
|
||||||
return jsonObject.toMap().keySet();
|
return jsonObject.toMap().keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +121,8 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
*/
|
*/
|
||||||
public Set<String> getCapabilitiesForRole(String adminUser, String adminPassword, String role)
|
public Set<String> getCapabilitiesForRole(String adminUser, String adminPassword, String role)
|
||||||
{
|
{
|
||||||
JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES + "?is=true").getJSONObject("data");
|
final JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES + "?is=true").getJSONObject
|
||||||
|
("data");
|
||||||
assertTrue("Could not find role '" + role + "' in " + jsonObject.keySet(), jsonObject.has(role));
|
assertTrue("Could not find role '" + role + "' in " + jsonObject.keySet(), jsonObject.has(role));
|
||||||
return jsonObject.getJSONObject(role).getJSONObject("capabilities").keySet();
|
return jsonObject.getJSONObject(role).getJSONObject("capabilities").keySet();
|
||||||
}
|
}
|
||||||
@@ -131,10 +138,10 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
*/
|
*/
|
||||||
public void createRole(String adminUser, String adminPassword, String roleName, String roleDisplayLabel, Set<String> capabilities)
|
public void createRole(String adminUser, String adminPassword, String roleName, String roleDisplayLabel, Set<String> capabilities)
|
||||||
{
|
{
|
||||||
JSONObject requestBody = new JSONObject();
|
final JSONObject requestBody = new JSONObject();
|
||||||
requestBody.put("name", roleName);
|
requestBody.put("name", roleName);
|
||||||
requestBody.put("displayLabel", roleDisplayLabel);
|
requestBody.put("displayLabel", roleDisplayLabel);
|
||||||
JSONArray capabilitiesArray = new JSONArray();
|
final JSONArray capabilitiesArray = new JSONArray();
|
||||||
capabilities.forEach(capabilitiesArray::put);
|
capabilities.forEach(capabilitiesArray::put);
|
||||||
requestBody.put("capabilities", capabilitiesArray);
|
requestBody.put("capabilities", capabilitiesArray);
|
||||||
doPostJsonRequest(adminUser, adminPassword, HttpStatus.SC_OK, requestBody, RM_ROLES);
|
doPostJsonRequest(adminUser, adminPassword, HttpStatus.SC_OK, requestBody, RM_ROLES);
|
||||||
@@ -151,10 +158,10 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
*/
|
*/
|
||||||
public void updateRole(String adminUser, String adminPassword, String roleName, String roleDisplayLabel, Set<String> capabilities)
|
public void updateRole(String adminUser, String adminPassword, String roleName, String roleDisplayLabel, Set<String> capabilities)
|
||||||
{
|
{
|
||||||
JSONObject requestBody = new JSONObject();
|
final JSONObject requestBody = new JSONObject();
|
||||||
requestBody.put("name", roleName);
|
requestBody.put("name", roleName);
|
||||||
requestBody.put("displayLabel", roleDisplayLabel);
|
requestBody.put("displayLabel", roleDisplayLabel);
|
||||||
JSONArray capabilitiesArray = new JSONArray();
|
final JSONArray capabilitiesArray = new JSONArray();
|
||||||
capabilities.forEach(capabilitiesArray::put);
|
capabilities.forEach(capabilitiesArray::put);
|
||||||
requestBody.put("capabilities", capabilitiesArray);
|
requestBody.put("capabilities", capabilitiesArray);
|
||||||
doPutJsonRequest(adminUser, adminPassword, HttpStatus.SC_OK, requestBody, RM_ROLES_ROLE, roleName);
|
doPutJsonRequest(adminUser, adminPassword, HttpStatus.SC_OK, requestBody, RM_ROLES_ROLE, roleName);
|
||||||
@@ -170,7 +177,7 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
public void deleteRole(String adminUser, String adminPassword, String roleName)
|
public void deleteRole(String adminUser, String adminPassword, String roleName)
|
||||||
{
|
{
|
||||||
doDeleteRequest(adminUser, adminPassword, MessageFormat.format(RM_ROLES_ROLE, "{0}", roleName));
|
doDeleteRequest(adminUser, adminPassword, MessageFormat.format(RM_ROLES_ROLE, "{0}", roleName));
|
||||||
boolean success = !getConfiguredRoles(adminUser, adminPassword).contains(roleName);
|
final boolean success = !getConfiguredRoles(adminUser, adminPassword).contains(roleName);
|
||||||
assertTrue("Failed to delete role " + roleName + " with " + adminUser, success);
|
assertTrue("Failed to delete role " + roleName + " with " + adminUser, success);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,8 +208,8 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
*/
|
*/
|
||||||
public void assignRoleToUser(String adminUser, String adminPassword, String userName, String role)
|
public void assignRoleToUser(String adminUser, String adminPassword, String userName, String role)
|
||||||
{
|
{
|
||||||
AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
|
final AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
|
||||||
String reqURL = MessageFormat.format(
|
final String reqURL = MessageFormat.format(
|
||||||
RM_ROLES_AUTHORITIES,
|
RM_ROLES_AUTHORITIES,
|
||||||
client.getApiUrl(),
|
client.getApiUrl(),
|
||||||
role,
|
role,
|
||||||
@@ -443,29 +450,51 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
public HttpResponse createHold(String user, String password, String holdName, String reason, String description)
|
public HttpResponse createHold(String user, String password, String holdName, String reason, String description)
|
||||||
{
|
{
|
||||||
// if the hold already exists don't try to create it again
|
// if the hold already exists don't try to create it again
|
||||||
String holdsContainerPath = getFilePlanPath() + "/Holds";
|
final String holdsContainerPath = Utility.buildPath(getFilePlanPath(), HOLDS_CONTAINER);
|
||||||
String fullHoldPath = holdsContainerPath + "/" + holdName;
|
final String fullHoldPath = holdsContainerPath + holdName;
|
||||||
CmisObject hold = getObjectByPath(user, password, fullHoldPath);
|
final CmisObject hold = getObjectByPath(user, password, fullHoldPath);
|
||||||
if (hold != null)
|
if (hold != null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// retrieve the Holds container nodeRef
|
// retrieve the Holds container nodeRef
|
||||||
String parentNodeRef = getItemNodeRef(user, password, "/Holds");
|
final String parentNodeRef = getItemNodeRef(user, password, "/Holds");
|
||||||
|
|
||||||
JSONObject requestParams = new JSONObject();
|
final JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef);
|
requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef);
|
||||||
requestParams.put("prop_cm_name", holdName);
|
requestParams.put("prop_cm_name", holdName);
|
||||||
requestParams.put("prop_cm_description", description);
|
requestParams.put("prop_cm_description", description);
|
||||||
requestParams.put("prop_rma_holdReason", reason);
|
requestParams.put("prop_rma_holdReason", reason);
|
||||||
|
|
||||||
// Make the POST request and throw an assertion error if it fails.
|
// Make the POST request and throw an assertion error if it fails.
|
||||||
HttpResponse httpResponse = doPostJsonRequest(user, password, SC_OK, requestParams, CREATE_HOLDS_API);
|
final HttpResponse httpResponse = doPostJsonRequest(user, password, SC_OK, requestParams, CREATE_HOLDS_API);
|
||||||
assertNotNull("Expected object to have been created at " + fullHoldPath,
|
assertNotNull("Expected object to have been created at " + fullHoldPath,
|
||||||
getObjectByPath(user, password, fullHoldPath));
|
getObjectByPath(user, password, fullHoldPath));
|
||||||
return httpResponse;
|
return httpResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds item (record/ record folder) to the hold
|
||||||
|
*
|
||||||
|
* @param user the user who adds the item to the hold
|
||||||
|
* @param password the user's password
|
||||||
|
* @param itemNodeRef the nodeRef of the item to be added to hold
|
||||||
|
* @param holdName the hold name
|
||||||
|
* @return The HTTP response
|
||||||
|
*/
|
||||||
|
public HttpResponse addItemToHold(String user, String password, String itemNodeRef, String holdName)
|
||||||
|
{
|
||||||
|
final JSONArray nodeRefs = new JSONArray().put(getNodeRefSpacesStore() + itemNodeRef);
|
||||||
|
final String holdNodeRef = getItemNodeRef(user, password, String.format("/%s/%s", HOLDS_CONTAINER, holdName));
|
||||||
|
final JSONArray holds = new JSONArray().put(getNodeRefSpacesStore() + holdNodeRef);
|
||||||
|
final JSONObject requestParams = new JSONObject();
|
||||||
|
requestParams.put("nodeRefs", nodeRefs);
|
||||||
|
requestParams.put("holds", holds);
|
||||||
|
|
||||||
|
return doPostJsonRequest(user, password, SC_OK, requestParams, RM_HOLDS_API);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates metadata, can be used on records, folders and categories
|
* Updates metadata, can be used on records, folders and categories
|
||||||
*
|
*
|
||||||
|
@@ -26,12 +26,22 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.v0.service;
|
package org.alfresco.rest.v0.service;
|
||||||
|
|
||||||
|
import static lombok.AccessLevel.PROTECTED;
|
||||||
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.alfresco.rest.core.RestAPIFactory;
|
||||||
|
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||||
|
import org.alfresco.rest.rm.community.model.user.UserPermissions;
|
||||||
import org.alfresco.rest.rm.community.model.user.UserRoles;
|
import org.alfresco.rest.rm.community.model.user.UserRoles;
|
||||||
import org.alfresco.rest.v0.RMRolesAndActionsAPI;
|
import org.alfresco.rest.v0.RMRolesAndActionsAPI;
|
||||||
|
import org.alfresco.utility.constants.UserRole;
|
||||||
import org.alfresco.utility.data.DataUser;
|
import org.alfresco.utility.data.DataUser;
|
||||||
|
import org.alfresco.utility.model.SiteModel;
|
||||||
|
import org.alfresco.utility.model.UserModel;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -45,11 +55,29 @@ import org.springframework.stereotype.Service;
|
|||||||
public class RoleService
|
public class RoleService
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@Getter (value = PROTECTED)
|
||||||
private RMRolesAndActionsAPI rmRolesAndActionsAPI;
|
private RMRolesAndActionsAPI rmRolesAndActionsAPI;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@Getter (value = PROTECTED)
|
||||||
private DataUser dataUser;
|
private DataUser dataUser;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Getter (value = PROTECTED)
|
||||||
|
private RestAPIFactory restAPIFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the capabilities for a role
|
||||||
|
*
|
||||||
|
* @param roleName the role name
|
||||||
|
* @return the list of capabilities
|
||||||
|
*/
|
||||||
|
public Set<String> getRoleCapabilities(String roleName)
|
||||||
|
{
|
||||||
|
return getRmRolesAndActionsAPI().getCapabilitiesForRole(getDataUser().getAdminUser().getUsername(),
|
||||||
|
getDataUser().getAdminUser().getPassword(), roleName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add capabilities to a role
|
* Add capabilities to a role
|
||||||
*
|
*
|
||||||
@@ -58,12 +86,10 @@ public class RoleService
|
|||||||
*/
|
*/
|
||||||
public void addCapabilitiesToRole(UserRoles role, Set<String> capabilities)
|
public void addCapabilitiesToRole(UserRoles role, Set<String> capabilities)
|
||||||
{
|
{
|
||||||
Set<String> roleCapabilities = new HashSet<>();
|
final Set<String> roleCapabilities = new HashSet<>(getRoleCapabilities(role.roleId));
|
||||||
roleCapabilities.addAll(rmRolesAndActionsAPI.getCapabilitiesForRole(dataUser.getAdminUser().getUsername(),
|
roleCapabilities.addAll(capabilities);
|
||||||
dataUser.getAdminUser().getPassword(), role.roleId));
|
|
||||||
capabilities.stream().forEach(cap -> roleCapabilities.add(cap));
|
|
||||||
|
|
||||||
rmRolesAndActionsAPI.updateRole(dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword(),
|
getRmRolesAndActionsAPI().updateRole(getDataUser().getAdminUser().getUsername(), getDataUser().getAdminUser().getPassword(),
|
||||||
role.roleId, role.displayName, roleCapabilities);
|
role.roleId, role.displayName, roleCapabilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,10 +101,75 @@ public class RoleService
|
|||||||
*/
|
*/
|
||||||
public void removeCapabilitiesFromRole(UserRoles role, Set<String> capabilities)
|
public void removeCapabilitiesFromRole(UserRoles role, Set<String> capabilities)
|
||||||
{
|
{
|
||||||
Set<String> roleCapabilities = rmRolesAndActionsAPI.getCapabilitiesForRole(dataUser.getAdminUser().getUsername(),
|
final Set<String> roleCapabilities = getRoleCapabilities(role.roleId);
|
||||||
dataUser.getAdminUser().getPassword(), role.roleId);
|
|
||||||
roleCapabilities.removeAll(capabilities);
|
roleCapabilities.removeAll(capabilities);
|
||||||
rmRolesAndActionsAPI.updateRole(dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword(),
|
getRmRolesAndActionsAPI().updateRole(getDataUser().getAdminUser().getUsername(), getDataUser().getAdminUser().getPassword(),
|
||||||
role.roleId, role.displayName, roleCapabilities);
|
role.roleId, role.displayName, roleCapabilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign permission on a record category and give the user RM role
|
||||||
|
*
|
||||||
|
* @param user the user to assign rm role and permissions
|
||||||
|
* @param categoryId the id of the category to assign permissions for
|
||||||
|
* @param userPermission the permissions to be assigned to the user
|
||||||
|
* @param userRole the rm role to be assigned to the user
|
||||||
|
*/
|
||||||
|
public void assignUserPermissionsOnCategoryAndRMRole(UserModel user, String categoryId, UserPermissions userPermission,
|
||||||
|
String userRole)
|
||||||
|
{
|
||||||
|
getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, userPermission);
|
||||||
|
getRmRolesAndActionsAPI().assignRoleToUser(getDataUser().getAdminUser().getUsername(), getDataUser().getAdminUser().getPassword(),
|
||||||
|
user.getUsername(), userRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to create a test user with rm role
|
||||||
|
*
|
||||||
|
* @param userRole the rm role
|
||||||
|
* @return the created user model
|
||||||
|
*/
|
||||||
|
public UserModel createUserWithRMRole(String userRole)
|
||||||
|
{
|
||||||
|
final UserModel rmUser = getDataUser().createRandomTestUser();
|
||||||
|
getRestAPIFactory().getRMUserAPI().assignRoleToUser(rmUser.getUsername(), userRole);
|
||||||
|
getRestAPIFactory().getRmRestWrapper().assertStatusCodeIs(OK);
|
||||||
|
return rmUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to create a test user with rm role and permissions over the record category
|
||||||
|
*
|
||||||
|
* @param userRole the rm role
|
||||||
|
* @param userPermission the permissions over the record category
|
||||||
|
* @param recordCategory the category on which user has permissions
|
||||||
|
* @return the created user model
|
||||||
|
*/
|
||||||
|
public UserModel createUserWithRMRoleAndCategoryPermission(String userRole, RecordCategory recordCategory,
|
||||||
|
UserPermissions userPermission)
|
||||||
|
{
|
||||||
|
final UserModel rmUser = createUserWithRMRole(userRole);
|
||||||
|
getRestAPIFactory().getRMUserAPI().addUserPermission(recordCategory.getId(), rmUser, userPermission);
|
||||||
|
getRestAPIFactory().getRmRestWrapper().assertStatusCodeIs(OK);
|
||||||
|
return rmUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to create a test user with rm role and permissions over the recordCategory and collaborator role
|
||||||
|
* in collaboration site
|
||||||
|
*
|
||||||
|
* @param siteModel collaboration site
|
||||||
|
* @param recordCategory the category on which permission should be given
|
||||||
|
* @param userRole the rm role
|
||||||
|
* @param userPermission the permissions over the recordCategory
|
||||||
|
* @return the created user model
|
||||||
|
*/
|
||||||
|
public UserModel createCollaboratorWithRMRoleAndPermission(SiteModel siteModel, RecordCategory recordCategory,
|
||||||
|
UserRoles userRole, UserPermissions userPermission)
|
||||||
|
{
|
||||||
|
final UserModel rmUser = createUserWithRMRoleAndCategoryPermission(userRole.roleId, recordCategory,
|
||||||
|
userPermission);
|
||||||
|
getDataUser().addUserToSite(rmUser, siteModel, UserRole.SiteCollaborator);
|
||||||
|
return rmUser;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -54,9 +54,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import org.alfresco.dataprep.ContentService;
|
import org.alfresco.dataprep.ContentService;
|
||||||
import org.alfresco.rest.RestTest;
|
import org.alfresco.rest.RestTest;
|
||||||
import org.alfresco.rest.core.RestAPIFactory;
|
import org.alfresco.rest.core.RestAPIFactory;
|
||||||
|
import org.alfresco.rest.core.RestResponse;
|
||||||
import org.alfresco.rest.model.RestNodeModel;
|
import org.alfresco.rest.model.RestNodeModel;
|
||||||
import org.alfresco.rest.rm.community.model.fileplan.FilePlan;
|
import org.alfresco.rest.rm.community.model.fileplan.FilePlan;
|
||||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType;
|
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType;
|
||||||
@@ -69,6 +71,7 @@ import org.alfresco.rest.rm.community.model.site.RMSite;
|
|||||||
import org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer;
|
import org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer;
|
||||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer;
|
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer;
|
||||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
|
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
|
||||||
|
import org.alfresco.rest.rm.community.model.user.UserPermissions;
|
||||||
import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI;
|
import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI;
|
||||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
|
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
|
||||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
|
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
|
||||||
@@ -76,6 +79,7 @@ import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
|
|||||||
import org.alfresco.rest.search.RestRequestQueryModel;
|
import org.alfresco.rest.search.RestRequestQueryModel;
|
||||||
import org.alfresco.rest.search.SearchNodeModel;
|
import org.alfresco.rest.search.SearchNodeModel;
|
||||||
import org.alfresco.rest.search.SearchRequest;
|
import org.alfresco.rest.search.SearchRequest;
|
||||||
|
import org.alfresco.rest.search.SearchSqlRequest;
|
||||||
import org.alfresco.rest.v0.RMRolesAndActionsAPI;
|
import org.alfresco.rest.v0.RMRolesAndActionsAPI;
|
||||||
import org.alfresco.rest.v0.SearchAPI;
|
import org.alfresco.rest.v0.SearchAPI;
|
||||||
import org.alfresco.utility.data.DataUser;
|
import org.alfresco.utility.data.DataUser;
|
||||||
@@ -88,8 +92,6 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all GS REST API Tests
|
* Base class for all GS REST API Tests
|
||||||
*
|
*
|
||||||
@@ -615,18 +617,50 @@ public class BaseRMRestTest extends RestTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign filling permission on a record category and give the user RM_USER role
|
* Assign permission on a record category and give the user RM role
|
||||||
*
|
*
|
||||||
* @param user the user to assign the permission to
|
* @param user the user to assign rm role and permissions
|
||||||
* @param categoryId the id of the category to assign permissions for
|
* @param categoryId the id of the category to assign permissions for
|
||||||
* @throws Exception
|
* @param userPermission the permissions to be assigned to the user
|
||||||
|
* @param userRole the rm role to be assigned to the user
|
||||||
*/
|
*/
|
||||||
public void assignFillingPermissionsOnCategory(UserModel user, String categoryId,
|
public void assignUserPermissionsOnCategoryAndRMRole(UserModel user, String categoryId, UserPermissions userPermission,
|
||||||
String userPermission, String userRole) throws Exception
|
String userRole)
|
||||||
{
|
{
|
||||||
getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, userPermission);
|
getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, userPermission);
|
||||||
rmRolesAndActionsAPI.assignRoleToUser(getAdminUser().getUsername(),
|
rmRolesAndActionsAPI.assignRoleToUser(getAdminUser().getUsername(), getAdminUser().getPassword(),
|
||||||
getAdminUser().getPassword(), user.getUsername(), userRole);
|
user.getUsername(), userRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to create a test user with rm role
|
||||||
|
*
|
||||||
|
* @param userRole the rm role
|
||||||
|
* @return the created user model
|
||||||
|
*/
|
||||||
|
protected UserModel createUserWithRMRole(String userRole)
|
||||||
|
{
|
||||||
|
UserModel rmUser = getDataUser().createRandomTestUser();
|
||||||
|
getRestAPIFactory().getRMUserAPI().assignRoleToUser(rmUser.getUsername(), userRole);
|
||||||
|
assertStatusCode(OK);
|
||||||
|
return rmUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to create a test user with rm role and permissions over the record category
|
||||||
|
*
|
||||||
|
* @param userRole the rm role
|
||||||
|
* @param userPermission the permissions over the record category
|
||||||
|
* @param recordCategory the category on which user has permissions
|
||||||
|
* @return the created user model
|
||||||
|
*/
|
||||||
|
protected UserModel createUserWithRMRoleAndCategoryPermission(String userRole, RecordCategory recordCategory,
|
||||||
|
UserPermissions userPermission)
|
||||||
|
{
|
||||||
|
UserModel rmUser = createUserWithRMRole(userRole);
|
||||||
|
getRestAPIFactory().getRMUserAPI().addUserPermission(recordCategory.getId(), rmUser, userPermission);
|
||||||
|
assertStatusCode(OK);
|
||||||
|
return rmUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -801,5 +835,4 @@ public class BaseRMRestTest extends RestTest
|
|||||||
documentLibrary.setNodeRef(nodes.get(0).onModel().getId());
|
documentLibrary.setNodeRef(nodes.get(0).onModel().getId());
|
||||||
return documentLibrary;
|
return documentLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -105,7 +105,7 @@ public class DataProviderClass
|
|||||||
* @return file plan component alias
|
* @return file plan component alias
|
||||||
*/
|
*/
|
||||||
@DataProvider
|
@DataProvider
|
||||||
public static String[][] categoryTypes()
|
public static Object[][] categoryTypes()
|
||||||
{
|
{
|
||||||
return new String[][] {
|
return new String[][] {
|
||||||
{ FOLDER_TYPE },
|
{ FOLDER_TYPE },
|
||||||
|
@@ -236,15 +236,12 @@ public class DeleteRecordTests extends BaseRMRestTest
|
|||||||
public void userWithoutDeleteRecordsCapabilityCantDeleteRecord() throws Exception
|
public void userWithoutDeleteRecordsCapabilityCantDeleteRecord() throws Exception
|
||||||
{
|
{
|
||||||
// Create test user and add it with collaboration privileges
|
// Create test user and add it with collaboration privileges
|
||||||
UserModel deleteUser = getDataUser().createRandomTestUser("delnoperm");
|
// Add RM role to user, RM Power User doesn't have the "Delete Record" capabilities
|
||||||
|
UserModel deleteUser = createUserWithRMRole(ROLE_RM_POWER_USER.roleId);
|
||||||
getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), SiteCollaborator);
|
getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), SiteCollaborator);
|
||||||
String username = deleteUser.getUsername();
|
String username = deleteUser.getUsername();
|
||||||
logger.info("Test user: " + username);
|
logger.info("Test user: " + username);
|
||||||
|
|
||||||
// Add RM role to user, RM Power User doesn't have the "Delete Record" capabilities
|
|
||||||
getRestAPIFactory().getRMUserAPI().assignRoleToUser(username, ROLE_RM_POWER_USER.roleId);
|
|
||||||
assertStatusCode(OK);
|
|
||||||
|
|
||||||
// Create random folder
|
// Create random folder
|
||||||
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
|
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
|
||||||
logger.info("Random folder:" + recordFolder.getName());
|
logger.info("Random folder:" + recordFolder.getName());
|
||||||
|
@@ -234,15 +234,12 @@ public class UpdateRecordsTests extends BaseRMRestTest
|
|||||||
public void userWithEditMetadataCapsCanUpdateMetadata() throws Exception
|
public void userWithEditMetadataCapsCanUpdateMetadata() throws Exception
|
||||||
{
|
{
|
||||||
RMUserAPI rmUserAPI = getRestAPIFactory().getRMUserAPI();
|
RMUserAPI rmUserAPI = getRestAPIFactory().getRMUserAPI();
|
||||||
// Create test user and add it with collab. privileges
|
// Create test user and add it with collab. privileges.
|
||||||
UserModel updateUser = getDataUser().createRandomTestUser("updateuser");
|
// RM Security Officer is the lowest role with Edit Record Metadata capabilities
|
||||||
|
UserModel updateUser = createUserWithRMRole(ROLE_RM_SECURITY_OFFICER.roleId);
|
||||||
updateUser.setUserRole(UserRole.SiteCollaborator);
|
updateUser.setUserRole(UserRole.SiteCollaborator);
|
||||||
getDataUser().addUserToSite(updateUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator);
|
getDataUser().addUserToSite(updateUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator);
|
||||||
|
|
||||||
// RM Security Officer is the lowest role with Edit Record Metadata capabilities
|
|
||||||
rmUserAPI.assignRoleToUser(updateUser.getUsername(), ROLE_RM_SECURITY_OFFICER.roleId);
|
|
||||||
assertStatusCode(OK);
|
|
||||||
|
|
||||||
// Create random folder
|
// Create random folder
|
||||||
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
|
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
|
||||||
logger.info("random folder:" + recordFolder.getName());
|
logger.info("random folder:" + recordFolder.getName());
|
||||||
|
@@ -66,7 +66,7 @@ public class RMSiteUtil
|
|||||||
/**
|
/**
|
||||||
* Creates an RM Site for the given compliance and default title and description
|
* Creates an RM Site for the given compliance and default title and description
|
||||||
*
|
*
|
||||||
* @param The RM site compliance
|
* @param compliance The RM site compliance
|
||||||
* @return The {@link RMSite} with the given details
|
* @return The {@link RMSite} with the given details
|
||||||
*/
|
*/
|
||||||
private static RMSite createRMSiteModel(RMSiteCompliance compliance)
|
private static RMSite createRMSiteModel(RMSiteCompliance compliance)
|
||||||
|
@@ -0,0 +1,7 @@
|
|||||||
|
log4j.rootLogger=info, console
|
||||||
|
|
||||||
|
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
|
||||||
|
|
||||||
|
log4j.logger.com.example=debug
|
Reference in New Issue
Block a user