Skip to content

Commit f50a292

Browse files
authored
Merge pull request #16986 from iterate-ch/feature/DEEP-25
Add specific error messages depending on working directory.
2 parents ae848ed + 6e37f91 commit f50a292

File tree

7 files changed

+45
-27
lines changed

7 files changed

+45
-27
lines changed

deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeature.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* GNU General Public License for more details.
1616
*/
1717

18-
import ch.cyberduck.core.Acl;
1918
import ch.cyberduck.core.LocaleFactory;
2019
import ch.cyberduck.core.Path;
2120
import ch.cyberduck.core.VersionId;
@@ -32,21 +31,20 @@
3231
import org.apache.logging.log4j.LogManager;
3332
import org.apache.logging.log4j.Logger;
3433

35-
import java.text.MessageFormat;
3634
import java.util.Collections;
3735
import java.util.List;
3836

39-
import static ch.cyberduck.core.deepbox.DeepboxAttributesFinderFeature.CANADDCHILDREN;
40-
4137
public 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
}

deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxTouchFeature.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,37 @@
2626
import org.apache.logging.log4j.LogManager;
2727
import org.apache.logging.log4j.Logger;
2828

29-
import java.text.MessageFormat;
30-
3129
import static ch.cyberduck.core.deepbox.DeepboxAttributesFinderFeature.CANADDCHILDREN;
3230

3331
public class DeepboxTouchFeature extends DefaultTouchFeature<Node> {
3432
private static final Logger log = LogManager.getLogger(DeepboxTouchFeature.class);
3533

36-
private final DeepboxSession session;
37-
private final DeepboxIdProvider fileid;
34+
private final DeepboxPathContainerService containerService;
3835

3936
public DeepboxTouchFeature(final DeepboxSession session, final DeepboxIdProvider fileid) {
4037
super(new DeepboxWriteFeature(session, fileid));
41-
this.session = session;
42-
this.fileid = fileid;
38+
this.containerService = new DeepboxPathContainerService(session, fileid);
4339
}
4440

4541
@Override
4642
public void preflight(final Path workdir, final String filename) throws BackgroundException {
47-
if(workdir.isRoot() || new DeepboxPathContainerService(session, fileid).isCompany(workdir) ||
48-
new DeepboxPathContainerService(session, fileid).isDeepbox(workdir) || new DeepboxPathContainerService(session, fileid).isBox(workdir)) {
49-
throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)).withFile(workdir);
43+
if(workdir.isRoot()) {
44+
throw new AccessDeniedException(LocaleFactory.localizedString("Adding files is not permitted in this area", "Deepbox")).withFile(workdir);
45+
}
46+
if(containerService.isCompany(workdir)) {
47+
throw new AccessDeniedException(LocaleFactory.localizedString("Adding files is not permitted at the organisation level", "Deepbox")).withFile(workdir);
48+
}
49+
if(containerService.isDeepbox(workdir)) {
50+
throw new AccessDeniedException(LocaleFactory.localizedString("Adding files is not permitted in this area", "Deepbox")).withFile(workdir);
51+
}
52+
if(containerService.isTrash(workdir)) {
53+
throw new AccessDeniedException(LocaleFactory.localizedString("Adding files is not permitted in this area", "Deepbox")).withFile(workdir);
54+
}
55+
if(containerService.isSharedWithMe(workdir)) {
56+
throw new AccessDeniedException(LocaleFactory.localizedString("Adding files is not permitted in this area", "Deepbox")).withFile(workdir);
57+
}
58+
if(containerService.isBox(workdir)) {
59+
throw new AccessDeniedException(LocaleFactory.localizedString("Adding files is not permitted in the boxes area", "Deepbox")).withFile(workdir);
5060
}
5161
final Acl acl = workdir.attributes().getAcl();
5262
if(Acl.EMPTY == acl) {
@@ -56,7 +66,7 @@ public void preflight(final Path workdir, final String filename) throws Backgrou
5666
}
5767
if(!acl.get(new Acl.CanonicalUser()).contains(CANADDCHILDREN)) {
5868
log.warn("ACL {} for {} does not include {}", acl, workdir, CANADDCHILDREN);
59-
throw new AccessDeniedException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename)).withFile(workdir);
69+
throw new AccessDeniedException(LocaleFactory.localizedString("Adding files is not permitted in this area", "Deepbox")).withFile(workdir);
6070
}
6171
}
6272
}

deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxTouchFeatureTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,22 @@ public void testNoAddChildrenFile() throws Exception {
186186
assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random()));
187187
assertThrows(AccessDeniedException.class, () -> new DeepboxDirectoryFeature(session, nodeid).preflight(folder.withAttributes(attributes), new AlphanumericRandomStringService().random()));
188188
}
189+
190+
@Test
191+
public void testTrash() {
192+
final DeepboxIdProvider nodeid = new DeepboxIdProvider(session);
193+
final Path parent = new Path("/ORG 4 - DeepBox Desktop App/ORG 4 - DeepBox Desktop App/ORG3:Box1/Trash", EnumSet.of(Path.Type.directory));
194+
final Path folder = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
195+
assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(parent, folder.getName()));
196+
assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).touch(folder, new TransferStatus()));
197+
}
198+
199+
@Test
200+
public void testSharedWithMe() {
201+
final DeepboxIdProvider nodeid = new DeepboxIdProvider(session);
202+
final Path parent = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory));
203+
final Path file = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
204+
assertThrows(AccessDeniedException.class, () -> new DeepboxTouchFeature(session, nodeid).preflight(parent, file.getName()));
205+
assertThrows(NotfoundException.class, () -> new DeepboxTouchFeature(session, nodeid).touch(file, new TransferStatus()));
206+
}
189207
}
1.1 KB
Binary file not shown.
962 Bytes
Binary file not shown.
1.04 KB
Binary file not shown.
1.02 KB
Binary file not shown.

0 commit comments

Comments
 (0)