3232import org .apache .logging .log4j .LogManager ;
3333import org .apache .logging .log4j .Logger ;
3434
35- import java .text .MessageFormat ;
3635import java .util .Collections ;
3736import java .util .List ;
3837
@@ -43,10 +42,12 @@ public class DeepboxDirectoryFeature implements Directory<VersionId> {
4342
4443 private final DeepboxSession session ;
4544 private final DeepboxIdProvider fileid ;
45+ private final DeepboxPathContainerService containerService ;
4646
4747 public DeepboxDirectoryFeature (final DeepboxSession session , final DeepboxIdProvider fileid ) {
4848 this .session = session ;
4949 this .fileid = fileid ;
50+ this .containerService = new DeepboxPathContainerService (session , fileid );
5051 }
5152
5253 @ Override
@@ -62,7 +63,7 @@ public Path mkdir(final Path folder, final TransferStatus status) throws Backgro
6263 final String deepBoxNodeId = fileid .getDeepBoxNodeId (folder .getParent ());
6364 final String boxNodeId = fileid .getBoxNodeId (folder .getParent ());
6465 final List <FolderAdded > created ;
65- if (new DeepboxPathContainerService ( session , fileid ) .isDocuments (folder .getParent ())) {
66+ if (containerService .isDocuments (folder .getParent ())) {
6667 created = new PathRestControllerApi (session .getClient ()).addFolders1 (
6768 body ,
6869 deepBoxNodeId ,
@@ -91,8 +92,26 @@ public Path mkdir(final Path folder, final TransferStatus status) throws Backgro
9192
9293 @ Override
9394 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 );
95+ if (workdir .isRoot ()) {
96+ throw new AccessDeniedException (LocaleFactory .localizedString ("Adding files is not permitted in this area" , "Deepbox" )).withFile (workdir );
97+ }
98+ if (containerService .isCompany (workdir )) {
99+ throw new AccessDeniedException (LocaleFactory .localizedString ("Adding files is not permitted at the organisation level" , "Deepbox" )).withFile (workdir );
100+ }
101+ if (containerService .isDeepbox (workdir )) {
102+ throw new AccessDeniedException (LocaleFactory .localizedString ("Adding files is not permitted in this area" , "Deepbox" )).withFile (workdir );
103+ }
104+ if (containerService .isTrash (workdir )) {
105+ throw new AccessDeniedException (LocaleFactory .localizedString ("Adding files is not permitted in this area" , "Deepbox" )).withFile (workdir );
106+ }
107+ if (containerService .isSharedWithMe (workdir )) {
108+ throw new AccessDeniedException (LocaleFactory .localizedString ("Adding files is not permitted in this area" , "Deepbox" )).withFile (workdir );
109+ }
110+ if (containerService .isBox (workdir )) {
111+ throw new AccessDeniedException (LocaleFactory .localizedString ("Adding files is not permitted in the boxes area" , "Deepbox" )).withFile (workdir );
112+ }
113+ if (containerService .isInbox (workdir )) {
114+ throw new AccessDeniedException (LocaleFactory .localizedString ("Adding folders is not permitted in the inbox" , "Deepbox" )).withFile (workdir );
96115 }
97116 final Acl acl = workdir .attributes ().getAcl ();
98117 if (Acl .EMPTY == acl ) {
@@ -102,7 +121,7 @@ public void preflight(final Path workdir, final String filename) throws Backgrou
102121 }
103122 if (!acl .get (new Acl .CanonicalUser ()).contains (CANADDCHILDREN )) {
104123 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 );
124+ throw new AccessDeniedException (LocaleFactory .localizedString ("Adding files is not permitted in this area " , "Deepbox" )).withFile (workdir );
106125 }
107126 }
108127}
0 commit comments