Skip to content

Commit

Permalink
#3559 Use file size limits from System Config
Browse files Browse the repository at this point in the history
  • Loading branch information
sekmiller committed Feb 28, 2017
1 parent 2abc58a commit 591c0c2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ public Response uploadDatasetLogo(@PathParam("id") String idSupplied, @FormDataP
} catch (IOException ex) {
return error(Response.Status.BAD_REQUEST, "Problem uploading file: " + ex);
}
if(file.length() > systemConfig.getThumbnailSizeLimitImage()){
return error(Response.Status.BAD_REQUEST, "File is larger than maximum size: " + systemConfig.getThumbnailSizeLimitImage() + ".");
}
Dataset datasetThatMayHaveChanged = datasetService.writeDatasetLogoToStagingArea(dataset, file);
datasetThatMayHaveChanged = datasetService.moveDatasetLogoFromStagingToFinal(dataset);
return ok("Thumbnail is now " + datasetThatMayHaveChanged.getDatasetThumbnail(datasetVersionService, fileService).getFilename());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public int getMultipleUploadFilesLimit() {
// create sensible defaults for these things? -- 4.2.2
public long getThumbnailSizeLimitImage() {
long limit = getThumbnailSizeLimit("Image");
return limit == 0 ? 5000000 : limit;
return limit == 0 ? 500000 : limit;
}

public long getThumbnailSizeLimitPDF() {
Expand All @@ -423,10 +423,8 @@ public long getThumbnailSizeLimit(String type) {
String option = null;
if ("Image".equals(type)) {
option = settingsService.getValueForKey(SettingsServiceBean.Key.ThumbnailSizeLimitImage);
option = System.getProperty("dataverse.dataAccess.thumbnail.image.limit");
} else if ("PDF".equals(type)) {
option = settingsService.getValueForKey(SettingsServiceBean.Key.ThumbnailSizeLimitPDF);
option = System.getProperty("dataverse.dataAccess.thumbnail.pdf.limit");
}
Long limit = null;

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/dataset-widgets.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</label>
<!--FIXME: consider supporting SVG: https://github.com/IQSS/dataverse/issues/2843-->
<p:fileUpload invalidFileMessage="#{bundle['dataset.thumbnailsAndWidget.thumbnailImage.upload.invalidMsg']}" id="changelogo" allowTypes="/(\.|\/)(jpg|jpeg|tff|png|gif)$/" update="@all"
sizeLimit="500000"
sizeLimit="#{systemConfig.thumbnailSizeLimitImage}"
oncomplete="bind_bsui_components();" dragDropSupport="true" auto="true" multiple="false"
fileUploadListener="#{DatasetWidgetsPage.handleImageFileUpload}" label="#{bundle['dataset.thumbnailsAndWidget.thumbnailImage.upload']}"/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/themeAndWidgetsFragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
fileUploadListener="#{themeWidgetFragment.handleImageFileUpload}" label="#{bundle['dataverse.theme.logo.image.upload']}"/>
</p:panelGrid>
<p:panelGrid rendered="#{empty themeWidgetFragment.editDv.dataverseTheme.logo}" columns="2" styleClass="noBorders">
<p:fileUpload id="uploadlogo" invalidFileMessage="#{bundle['dataverse.theme.logo.image.invalidMsg']}" sizeLimit="500000" allowTypes="/(\.|\/)(jpg|jpeg|tff|png|gif)$/" update=":themeWidgetsForm:themeWidgetsTabView" oncomplete="bind_bsui_components();" dragDropSupport="true" auto="true" multiple="false"
<p:fileUpload id="uploadlogo" invalidFileMessage="#{bundle['dataverse.theme.logo.image.invalidMsg']}" sizeLimit="#{systemConfig.thumbnailSizeLimitImage}" allowTypes="/(\.|\/)(jpg|jpeg|tff|png|gif)$/" update=":themeWidgetsForm:themeWidgetsTabView" oncomplete="bind_bsui_components();" dragDropSupport="true" auto="true" multiple="false"
fileUploadListener="#{themeWidgetFragment.handleImageFileUpload}" label="#{bundle['dataverse.theme.logo.image.uploadImgFile']}"/>
</p:panelGrid>
<ui:fragment rendered="#{not empty themeWidgetFragment.editDv.dataverseTheme.logo}">
Expand Down
18 changes: 16 additions & 2 deletions src/test/java/edu/harvard/iq/dataverse/api/SearchIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1459,14 +1459,28 @@ public void testDatasetThumbnail() {
.body("data[0]", CoreMatchers.equalTo("dataverseproject.png"))
.body("data[1]", CoreMatchers.equalTo("trees.png"))
.statusCode(200);

String datasetLogo = "src/main/webapp/resources/images/cc0.png";
Response overrideThumbnail = UtilIT.uploadDatasetLogo(datasetPersistentId, datasetLogo, apiToken);
overrideThumbnail.prettyPrint();
overrideThumbnail.then().assertThat()
.body("data.message", CoreMatchers.equalTo("Thumbnail is now " + BundleUtil.getStringFromBundle("dataset.thumbnailsAndWidget.thumbnailImage.nonDatasetFile")))
.statusCode(200);


//Add Failing Test logo file too big
String smallFile = "10";
Response setThumbnailSizeLimitImage = UtilIT.setSetting(SettingsServiceBean.Key.ThumbnailSizeLimitImage, smallFile);

Response overrideThumbnailFail = UtilIT.uploadDatasetLogo(datasetPersistentId, datasetLogo, apiToken);

overrideThumbnailFail.prettyPrint();
overrideThumbnailFail.then().assertThat()
.body("message", CoreMatchers.equalTo("File is larger than maximum size: " + smallFile + "."))
.statusCode(400);

setThumbnailSizeLimitImage = UtilIT.setSetting(SettingsServiceBean.Key.ThumbnailSizeLimitImage, "500000");


Response getThumbnail4 = UtilIT.getDatasetThumbnail(datasetPersistentId, apiToken);
getThumbnail4.prettyPrint();
getThumbnail4.then().assertThat()
Expand Down

0 comments on commit 591c0c2

Please sign in to comment.