diff --git a/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/CreateSampleTest.java b/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/CreateSampleTest.java index 8739ce079dc08b5f78fa4c43bed97c17aa3f0e44..ca2c7b5302dc19ff0a52eed187a3ac68db8d69aa 100644 --- a/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/CreateSampleTest.java +++ b/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/CreateSampleTest.java @@ -2114,6 +2114,38 @@ public class CreateSampleTest extends AbstractSampleTest }); } + @Test(dataProvider = USER_ROLES_PROVIDER) + public void testCreateWithDifferentRolesParentChildSample(RoleWithHierarchy role) + { + testWithUserRole(role, params -> + { + final SampleCreation parentCreation = new SampleCreation(); + parentCreation.setCreationId(new CreationId(UUID.randomUUID().toString())); + parentCreation.setCode("TEST_PARENT_SAMPLE_" + UUID.randomUUID()); + parentCreation.setTypeId(new EntityTypePermId("CELL_PLATE")); + parentCreation.setSpaceId(params.space1Id); + + final SampleCreation childCreation = new SampleCreation(); + childCreation.setCreationId(new CreationId(UUID.randomUUID().toString())); + childCreation.setCode("TEST_CHILD_" + UUID.randomUUID()); + childCreation.setTypeId(new EntityTypePermId("CELL_PLATE")); + childCreation.setSpaceId(params.space1Id); + + parentCreation.setChildIds(List.of(childCreation.getCreationId())); + childCreation.setParentIds(List.of(parentCreation.getCreationId())); + + if (List.of(RoleWithHierarchy.RoleLevel.INSTANCE, RoleWithHierarchy.RoleLevel.SPACE).contains(role.getRoleLevel()) && List.of( + RoleWithHierarchy.RoleCode.ADMIN, RoleWithHierarchy.RoleCode.POWER_USER, RoleWithHierarchy.RoleCode.USER) + .contains(role.getRoleCode())) + { + v3api.createSamples(params.userSessionToken, List.of(parentCreation, childCreation)); + } else + { + assertAnyAuthorizationException(() -> v3api.createSamples(params.userSessionToken, Collections.singletonList(parentCreation))); + } + }); + } + @Test public void testLogging() { diff --git a/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/UpdateSampleTest.java b/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/UpdateSampleTest.java index a85a7eb8edc89a5b5721bee837d3204bac9be0b6..f5b1797792af476bae52a9ff4c024cbb0bb2cee1 100644 --- a/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/UpdateSampleTest.java +++ b/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/UpdateSampleTest.java @@ -2725,4 +2725,48 @@ public class UpdateSampleTest extends AbstractSampleTest }); } + @Test(dataProvider = USER_ROLES_PROVIDER) + public void testUpdateWithDifferentRolesParentChildSample(RoleWithHierarchy role) + { + testWithUserRole(role, params -> + { + final SampleCreation parentCreation = new SampleCreation(); + parentCreation.setCreationId(new CreationId(UUID.randomUUID().toString())); + parentCreation.setCode("TEST_PARENT_SAMPLE_" + UUID.randomUUID()); + parentCreation.setTypeId(new EntityTypePermId("CELL_PLATE")); + parentCreation.setSpaceId(params.space1Id); + + final SampleCreation childCreation = new SampleCreation(); + childCreation.setCreationId(new CreationId(UUID.randomUUID().toString())); + childCreation.setCode("TEST_CHILD_" + UUID.randomUUID()); + childCreation.setTypeId(new EntityTypePermId("CELL_PLATE")); + childCreation.setSpaceId(params.space1Id); + + parentCreation.setChildIds(List.of(childCreation.getCreationId())); + childCreation.setParentIds(List.of(parentCreation.getCreationId())); + + List<SamplePermId> sampleIds = v3api.createSamples(params.adminSessionToken, List.of(parentCreation, childCreation)); + SamplePermId parentId = sampleIds.get(0); + SamplePermId childId = sampleIds.get(1); + + SampleUpdate parentUpdate = new SampleUpdate(); + parentUpdate.setSampleId(parentId); + parentUpdate.getChildIds().remove(childId); + + SampleUpdate childUpdate = new SampleUpdate(); + childUpdate.setSampleId(childId); + childUpdate.getParentIds().remove(parentId); + + if (List.of(RoleWithHierarchy.RoleLevel.INSTANCE, RoleWithHierarchy.RoleLevel.SPACE).contains(role.getRoleLevel()) && List.of( + RoleWithHierarchy.RoleCode.ADMIN, RoleWithHierarchy.RoleCode.POWER_USER) + .contains(role.getRoleCode())) + { + v3api.updateSamples(params.userSessionToken, List.of(parentUpdate, childUpdate)); + } else + { + assertAnyAuthorizationException(() -> v3api.updateSamples(params.userSessionToken, List.of(parentUpdate, childUpdate))); + } + }); + } + }