@@ -371,6 +371,119 @@ describe("Folder Level Permissions - Security Checks", () => {
371371 } ) ;
372372 } ) ;
373373
374+ it ( "should not allow moving a folder to an inaccessible folder, based on permission level (owner vs editor vs viewer)" , async ( ) => {
375+ const folderA = await acoIdentityA
376+ . createFolder ( {
377+ data : {
378+ title : "Folder A" ,
379+ slug : "folder-a" ,
380+ type : FOLDER_TYPE
381+ }
382+ } )
383+ . then ( ( [ response ] ) => {
384+ return response . data . aco . createFolder . data ;
385+ } ) ;
386+
387+ const folderB = await acoIdentityA
388+ . createFolder ( {
389+ data : {
390+ title : "Folder B" ,
391+ slug : "folder-b" ,
392+ type : FOLDER_TYPE
393+ }
394+ } )
395+ . then ( ( [ response ] ) => {
396+ return response . data . aco . createFolder . data ;
397+ } ) ;
398+
399+ const folderC = await acoIdentityA
400+ . createFolder ( {
401+ data : {
402+ title : "Folder C" ,
403+ slug : "folder-c" ,
404+ type : FOLDER_TYPE
405+ }
406+ } )
407+ . then ( ( [ response ] ) => {
408+ return response . data . aco . createFolder . data ;
409+ } ) ;
410+
411+ const subFolder = await acoIdentityA
412+ . createFolder ( {
413+ data : {
414+ title : "Sub Folder" ,
415+ slug : "subfolder" ,
416+ type : FOLDER_TYPE ,
417+ parentId : folderA . id
418+ }
419+ } )
420+ . then ( ( [ response ] ) => {
421+ return response . data . aco . createFolder . data ;
422+ } ) ;
423+
424+ await acoIdentityA . updateFolder ( {
425+ id : folderA . id ,
426+ data : {
427+ permissions : [ { level : "owner" , target : `admin:${ identityB . id } ` } ]
428+ }
429+ } ) ;
430+
431+ await acoIdentityA . updateFolder ( {
432+ id : folderB . id ,
433+ data : {
434+ permissions : [ { level : "editor" , target : `admin:${ identityB . id } ` } ]
435+ }
436+ } ) ;
437+
438+ await acoIdentityA . updateFolder ( {
439+ id : folderC . id ,
440+ data : {
441+ permissions : [ { level : "viewer" , target : `admin:${ identityB . id } ` } ]
442+ }
443+ } ) ;
444+
445+ // Should be allowed to move a subfolder from folder A to folder B, because user B has "owner" access to folder A and "editor" access to folder B.
446+ await expect (
447+ acoIdentityB
448+ . updateFolder ( {
449+ id : subFolder . id ,
450+ data : { parentId : folderB . id }
451+ } )
452+ . then ( ( [ response ] ) => {
453+ return response . data . aco . updateFolder . data ;
454+ } )
455+ ) . resolves . toMatchObject ( { id : subFolder . id , parentId : folderB . id } ) ;
456+
457+ // Should be allowed to move a subfolder from folder B to folder A, because user B has "owner" access to folder A and "editor" access to folder B.
458+ await expect (
459+ acoIdentityB
460+ . updateFolder ( {
461+ id : subFolder . id ,
462+ data : { parentId : folderA . id }
463+ } )
464+ . then ( ( [ response ] ) => {
465+ return response . data . aco . updateFolder . data ;
466+ } )
467+ ) . resolves . toMatchObject ( { id : subFolder . id , parentId : folderA . id } ) ;
468+
469+ // Should not be allowed to move a subfolder from folder A to folder C, because user A has "owner" access to folder A and "viewer" access to folder C.
470+ await expect (
471+ acoIdentityB
472+ . updateFolder ( {
473+ id : folderB . id ,
474+ data : { parentId : folderC . id }
475+ } )
476+ . then ( ( [ response ] ) => {
477+ return response . data . aco . updateFolder . error ;
478+ } )
479+ ) . resolves . toEqual ( {
480+ code : "CANNOT_MOVE_FOLDER_TO_NEW_PARENT" ,
481+ data : null ,
482+ message :
483+ "Cannot move folder to a new parent because you don't have access to the new parent."
484+ } ) ;
485+ } ) ;
486+
374487 it ( "should still be be able to access a folder if its parent is inaccessible" , async ( ) => {
375488 const folderA = await acoIdentityA
376489 . createFolder ( {
0 commit comments