1515 * GNU General Public License for more details.
1616 */
1717
18- import ch .cyberduck .core .Acl ;
1918import ch .cyberduck .core .LocaleFactory ;
2019import ch .cyberduck .core .Path ;
2120import ch .cyberduck .core .VersionId ;
3231import org .apache .logging .log4j .LogManager ;
3332import org .apache .logging .log4j .Logger ;
3433
35- import java .text .MessageFormat ;
3634import java .util .Collections ;
3735import java .util .List ;
3836
39- import static ch .cyberduck .core .deepbox .DeepboxAttributesFinderFeature .CANADDCHILDREN ;
40-
4137public class DeepboxDirectoryFeature implements Directory <VersionId > {
4238 private static final Logger log = LogManager .getLogger (DeepboxDirectoryFeature .class );
4339
4440 private final DeepboxSession session ;
4541 private final DeepboxIdProvider fileid ;
42+ private final DeepboxPathContainerService containerService ;
4643
4744 public DeepboxDirectoryFeature (final DeepboxSession session , final DeepboxIdProvider fileid ) {
4845 this .session = session ;
4946 this .fileid = fileid ;
47+ this .containerService = new DeepboxPathContainerService (session , fileid );
5048 }
5149
5250 @ Override
@@ -62,7 +60,7 @@ public Path mkdir(final Path folder, final TransferStatus status) throws Backgro
6260 final String deepBoxNodeId = fileid .getDeepBoxNodeId (folder .getParent ());
6361 final String boxNodeId = fileid .getBoxNodeId (folder .getParent ());
6462 final List <FolderAdded > created ;
65- if (new DeepboxPathContainerService ( session , fileid ) .isDocuments (folder .getParent ())) {
63+ if (containerService .isDocuments (folder .getParent ())) {
6664 created = new PathRestControllerApi (session .getClient ()).addFolders1 (
6765 body ,
6866 deepBoxNodeId ,
@@ -91,18 +89,10 @@ public Path mkdir(final Path folder, final TransferStatus status) throws Backgro
9189
9290 @ Override
9391 public void preflight (final Path workdir , final String filename ) throws BackgroundException {
94- if (workdir .isRoot () || (new DeepboxPathContainerService (session , fileid ).isContainer (workdir ) && !new DeepboxPathContainerService (session , fileid ).isDocuments (workdir ))) {
95- throw new AccessDeniedException (MessageFormat .format (LocaleFactory .localizedString ("Cannot create folder {0}" , "Error" ), filename )).withFile (workdir );
96- }
97- final Acl acl = workdir .attributes ().getAcl ();
98- if (Acl .EMPTY == acl ) {
99- // Missing initialization
100- log .warn ("Unknown ACLs on {}" , workdir );
101- return ;
102- }
103- if (!acl .get (new Acl .CanonicalUser ()).contains (CANADDCHILDREN )) {
104- log .warn ("ACL {} for {} does not include {}" , acl , workdir , CANADDCHILDREN );
105- throw new AccessDeniedException (MessageFormat .format (LocaleFactory .localizedString ("Cannot create folder {0}" , "Error" ), filename )).withFile (workdir );
92+ if (containerService .isInbox (workdir )) {
93+ throw new AccessDeniedException (LocaleFactory .localizedString ("Adding folders is not permitted in the inbox" , "Deepbox" )).withFile (workdir );
10694 }
95+ // Same checks as for new file
96+ new DeepboxTouchFeature (session , fileid ).preflight (workdir , filename );
10797 }
10898}
0 commit comments