Skip to content

Commit

Permalink
Needs correction file management
Browse files Browse the repository at this point in the history
Odd behavior can occur with continued use between `Replace Manuscript` and Additional Documents interface. This is attempts to reduce those.
  • Loading branch information
wwelling committed Aug 28, 2024
1 parent 4cb3b5d commit f29da14
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 28 deletions.
45 changes: 25 additions & 20 deletions src/main/java/org/tdl/vireo/controller/SubmissionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public ApiResponse addComment(@WeaverUser User user, @PathVariable Long submissi
String subject = (String) data.get("subject");
String templatedMessage = templateUtility.compileString((String) data.get("message"), submission);
actionLogRepo.createPublicLog(submission, user, subject + ": " + templatedMessage);
}
}
} else {
String subject = (String) data.get("subject");
String templatedMessage = templateUtility.compileString((String) data.get("message"), submission);
Expand Down Expand Up @@ -1023,29 +1023,34 @@ public ApiResponse removeFile(@WeaverUser User user, @PathVariable Long submissi
Submission submission = submissionRepo.read(submissionId);
ApiResponse apiResponse = new ApiResponse(SUCCESS);
int hash = user.getEmail().hashCode();
FieldValue fileFieldValue = fieldValueRepo.findById(fieldValueId).get();
String documentType = fileFieldValue.getFieldPredicate().getValue();
String uri = fileFieldValue.getValue();
if (user.getRole().equals(Role.ROLE_STUDENT) && documentType.equals("_doctype_license")) {
apiResponse = new ApiResponse(ERROR, "You are not allowed to delete license files!");
} else {
if (user.getRole().equals(Role.ROLE_ADMIN) || user.getRole().equals(Role.ROLE_MANAGER) || uri.contains(String.valueOf(hash))) {
String fileName = "";
String fileSize = "file not found";
if (assetService.assetFileExists(uri)) {
JsonNode fileInfo = assetService.getAssetFileInfo(uri, submission);
fileName = fileInfo.get("name").asText();
fileSize = fileInfo.get("readableSize").asText();
Optional<FieldValue> fileFieldValue = fieldValueRepo.findById(fieldValueId);
if (fileFieldValue.isPresent()) {
String documentType = fileFieldValue.get().getFieldPredicate().getValue();
String uri = fileFieldValue.get().getValue();
if (user.getRole().equals(Role.ROLE_STUDENT) && documentType.equals("_doctype_license")) {
apiResponse = new ApiResponse(ERROR, "You are not allowed to delete license files!");
} else {
if (user.getRole().equals(Role.ROLE_ADMIN) || user.getRole().equals(Role.ROLE_MANAGER) || uri.contains(String.valueOf(hash))) {
String fileName = "";
String fileSize = "file not found";
if (assetService.assetFileExists(uri)) {
JsonNode fileInfo = assetService.getAssetFileInfo(uri, submission);
fileName = fileInfo.get("name").asText();
fileSize = fileInfo.get("readableSize").asText();
} else {
fileName = assetService.getAssetFileName(uri);
}

assetService.delete(uri);
actionLogRepo.createPublicLog(submission, user, documentType.substring(9).toUpperCase() + " file " + fileName + " (" + fileSize + ") removed");
} else {
fileName = assetService.getAssetFileName(uri);
apiResponse = new ApiResponse(ERROR, "This is not your file to delete!");
}

assetService.delete(uri);
actionLogRepo.createPublicLog(submission, user, documentType.substring(9).toUpperCase() + " file " + fileName + " (" + fileSize + ") removed");
} else {
apiResponse = new ApiResponse(ERROR, "This is not your file to delete!");
}
} else {
apiResponse = new ApiResponse(ERROR, "There is no field value with id " + fieldValueId);
}

return apiResponse;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,

var deleteFile = function (fieldValue) {
fieldValue.removing = true;
FileUploadService.removeFile($scope.submission, fieldValue).then(function (removed) {
delete fieldValue.removing;
var deleteFilePromise = FileUploadService.removeFile($scope.submission, fieldValue);

deleteFilePromise.then(function (removed) {
if (removed) {
delete fieldValue.removing;
}
});

return deleteFilePromise;
};

StudentSubmissionRepo.fetchSubmissionById($routeParams.submissionId).then(function (submission) {
Expand Down Expand Up @@ -84,8 +90,17 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,
var fieldValue = $scope.removeQueue[i];
removePromises.push(deleteFile(fieldValue));
}
$q.all(removePromises).then(function () {
$q.all(removePromises).then(function (removeFiles) {
$scope.removingUploads = false;
if (removeFiles.every(Boolean)) {
StudentSubmissionRepo.fetchSubmissionById($routeParams.submissionId).then(function (submission) {
angular.extend($scope.submission, submission);
$scope.submission.enableListeners();
$scope.submission.fetchDocumentTypeFileInfo();
});
} else {
console.error('Failed to remove additional files. Please refresh the page.');
}
});
};

Expand All @@ -97,9 +112,17 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,

$scope.archiveManuscript = function () {
$scope.archivingManuscript = true;
FileUploadService.archiveFile($scope.submission, $scope.submission.primaryDocumentFieldValue, true).then(function () {
FileUploadService.archiveFile($scope.submission, $scope.submission.primaryDocumentFieldValue, true).then(function (removeFieldValue) {
$scope.archivingManuscript = false;
$scope.submission.addFieldValue($scope.submission.getPrimaryDocumentFieldProfile().fieldPredicate);
if (removeFieldValue) {
StudentSubmissionRepo.fetchSubmissionById($routeParams.submissionId).then(function (submission) {
$scope.submission = submission;
$scope.submission.enableListeners();
$scope.submission.fetchDocumentTypeFileInfo();
});
} else {
console.error('Failed to remove field value. Please refresh the page.');
}
});
};

Expand Down Expand Up @@ -170,9 +193,10 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,

CustomActionDefinitionRepo.listen(function(apiRes) {
if(apiRes.meta.status === 'SUCCESS') {
StudentSubmissionRepo.remove($scope.submission);
StudentSubmissionRepo.fetchSubmissionById($routeParams.submissionId).then(function (submission) {
angular.extend($scope.submission, submission);
$scope.submission.enableListeners();
$scope.submission.fetchDocumentTypeFileInfo();
});
}
});
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/org/tdl/vireo/model/EmailRecipientContactTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public void testGetEmails() {

emails.add("first@example.com");
emails.add("second@example.com");

// expected, actual
assertEquals(2, emails.size(), "Expected emails are not as expected.");

otherFieldValue.setId(1L);
otherFieldValue.setValue("value1");
fieldValue.setId(2L);
Expand All @@ -40,14 +44,16 @@ public void testGetEmails() {
fieldValues.add(fieldValue);
fieldValues.add(otherFieldValue);
fieldPredicate.setId(1L);
fieldPredicate.setValue("notnull");

ReflectionTestUtils.setField(emailRecipientContact, "fieldPredicate", fieldPredicate);

when(submission.getFieldValuesByPredicate(any(FieldPredicate.class))).thenReturn(fieldValues);
when(submission.getFieldValuesByPredicateValue(any(String.class))).thenReturn(fieldValues);

List<String> got = emailRecipientContact.getEmails(submission);

assertEquals(got.size(), emails.size(), "Emails array does not have the correct length.");
// expected, actual
assertEquals(emails.size(), got.size(), "Emails array does not have the correct length.");

emails.forEach(email -> {
String found = null;
Expand Down

0 comments on commit f29da14

Please sign in to comment.