transform UserPermissions in enum; add helper methods to create users with rm role, permissions or clearance

This commit is contained in:
cagache
2019-04-23 08:23:43 +03:00
parent 0710c81b53
commit a54a80f6a6
7 changed files with 50 additions and 37 deletions

View File

@@ -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;
}
} }

View File

@@ -57,9 +57,8 @@ public class FilesAPI extends RMModelRequest
* @param fileId The Id of a file to declare as record * @param fileId The Id of a file to declare as record
* @param parameters Request parameters, refer to API documentation for more details * @param parameters Request parameters, refer to API documentation for more details
* @return The {@link Record} for created record * @return The {@link Record} for created record
* @throws Exception for malformed JSON responses
*/ */
public Record declareAsRecord(String fileId, String parameters) throws Exception public Record declareAsRecord(String fileId, String parameters)
{ {
mandatoryString("fileId", fileId); mandatoryString("fileId", fileId);
@@ -76,9 +75,8 @@ public class FilesAPI extends RMModelRequest
* *
* @param fileId The Id of a file to declare as record * @param fileId The Id of a file to declare as record
* @return The {@link Record} for created record * @return The {@link Record} for created record
* @throws Exception for malformed JSON responses
*/ */
public Record declareAsRecord(String fileId) throws Exception public Record declareAsRecord(String fileId)
{ {
mandatoryString("fileId", fileId); mandatoryString("fileId", fileId);

View File

@@ -86,9 +86,8 @@ 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 +116,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();
@@ -132,7 +131,7 @@ public class RMUserAPI extends RMModelRequest
.addArray("permissions") .addArray("permissions")
.addObject() .addObject()
.add("authority", user.getUsername()) .add("authority", user.getUsername())
.add("role", permission) .add("role", permission.permissionId)
.end() .end()
.getJson(); .getJson();

View File

@@ -54,6 +54,7 @@ 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;
@@ -69,6 +70,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;
@@ -88,8 +90,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 +615,34 @@ public class BaseRMRestTest extends RestTest
} }
/** /**
* Assign filling permission on a record category and give the user RM_USER role * Helper method to create a test user with rm role
* *
* @param user the user to assign the permission to * @param userRole the rm role
* @param categoryId the id of the category to assign permissions for * @return the created user model
* @throws Exception
*/ */
public void assignFillingPermissionsOnCategory(UserModel user, String categoryId, protected UserModel createUserWithRMRole(String userRole)
String userPermission, String userRole) throws Exception
{ {
getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, userPermission); UserModel rmUser = getDataUser().createRandomTestUser();
rmRolesAndActionsAPI.assignRoleToUser(getAdminUser().getUsername(), getRestAPIFactory().getRMUserAPI().assignRoleToUser(rmUser.getUsername(), userRole);
getAdminUser().getPassword(), user.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;
} }
/** /**
@@ -793,5 +809,4 @@ public class BaseRMRestTest extends RestTest
documentLibrary.setNodeRef(nodes.get(0).onModel().getId()); documentLibrary.setNodeRef(nodes.get(0).onModel().getId());
return documentLibrary; return documentLibrary;
} }
} }

View File

@@ -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());

View File

@@ -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());

View File

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