change the UserRoles.java to a enum

add the within RoleService a utility method to add/remove list of capabilities from a ROLE
This commit is contained in:
Rodica Sutu
2018-03-27 21:14:21 +03:00
parent 18ca70469f
commit 11ca553d50
8 changed files with 163 additions and 20 deletions

View File

@@ -26,8 +26,17 @@
*/
package org.alfresco.rest.rm.community.base;
import static com.google.common.collect.Sets.newHashSet;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_ADMIN;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_MANAGER;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_POWER_USER;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_SECURITY_OFFICER;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_USER;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import java.util.Set;
/**
* Test data used in tests
*
@@ -83,4 +92,9 @@ public interface TestData
public static String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
public static final String ALFRESCO_ADMINISTRATORS = "ALFRESCO_ADMINISTRATORS";
/**
* The ids of the default RM roles.
*/
public static final Set<String> RM_ROLES = newHashSet(ROLE_RM_ADMIN.roleId, ROLE_RM_MANAGER.roleId,
ROLE_RM_POWER_USER.roleId, ROLE_RM_SECURITY_OFFICER.roleId, ROLE_RM_USER.roleId);
}

View File

@@ -488,7 +488,7 @@ public class FilePlanTests extends BaseRMRestTest
children.add(recordCategory);
}
getRestAPIFactory().getRMUserAPI().assignRoleToUser(managerUser.getUsername(), ROLE_RM_MANAGER);
getRestAPIFactory().getRMUserAPI().assignRoleToUser(managerUser.getUsername(), ROLE_RM_MANAGER.roleId);
// Get record category children from API
getRestAPIFactory().getFilePlansAPI(managerUser).getRootRecordCategories(FILE_PLAN_ALIAS)
.assertThat().entriesListIsEmpty().assertThat().paginationExist();

View File

@@ -187,7 +187,7 @@ public class DeleteRecordTests extends BaseRMRestTest
getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), SiteCollaborator);
// Add RM role to user
getRestAPIFactory().getRMUserAPI().assignRoleToUser(username, ROLE_RM_POWER_USER);
getRestAPIFactory().getRMUserAPI().assignRoleToUser(username, ROLE_RM_POWER_USER.roleId);
assertStatusCode(OK);
// Try to delete newRecord
@@ -218,7 +218,7 @@ public class DeleteRecordTests extends BaseRMRestTest
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);
getRestAPIFactory().getRMUserAPI().assignRoleToUser(username, ROLE_RM_POWER_USER.roleId);
assertStatusCode(OK);
// Create random folder

View File

@@ -32,6 +32,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_SECURITY_OFFICER;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicRecordModel;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicUnfiledContainerChildModel;
@@ -58,7 +59,6 @@ import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChi
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildCollection;
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildProperties;
import org.alfresco.rest.rm.community.model.user.UserPermissions;
import org.alfresco.rest.rm.community.model.user.UserRoles;
import org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RMUserAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
@@ -240,7 +240,7 @@ public class UpdateRecordsTests extends BaseRMRestTest
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(), UserRoles.ROLE_RM_SECURITY_OFFICER);
rmUserAPI.assignRoleToUser(updateUser.getUsername(), ROLE_RM_SECURITY_OFFICER.roleId);
assertStatusCode(OK);
// Create random folder

View File

@@ -31,7 +31,7 @@ import static java.util.Collections.singleton;
import static com.google.common.collect.Sets.newHashSet;
import static org.alfresco.rest.rm.community.model.user.UserRoles.RM_ROLES;
import static org.alfresco.rest.rm.community.base.TestData.RM_ROLES;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_USER;
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
import static org.junit.Assert.assertEquals;
@@ -76,7 +76,8 @@ public class RMRolesTests extends BaseRMRestTest
public void checkCapabilitiesForUser()
{
Set<String> capabilities = rmRolesAndActionsAPI
.getCapabilitiesForRole(getAdminUser().getUsername(), getAdminUser().getPassword(), ROLE_RM_USER);
.getCapabilitiesForRole(getAdminUser().getUsername(), getAdminUser().getPassword(), ROLE_RM_USER
.roleId);
assertEquals("Unexpected capabilities found for RM User.", capabilities, CAPABILITIES);
}