Skip to content

Commit

Permalink
Fix cancel clearing and start investigating session cookie issue (#347)
Browse files Browse the repository at this point in the history
* Fix cancel clearing and start investigating session cookie issue
* Remove cancelled files from session key
* Remove console logs
* Remove fake test

---------

Co-authored-by: Chibuisi Enyia <[email protected]>
Co-authored-by: Alex Gonzalez <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2023
1 parent 9440a74 commit ef9780d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/main/java/formflow/library/FileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ public ResponseEntity<?> upload(
log.info("POST upload (url: {}): flow: {}, inputName: {}", request.getRequestURI().toLowerCase(), flow, inputName);
try {
if (!doesFlowExist(flow)) {
throwNotFoundError(flow, null, String.format("Could not find flow with name %s in your application's flow configuration.", flow));
throwNotFoundError(flow, null,
String.format("Could not find flow with name %s in your application's flow configuration.", flow));
}

Submission submission = submissionRepositoryService.findOrCreate(httpSession);
UUID userFileId = UUID.randomUUID();
if (submission.getId() == null) {
Expand Down Expand Up @@ -162,8 +163,9 @@ public ResponseEntity<?> upload(
} else {
dzFilesMap = (HashMap<String, HashMap<UUID, HashMap<String, String>>>) httpSession.getAttribute(SESSION_USERFILES_KEY);
if (dzFilesMap.containsKey(inputName)) {
// a map for this dropzone widget already exists, let's add more files to it
userFileMap = dzFilesMap.get(inputName);
// Double check that files in session cookie are in db
userFileMap.entrySet().removeIf(e -> userFileRepositoryService.findById(e.getKey()).isEmpty());
} else {
// a map for this inputName dropzone instance does not exist yet, let's create it so we can add files to it
userFileMap = new HashMap<>();
Expand Down Expand Up @@ -203,7 +205,8 @@ RedirectView delete(
HttpServletRequest request
) {
try {
log.info("POST delete (url: {}): fileId: {} inputName: {}", request.getRequestURI().toLowerCase(), fileId, dropZoneInstanceName);
log.info("POST delete (url: {}): fileId: {} inputName: {}", request.getRequestURI().toLowerCase(), fileId,
dropZoneInstanceName);
UUID submissionId = (UUID) httpSession.getAttribute("id");
Optional<Submission> maybeSubmission = submissionRepositoryService.findById(submissionId);

Expand Down Expand Up @@ -260,7 +263,8 @@ public ResponseEntity<StreamingResponseBody> downloadSingleFile(
@PathVariable String fileId,
HttpServletRequest request
) {
log.info("GET downloadSingleFile (url: {}): submissionId: {} fileId {}", request.getRequestURI().toLowerCase(), submissionId, fileId);
log.info("GET downloadSingleFile (url: {}): submissionId: {} fileId {}", request.getRequestURI().toLowerCase(), submissionId,
fileId);
if (!submissionId.equals(httpSession.getAttribute("id").toString())) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ QUnit.module('Dropzone', function () {
});
QUnit.testDone(function () {
document.querySelector("#uploadTest").className += " display-none";
});
});
5 changes: 4 additions & 1 deletion src/main/resources/templates/fragments/fileUploader.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,11 @@
if (fTD.name === file.name) {
removeFileFromDropzone(file, id);
sendDeleteXhrRequest(id);
window['cancelledFiles' + [[${inputName}]]] =
window['cancelledFiles' + [[${inputName}]]]
.filter(cancelledFile => cancelledFile.name !== file.name);
}
})
});
}

function sendDeleteXhrRequest(id) {
Expand Down

0 comments on commit ef9780d

Please sign in to comment.