@@ -134,6 +134,7 @@ class ExploreTest {
134
134
private static final UUID SCRIPT_ID_BASE_FORM_CONTINGENCY_LIST_UUID = UUID .randomUUID ();
135
135
private static final UUID ELEMENT_UUID = UUID .randomUUID ();
136
136
private static final UUID FORBIDDEN_ELEMENT_UUID = UUID .randomUUID ();
137
+ private static final UUID DIRECTORY_NOT_OWNED_SUBELEMENT_UUID = UUID .randomUUID ();
137
138
138
139
@ Autowired
139
140
private MockMvc mockMvc ;
@@ -433,29 +434,31 @@ public MockResponse dispatch(RecordedRequest request) {
433
434
}
434
435
return new MockResponse (404 );
435
436
} else if ("HEAD" .equals (request .getMethod ())) {
436
- if (path .matches ("/v1/elements\\ ?accessType=.*&ids=" + PARENT_DIRECTORY_UUID + "&targetDirectoryUuid" )) {
437
+ if (path .matches ("/v1/elements\\ ?accessType=.*&ids=" + PARENT_DIRECTORY_UUID + "&targetDirectoryUuid&recursiveCheck=.* " )) {
437
438
return new MockResponse (200 );
438
- } else if (path .matches ("/v1/elements\\ ?accessType=.*&ids=" + NO_CONTENT_DIRECTORY_UUID + "&targetDirectoryUuid" )) {
439
- return new MockResponse (204 );
440
- } else if (path .matches ("/v1/elements\\ ?accessType=.*&ids=" + FORBIDDEN_STUDY_UUID + "&targetDirectoryUuid" )) {
439
+ } else if (path .matches ("/v1/elements\\ ?accessType=.*&ids=" + NO_CONTENT_DIRECTORY_UUID + "&targetDirectoryUuid&recursiveCheck=.*" )) {
441
440
return new MockResponse (403 );
442
- } else if (path .matches ("/v1/elements\\ ?accessType=.*&ids=" + PARENT_DIRECTORY_UUID_FORBIDDEN + "&targetDirectoryUuid" )) {
441
+ } else if (path .matches ("/v1/elements\\ ?accessType=.*&ids=" + FORBIDDEN_STUDY_UUID + "&targetDirectoryUuid&recursiveCheck=.*" )) {
442
+ return new MockResponse (403 );
443
+ } else if (path .matches ("/v1/elements\\ ?accessType=.*&ids=" + PARENT_DIRECTORY_UUID_FORBIDDEN + "&targetDirectoryUuid&recursiveCheck=.*" )) {
443
444
return new MockResponse (403 );
444
445
} else if (path .matches ("/v1/elements\\ ?forUpdate=true&ids=" + FORBIDDEN_ELEMENT_UUID ) && USER_NOT_ALLOWED .equals (request .getHeaders ().get ("userId" ))) {
445
446
return new MockResponse (403 );
447
+ } else if (path .matches ("/v1/elements\\ ?accessType=WRITE&ids=" + DIRECTORY_NOT_OWNED_SUBELEMENT_UUID + "&targetDirectoryUuid.*&recursiveCheck=true" )) {
448
+ return new MockResponse (409 );
446
449
} else if (path .matches ("/v1/elements\\ ?forDeletion=true&ids=.*" ) || path .matches ("/v1/elements\\ ?forUpdate=true&ids=.*" )) {
447
450
return new MockResponse (200 );
448
451
} else if (path .matches ("/v1/directories/" + PARENT_DIRECTORY_UUID2 + "/elements/elementName/types/type" )) {
449
452
return new MockResponse (200 );
450
- } else if (path .matches ("/v1/elements\\ ?accessType=READ&ids=" + TEST_ACCESS_DIRECTORY_UUID_ALLOWED + "&targetDirectoryUuid" )) {
453
+ } else if (path .matches ("/v1/elements\\ ?accessType=READ&ids=" + TEST_ACCESS_DIRECTORY_UUID_ALLOWED + "&targetDirectoryUuid&recursiveCheck=.* " )) {
451
454
return new MockResponse (200 );
452
- } else if (path .matches ("/v1/elements\\ ?accessType=READ&ids=" + TEST_ACCESS_DIRECTORY_UUID_FORBIDDEN + "&targetDirectoryUuid" )) {
453
- return new MockResponse (204 );
454
- } else if (path .matches ("/v1/elements\\ ?accessType=WRITE&ids=" + TEST_ACCESS_DIRECTORY_UUID_ALLOWED + "&targetDirectoryUuid" )) {
455
+ } else if (path .matches ("/v1/elements\\ ?accessType=READ&ids=" + TEST_ACCESS_DIRECTORY_UUID_FORBIDDEN + "&targetDirectoryUuid&recursiveCheck=.* " )) {
456
+ return new MockResponse (403 );
457
+ } else if (path .matches ("/v1/elements\\ ?accessType=WRITE&ids=" + TEST_ACCESS_DIRECTORY_UUID_ALLOWED + "&targetDirectoryUuid&recursiveCheck=.* " )) {
455
458
return new MockResponse (200 );
456
- } else if (path .matches ("/v1/elements\\ ?accessType=WRITE&ids=" + TEST_ACCESS_DIRECTORY_UUID_FORBIDDEN + "&targetDirectoryUuid" )) {
457
- return new MockResponse (204 );
458
- } else if (path .matches ("/v1/elements\\ ?accessType=.*&ids=.*&targetDirectoryUuid.*" )) {
459
+ } else if (path .matches ("/v1/elements\\ ?accessType=WRITE&ids=" + TEST_ACCESS_DIRECTORY_UUID_FORBIDDEN + "&targetDirectoryUuid&recursiveCheck=.* " )) {
460
+ return new MockResponse (403 );
461
+ } else if (path .matches ("/v1/elements\\ ?accessType=.*&ids=.*&targetDirectoryUuid.*&recursiveCheck=.* " )) {
459
462
return new MockResponse (200 );
460
463
}
461
464
}
@@ -660,6 +663,7 @@ void testDeleteElement() throws Exception {
660
663
deleteElement (MODIFICATION_UUID );
661
664
deleteElementsNotAllowed (List .of (FORBIDDEN_STUDY_UUID ), PARENT_DIRECTORY_UUID_FORBIDDEN , 403 );
662
665
deleteElementNotAllowed (FORBIDDEN_STUDY_UUID , 403 );
666
+ deleteElementNotAllowed (DIRECTORY_NOT_OWNED_SUBELEMENT_UUID , 409 );
663
667
}
664
668
665
669
@ Test
@@ -1242,6 +1246,18 @@ void testUpdateElementNotOk() throws Exception {
1242
1246
).andExpect (status ().isForbidden ());
1243
1247
}
1244
1248
1249
+ @ Test
1250
+ void testMoveDirectoryContainingNotOwnedSubelements () throws Exception {
1251
+ ElementAttributes elementAttributes = new ElementAttributes ();
1252
+ elementAttributes .setElementName (STUDY1 );
1253
+ mockMvc .perform (put ("/v1/explore/elements?targetDirectoryUuid={parentDirectoryUuid}" ,
1254
+ PARENT_DIRECTORY_UUID )
1255
+ .header ("userId" , USER1 )
1256
+ .contentType (MediaType .APPLICATION_JSON )
1257
+ .content (mapper .writeValueAsString (List .of (DIRECTORY_NOT_OWNED_SUBELEMENT_UUID )))
1258
+ ).andExpect (status ().isConflict ());
1259
+ }
1260
+
1245
1261
@ Test
1246
1262
void testGetRootDirectories (final MockWebServer server ) throws Exception {
1247
1263
MvcResult result = mockMvc .perform (get ("/v1/explore/directories/root-directories" )
@@ -1358,15 +1374,15 @@ void testHasRights(final MockWebServer server) throws Exception {
1358
1374
// test read access forbidden
1359
1375
mockMvc .perform (head ("/v1/explore/directories/" + TEST_ACCESS_DIRECTORY_UUID_FORBIDDEN + "?permission=READ" )
1360
1376
.header ("userId" , NOT_ADMIN_USER )
1361
- ).andExpect (status ().isNoContent ());
1377
+ ).andExpect (status ().isForbidden ());
1362
1378
1363
1379
requests = TestUtils .getRequestsWithBodyDone (1 , server );
1364
1380
assertTrue (requests .stream ().anyMatch (r -> r .getPath ().contains ("v1/elements?accessType=READ&ids=" + TEST_ACCESS_DIRECTORY_UUID_FORBIDDEN + "&targetDirectoryUuid" )));
1365
1381
1366
1382
// test write access forbidden
1367
1383
mockMvc .perform (head ("/v1/explore/directories/" + TEST_ACCESS_DIRECTORY_UUID_FORBIDDEN + "?permission=WRITE" )
1368
1384
.header ("userId" , NOT_ADMIN_USER )
1369
- ).andExpect (status ().isNoContent ());
1385
+ ).andExpect (status ().isForbidden ());
1370
1386
1371
1387
requests = TestUtils .getRequestsWithBodyDone (1 , server );
1372
1388
assertTrue (requests .stream ().anyMatch (r -> r .getPath ().contains ("v1/elements?accessType=WRITE&ids=" + TEST_ACCESS_DIRECTORY_UUID_FORBIDDEN + "&targetDirectoryUuid" )));
0 commit comments