Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More project roles #61

Draft
wants to merge 3 commits into
base: metadata-field-security
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -97,8 +95,10 @@ public Long createProject(CreateProjectRequest request) throws EntityExistsExcep
* @return list of roles and their internationalized strings
*/
public List<Role> 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());
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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<ProjectRole, Integer> 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<WebElement> options = dropdown.findElements(By.className("ant-select-item-option"));
options.get(1).click();
options.get(roleRow).click();
wait.until(ExpectedConditions.invisibilityOf(dropdown));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down