diff --git a/src/main/java/ca/corefacility/bioinformatics/irida/model/enums/ProjectRole.java b/src/main/java/ca/corefacility/bioinformatics/irida/model/enums/ProjectRole.java index 45d82b29d76..e68305baa7c 100644 --- a/src/main/java/ca/corefacility/bioinformatics/irida/model/enums/ProjectRole.java +++ b/src/main/java/ca/corefacility/bioinformatics/irida/model/enums/ProjectRole.java @@ -6,7 +6,9 @@ public enum ProjectRole { PROJECT_USER("PROJECT_USER", 1), - PROJECT_OWNER("PROJECT_OWNER", 2); + PROJECT_L2("PROJECT_L2", 2), + PROJECT_L3("PROJECT_L3", 3), + PROJECT_OWNER("PROJECT_OWNER", 4); private String code; private int level; @@ -31,6 +33,10 @@ public static ProjectRole fromString(String code) { switch (code.toUpperCase()) { case "PROJECT_USER": return PROJECT_USER; + case "PROJECT_L2": + return PROJECT_L2; + case "PROJECT_L3": + return PROJECT_L3; case "PROJECT_OWNER": return PROJECT_OWNER; default: diff --git a/src/main/java/ca/corefacility/bioinformatics/irida/ria/web/services/UIProjectsService.java b/src/main/java/ca/corefacility/bioinformatics/irida/ria/web/services/UIProjectsService.java index 501d1e23608..47a6dc2a97d 100644 --- a/src/main/java/ca/corefacility/bioinformatics/irida/ria/web/services/UIProjectsService.java +++ b/src/main/java/ca/corefacility/bioinformatics/irida/ria/web/services/UIProjectsService.java @@ -1,9 +1,6 @@ package ca.corefacility.bioinformatics.irida.ria.web.services; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import javax.validation.ConstraintViolationException; @@ -17,6 +14,7 @@ import ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException; import ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException; +import ca.corefacility.bioinformatics.irida.model.enums.ProjectRole; import ca.corefacility.bioinformatics.irida.model.project.Project; import ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate; import ca.corefacility.bioinformatics.irida.model.user.User; @@ -97,8 +95,10 @@ public Long createProject(CreateProjectRequest request) throws EntityExistsExcep * @return list of roles and their internationalized strings */ public List getProjectRoles(Locale locale) { - return PROJECT_ROLES.stream() - .map(role -> new Role(role, messageSource.getMessage("projectRole." + role, new Object[] {}, locale))) + + return Arrays.stream(ProjectRole.values()) + .map(role -> new Role(role.toString(), + messageSource.getMessage("projectRole." + role.toString(), new Object[] {}, locale))) .collect(Collectors.toList()); } diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index 0b61b3595f1..b434b138671 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -181,6 +181,8 @@ project.samples=Samples # Project role projectRole.PROJECT_USER=Collaborator +projectRole.PROJECT_L2=Level 2 +projectRole.PROJECT_L3=Level 3 projectRole.PROJECT_OWNER=Manager projectRole.PROJECT_NONE=None diff --git a/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/pages/projects/ProjectMetadataPage.java b/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/pages/projects/ProjectMetadataPage.java index 027a8c91bbe..b8df94a5767 100644 --- a/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/pages/projects/ProjectMetadataPage.java +++ b/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/pages/projects/ProjectMetadataPage.java @@ -1,6 +1,8 @@ package ca.corefacility.bioinformatics.irida.ria.integration.pages.projects; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.openqa.selenium.By; import org.openqa.selenium.Keys; @@ -11,6 +13,7 @@ import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; +import ca.corefacility.bioinformatics.irida.model.enums.ProjectRole; import ca.corefacility.bioinformatics.irida.ria.integration.pages.AbstractPage; public class ProjectMetadataPage extends AbstractPage { @@ -204,12 +207,20 @@ public String getFieldRestrictionForRow(int row) { return fieldRestrictionSelects.get(row).findElement(By.className("ant-select-selection-item")).getText(); } - public void updateFieldRestrictionToOwner(int row) { + public void updateFieldRestrictionToRole(int row, ProjectRole role) { + Map roleToRow = new HashMap<>(); + roleToRow.put(ProjectRole.PROJECT_USER, 0); + roleToRow.put(ProjectRole.PROJECT_L2, 1); + roleToRow.put(ProjectRole.PROJECT_L3, 2); + roleToRow.put(ProjectRole.PROJECT_OWNER, 3); + + Integer roleRow = roleToRow.get(role); + WebDriverWait wait = new WebDriverWait(driver, 2); fieldRestrictionSelects.get(row).click(); WebElement dropdown = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("ant-select-dropdown"))); List options = dropdown.findElements(By.className("ant-select-item-option")); - options.get(1).click(); + options.get(roleRow).click(); wait.until(ExpectedConditions.invisibilityOf(dropdown)); } diff --git a/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/projects/ProjectMetadataIT.java b/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/projects/ProjectMetadataIT.java index 62db5eff76a..72ac695b1eb 100644 --- a/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/projects/ProjectMetadataIT.java +++ b/src/test/java/ca/corefacility/bioinformatics/irida/ria/integration/projects/ProjectMetadataIT.java @@ -3,6 +3,7 @@ import org.junit.Assert; import org.junit.Test; +import ca.corefacility.bioinformatics.irida.model.enums.ProjectRole; import ca.corefacility.bioinformatics.irida.ria.integration.AbstractIridaUIITChromeDriver; import ca.corefacility.bioinformatics.irida.ria.integration.pages.LoginPage; import ca.corefacility.bioinformatics.irida.ria.integration.pages.projects.ProjectMetadataPage; @@ -24,7 +25,7 @@ public void testAdminProjectMetadata() { // TEST FIELD RESTRICTIONS Assert.assertTrue("Fields restrictions settings should be visible to managers", page.areFieldRestrictionSettingsVisible()); Assert.assertEquals("Should currently be set to collaborator by default", "Collaborator", page.getFieldRestrictionForRow(0)); - page.updateFieldRestrictionToOwner(0); + page.updateFieldRestrictionToRole(0, ProjectRole.PROJECT_OWNER); Assert.assertEquals("Field should now be restricted to managers", "Manager", page.getFieldRestrictionForRow(0)); // TEMPLATES