diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/user/UserPermissions.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/user/UserPermissions.java
index 1b9dfe5aba..7c237bd47c 100644
--- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/user/UserPermissions.java
+++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/user/UserPermissions.java
@@ -32,9 +32,16 @@ package org.alfresco.rest.rm.community.model.user;
* @author Kristijan Conkas
* @since 2.6
*/
-public class UserPermissions
+public enum UserPermissions
{
- public static final String PERMISSION_FILING = "Filing";
- public static final String PERMISSION_READ_RECORDS = "ReadRecords";
- public static final String PERMISSION_FILE_RECORDS = "FileRecords";
+ PERMISSION_FILING("Filing"),
+ PERMISSION_READ_RECORDS("ReadRecords"),
+ PERMISSION_FILE_RECORDS("FileRecords");
+
+ public final String permissionId;
+
+ UserPermissions(String permissionId)
+ {
+ this.permissionId = permissionId;
+ }
}
diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/GSCoreAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/GSCoreAPI.java
index 23f6655166..febd2b5427 100644
--- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/GSCoreAPI.java
+++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/GSCoreAPI.java
@@ -113,7 +113,7 @@ public class GSCoreAPI extends RMModelRequest
/**
* Provides DSL on all REST calls under records/...
API path
*
- * @return {@link FilePlanComponentAPI}
+ * @return {@link RecordsAPI}
*/
public RecordsAPI usingRecords()
{
diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java
index d24c53c614..6cd2b7d0d4 100644
--- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java
+++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java
@@ -84,11 +84,11 @@ public class RMUserAPI extends RMModelRequest
/**
* Assign RM role to user
+ *
* @param userName User's username
* @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();
@@ -97,31 +97,31 @@ public class RMUserAPI extends RMModelRequest
// override v1 baseURI and basePath
RequestSpecification spec = new RequestSpecBuilder()
- .setBaseUri(client.getApiUrl())
- .setBasePath("/")
- .build();
+ .setBaseUri(client.getApiUrl())
+ .setBasePath("/")
+ .build();
Response response = given()
- .spec(spec)
- .log().all()
- .pathParam("role", userRole)
- .pathParam("authority", userName)
- .param("alf_ticket", client.getAlfTicket(adminUser.getUsername(),
- adminUser.getPassword()))
- .when()
- .post("/rm/roles/{role}/authorities/{authority}")
- .prettyPeek()
- .andReturn();
+ .spec(spec)
+ .log().all()
+ .pathParam("role", userRole)
+ .pathParam("authority", userName)
+ .param("alf_ticket", client.getAlfTicket(adminUser.getUsername(),
+ adminUser.getPassword()))
+ .when()
+ .post("/rm/roles/{role}/authorities/{authority}")
+ .prettyPeek()
+ .andReturn();
getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
}
/**
* 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 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();
@@ -129,34 +129,76 @@ public class RMUserAPI extends RMModelRequest
AlfrescoHttpClient client = getAlfrescoHttpClient();
JsonObject bodyJson = buildObject()
- .addArray("permissions")
+ .addArray("permissions")
.addObject()
- .add("authority", user.getUsername())
- .add("role", permission)
- .end()
- .getJson();
+ .add("authority", (user != null ? user.getUsername() : null))
+ .add("role", permission.permissionId)
+ .end()
+ .getJson();
// override v1 baseURI and basePath
RequestSpecification spec = new RequestSpecBuilder()
- .setBaseUri(client.getApiUrl())
- .setBasePath("/")
- .build();
+ .setBaseUri(client.getApiUrl())
+ .setBasePath("/")
+ .build();
// execute an "old-style" API call
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();
+ .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()));
}
+ /**
+ * 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
*
@@ -168,7 +210,7 @@ public class RMUserAPI extends RMModelRequest
public boolean createUser(String userName, String userPassword, String userEmail)
{
UserModel adminUser = getRmRestWrapper().getTestUser();
- AlfrescoHttpClient client = getAlfrescoHttpClient();
+ final AlfrescoHttpClient client = getAlfrescoHttpClient();
JsonObject body = buildObject()
.add("userName", userName)
@@ -178,7 +220,7 @@ public class RMUserAPI extends RMModelRequest
.add("email", userEmail)
.getJson();
- RequestSpecification spec = new RequestSpecBuilder()
+ final RequestSpecification spec = new RequestSpecBuilder()
.setBaseUri(client.getApiUrl())
.setBasePath("/")
.setAuth(basic(adminUser.getUsername(), adminUser.getPassword()))
diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java
index 2cc343a50a..d57c16fabf 100644
--- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java
+++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java
@@ -47,6 +47,7 @@ import org.alfresco.dataprep.AlfrescoHttpClientFactory;
import org.alfresco.dataprep.UserService;
import org.alfresco.rest.core.v0.BaseAPI;
import org.alfresco.rest.core.v0.RMEvents;
+import org.alfresco.utility.Utility;
import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.http.HttpResponse;
@@ -72,6 +73,8 @@ import org.springframework.stereotype.Component;
@Component
public class RMRolesAndActionsAPI extends BaseAPI
{
+ public static final String HOLDS_CONTAINER = "Holds";
+
/** The URI to view the configured roles and capabilities. */
private static final String RM_ROLES = "{0}rma/admin/rmroles";
/** 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 String MOVE_ACTIONS_API = "action/rm-move-to/site/rm/documentLibrary/{0}";
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 */
@Autowired
@@ -101,7 +106,8 @@ public class RMRolesAndActionsAPI extends BaseAPI
public Set getConfiguredRoles(String adminUser, String adminPassword)
{
// 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();
}
@@ -115,7 +121,8 @@ public class RMRolesAndActionsAPI extends BaseAPI
*/
public Set 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));
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 capabilities)
{
- JSONObject requestBody = new JSONObject();
+ final JSONObject requestBody = new JSONObject();
requestBody.put("name", roleName);
requestBody.put("displayLabel", roleDisplayLabel);
- JSONArray capabilitiesArray = new JSONArray();
+ final JSONArray capabilitiesArray = new JSONArray();
capabilities.forEach(capabilitiesArray::put);
requestBody.put("capabilities", capabilitiesArray);
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 capabilities)
{
- JSONObject requestBody = new JSONObject();
+ final JSONObject requestBody = new JSONObject();
requestBody.put("name", roleName);
requestBody.put("displayLabel", roleDisplayLabel);
- JSONArray capabilitiesArray = new JSONArray();
+ final JSONArray capabilitiesArray = new JSONArray();
capabilities.forEach(capabilitiesArray::put);
requestBody.put("capabilities", capabilitiesArray);
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)
{
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);
}
@@ -201,8 +208,8 @@ public class RMRolesAndActionsAPI extends BaseAPI
*/
public void assignRoleToUser(String adminUser, String adminPassword, String userName, String role)
{
- AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
- String reqURL = MessageFormat.format(
+ final AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
+ final String reqURL = MessageFormat.format(
RM_ROLES_AUTHORITIES,
client.getApiUrl(),
role,
@@ -443,29 +450,51 @@ public class RMRolesAndActionsAPI extends BaseAPI
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
- String holdsContainerPath = getFilePlanPath() + "/Holds";
- String fullHoldPath = holdsContainerPath + "/" + holdName;
- CmisObject hold = getObjectByPath(user, password, fullHoldPath);
+ final String holdsContainerPath = Utility.buildPath(getFilePlanPath(), HOLDS_CONTAINER);
+ final String fullHoldPath = holdsContainerPath + holdName;
+ final CmisObject hold = getObjectByPath(user, password, fullHoldPath);
if (hold != null)
{
return null;
}
// 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("prop_cm_name", holdName);
requestParams.put("prop_cm_description", description);
requestParams.put("prop_rma_holdReason", reason);
// 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,
getObjectByPath(user, password, fullHoldPath));
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
*
diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java
index ccf2785cd8..c37dcc8541 100644
--- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java
+++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java
@@ -26,12 +26,22 @@
*/
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.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.v0.RMRolesAndActionsAPI;
+import org.alfresco.utility.constants.UserRole;
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.stereotype.Service;
@@ -45,11 +55,29 @@ import org.springframework.stereotype.Service;
public class RoleService
{
@Autowired
+ @Getter (value = PROTECTED)
private RMRolesAndActionsAPI rmRolesAndActionsAPI;
@Autowired
+ @Getter (value = PROTECTED)
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 getRoleCapabilities(String roleName)
+ {
+ return getRmRolesAndActionsAPI().getCapabilitiesForRole(getDataUser().getAdminUser().getUsername(),
+ getDataUser().getAdminUser().getPassword(), roleName);
+ }
+
/**
* Add capabilities to a role
*
@@ -58,12 +86,10 @@ public class RoleService
*/
public void addCapabilitiesToRole(UserRoles role, Set capabilities)
{
- Set roleCapabilities = new HashSet<>();
- roleCapabilities.addAll(rmRolesAndActionsAPI.getCapabilitiesForRole(dataUser.getAdminUser().getUsername(),
- dataUser.getAdminUser().getPassword(), role.roleId));
- capabilities.stream().forEach(cap -> roleCapabilities.add(cap));
+ final Set roleCapabilities = new HashSet<>(getRoleCapabilities(role.roleId));
+ roleCapabilities.addAll(capabilities);
- rmRolesAndActionsAPI.updateRole(dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword(),
+ getRmRolesAndActionsAPI().updateRole(getDataUser().getAdminUser().getUsername(), getDataUser().getAdminUser().getPassword(),
role.roleId, role.displayName, roleCapabilities);
}
@@ -75,10 +101,75 @@ public class RoleService
*/
public void removeCapabilitiesFromRole(UserRoles role, Set capabilities)
{
- Set roleCapabilities = rmRolesAndActionsAPI.getCapabilitiesForRole(dataUser.getAdminUser().getUsername(),
- dataUser.getAdminUser().getPassword(), role.roleId);
+ final Set roleCapabilities = getRoleCapabilities(role.roleId);
roleCapabilities.removeAll(capabilities);
- rmRolesAndActionsAPI.updateRole(dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword(),
+ getRmRolesAndActionsAPI().updateRole(getDataUser().getAdminUser().getUsername(), getDataUser().getAdminUser().getPassword(),
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;
+ }
}
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java
index 2cdf80ea5b..86fc641882 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java
@@ -54,9 +54,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
+import lombok.Getter;
import org.alfresco.dataprep.ContentService;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.core.RestAPIFactory;
+import org.alfresco.rest.core.RestResponse;
import org.alfresco.rest.model.RestNodeModel;
import org.alfresco.rest.rm.community.model.fileplan.FilePlan;
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.unfiledcontainer.UnfiledContainer;
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.RecordCategoryAPI;
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.SearchNodeModel;
import org.alfresco.rest.search.SearchRequest;
+import org.alfresco.rest.search.SearchSqlRequest;
import org.alfresco.rest.v0.RMRolesAndActionsAPI;
import org.alfresco.rest.v0.SearchAPI;
import org.alfresco.utility.data.DataUser;
@@ -88,8 +92,6 @@ import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
-import lombok.Getter;
-
/**
* 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
- * @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,
- String userPermission, String userRole) throws Exception
+ public void assignUserPermissionsOnCategoryAndRMRole(UserModel user, String categoryId, UserPermissions userPermission,
+ String userRole)
{
getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, userPermission);
- rmRolesAndActionsAPI.assignRoleToUser(getAdminUser().getUsername(),
- getAdminUser().getPassword(), user.getUsername(), userRole);
+ rmRolesAndActionsAPI.assignRoleToUser(getAdminUser().getUsername(), 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
+ */
+ 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());
return documentLibrary;
}
-
}
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/DataProviderClass.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/DataProviderClass.java
index b4b39f70b8..d437da677a 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/DataProviderClass.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/DataProviderClass.java
@@ -105,7 +105,7 @@ public class DataProviderClass
* @return file plan component alias
*/
@DataProvider
- public static String[][] categoryTypes()
+ public static Object[][] categoryTypes()
{
return new String[][] {
{ FOLDER_TYPE },
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java
index ef63360a39..387e263460 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java
@@ -236,15 +236,12 @@ public class DeleteRecordTests extends BaseRMRestTest
public void userWithoutDeleteRecordsCapabilityCantDeleteRecord() throws Exception
{
// 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);
String username = deleteUser.getUsername();
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
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
logger.info("Random folder:" + recordFolder.getName());
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java
index 2f8f3af510..c433c99dc6 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java
@@ -234,15 +234,12 @@ public class UpdateRecordsTests extends BaseRMRestTest
public void userWithEditMetadataCapsCanUpdateMetadata() throws Exception
{
RMUserAPI rmUserAPI = getRestAPIFactory().getRMUserAPI();
- // Create test user and add it with collab. privileges
- UserModel updateUser = getDataUser().createRandomTestUser("updateuser");
+ // Create test user and add it with collab. privileges.
+ // RM Security Officer is the lowest role with Edit Record Metadata capabilities
+ UserModel updateUser = createUserWithRMRole(ROLE_RM_SECURITY_OFFICER.roleId);
updateUser.setUserRole(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
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
logger.info("random folder:" + recordFolder.getName());
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java
index b3574a0fcb..80062165ca 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java
@@ -66,7 +66,7 @@ public class RMSiteUtil
/**
* 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
*/
private static RMSite createRMSiteModel(RMSiteCompliance compliance)
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/resources/log4j.properties b/rm-automation/rm-automation-community-rest-api/src/test/resources/log4j.properties
new file mode 100644
index 0000000000..93c931c03c
--- /dev/null
+++ b/rm-automation/rm-automation-community-rest-api/src/test/resources/log4j.properties
@@ -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
\ No newline at end of file