Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cancel clearing and start investigating session cookie issue #347

Merged
merged 5 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
cy-by marked this conversation as resolved.
Show resolved Hide resolved
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,
cy-by marked this conversation as resolved.
Show resolved Hide resolved
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
Loading