Skip to content

Commit 13a73f7

Browse files
committed
Add specific error messages depending on working directory.
1 parent 031d8c2 commit 13a73f7

File tree

7 files changed

+62
-15
lines changed

7 files changed

+62
-15
lines changed

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.apache.logging.log4j.LogManager;
3333
import org.apache.logging.log4j.Logger;
3434

35-
import java.text.MessageFormat;
3635
import java.util.Collections;
3736
import 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
}

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)