Skip to content

Commit 7698393

Browse files
committed
Forbid providing both "moveTo" and "copyTo" in single-item POST
- fix minor errorMSG bug in handleMove - update helptext in POST method to be stylistically consistent with remaining help texts
1 parent cf43d17 commit 7698393

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

workspace-server/src/main/java/gov/nasa/jpl/aerie/workspace/server/WorkspaceBindings.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,24 +441,29 @@ private void post(Context context) {
441441
final String helpText = """
442442
Expected JSON body with one of the following formats:
443443
444-
To move a file:
444+
To move an item:
445445
{
446-
"moveTo": "<destination-path>",
447-
"toWorkspace": <new-workspace-id>, (optional)
446+
"toWorkspace": 2, // optional. if provided, the item will be moved to the specified workspace.
447+
// defaults to the current workspace.
448+
"moveTo": "path/to/destination", // required. path within the destination workspace to move the item to, ending with the item.
449+
// to rename an item, end the 'moveTo' path with a name that differs from the item's current name.
448450
}
449451
450-
To copy a file:
452+
To copy an item:
451453
{
452-
"copyTo": "<destination-path>",
453-
"toWorkspace": <new-workspace-id>, (optional)
454-
}
455-
""";
454+
"toWorkspace": 2, // optional. if provided, the item will be copied to the specified workspace.
455+
// defaults to the current workspace.
456+
"copyTo": "path/to/destination/folder", // required. path within the destination workspace to copy the item to, ending with the item.
457+
}""";
456458

457459
try (JsonReader bodyReader = Json.createReader(new StringReader(context.body()))) {
458460
JsonObject bodyJson = bodyReader.readObject();
459461
final boolean success;
460462

461-
if (bodyJson.containsKey("moveTo")) {
463+
if(bodyJson.containsKey("moveTo") && bodyJson.containsKey("copyTo")){
464+
context.status(400).json(new FormattedError("Invalid request. Too many actions specified.\n\n" + helpText));
465+
return;
466+
} else if (bodyJson.containsKey("moveTo")) {
462467
success = handleMove(context, bodyJson);
463468
} else if (bodyJson.containsKey("copyTo")) {
464469
success = handleCopy(context, bodyJson);
@@ -556,7 +561,7 @@ && checkPermissions(context, targetWorkspace, WorkspaceAction.write_file_directo
556561
}
557562

558563
final var errorMsg = "Unable to move '%s' in Workspace %d to '%s' in Workspace %d."
559-
.formatted(pathInfo, sourceWorkspace, destination, targetWorkspace);
564+
.formatted(pathInfo.filePath(), sourceWorkspace, destination, targetWorkspace);
560565
try {
561566
if (workspaceService.isDirectory(sourceWorkspace, pathInfo.filePath())) {
562567
if (workspaceService.moveDirectory(sourceWorkspace, pathInfo.filePath, targetWorkspace, destination)) {

0 commit comments

Comments
 (0)