Implement community feedbacks

This commit is contained in:
Mykhaylo
2021-09-20 16:37:43 +02:00
parent 87040d154f
commit 496bb35eea
14 changed files with 211 additions and 86 deletions

View File

@@ -11,11 +11,15 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.services.ConfigurationService;
import org.dspace.versioning.dao.VersionHistoryDAO; import org.dspace.versioning.dao.VersionHistoryDAO;
import org.dspace.versioning.service.VersionHistoryService; import org.dspace.versioning.service.VersionHistoryService;
import org.dspace.versioning.service.VersioningService; import org.dspace.versioning.service.VersioningService;
@@ -34,6 +38,12 @@ public class VersionHistoryServiceImpl implements VersionHistoryService {
@Autowired(required = true) @Autowired(required = true)
private VersioningService versioningService; private VersioningService versioningService;
@Autowired
private AuthorizeService authorizeService;
@Autowired
private ConfigurationService configurationService;
protected VersionHistoryServiceImpl() { protected VersionHistoryServiceImpl() {
} }
@@ -210,4 +220,20 @@ public class VersionHistoryServiceImpl implements VersionHistoryService {
return versionHistoryDAO.findByItem(context, item); return versionHistoryDAO.findByItem(context, item);
} }
@Override
public boolean canSeeDraftVersion(Context context, VersionHistory versionHistory) throws SQLException {
Version version = this.getLatestVersion(context, versionHistory);
if (Objects.nonNull(version)) {
EPerson submitter = version.getItem().getSubmitter();
boolean isAdmin = authorizeService.isAdmin(context);
boolean canCreateVersion = configurationService
.getBooleanProperty("versioning.submitterCanCreateNewVersion");
if (!isAdmin && !(canCreateVersion && Objects.equals(submitter, context.getCurrentUser()))) {
return false;
}
return true;
}
return false;
}
} }

View File

@@ -67,4 +67,6 @@ public interface VersionHistoryService extends DSpaceCRUDService<VersionHistory>
public void remove(VersionHistory versionHistory, Version version); public void remove(VersionHistory versionHistory, Version version);
public boolean canSeeDraftVersion(Context context, VersionHistory versionHistory) throws SQLException;
} }

View File

@@ -55,9 +55,7 @@ public class CanCreateVersionFeature implements AuthorizationFeature {
} }
Item item = itemService.find(context, UUID.fromString(((ItemRest) object).getUuid())); Item item = itemService.find(context, UUID.fromString(((ItemRest) object).getUuid()));
if (Objects.nonNull(item)) { if (Objects.nonNull(item)) {
String stringBlockEntity = configurationService.getProperty("versioning.block.entity"); boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
boolean isBlockEntity = StringUtils.isNotBlank(stringBlockEntity) ?
Boolean.valueOf(stringBlockEntity) : true;
boolean hasEntityType = StringUtils.isNotBlank(itemService. boolean hasEntityType = StringUtils.isNotBlank(itemService.
getMetadataFirstValue(item, "dspace", "entity", "type", Item.ANY)); getMetadataFirstValue(item, "dspace", "entity", "type", Item.ANY));
if (isBlockEntity && hasEntityType) { if (isBlockEntity && hasEntityType) {

View File

@@ -54,9 +54,7 @@ public class CanDeleteVersionFeature extends DeleteFeature {
Version version = versioningService.getVersion(context, ((VersionRest)object).getId()); Version version = versioningService.getVersion(context, ((VersionRest)object).getId());
if (Objects.nonNull(version) && Objects.nonNull(version.getItem())) { if (Objects.nonNull(version) && Objects.nonNull(version.getItem())) {
ItemRest itemRest = itemConverter.convert(version.getItem(), DefaultProjection.DEFAULT); ItemRest itemRest = itemConverter.convert(version.getItem(), DefaultProjection.DEFAULT);
String stringBlockEntity = configurationService.getProperty("versioning.block.entity"); boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
boolean isBlockEntity = StringUtils.isNotBlank(stringBlockEntity) ?
Boolean.valueOf(stringBlockEntity) : true;
boolean hasEntityType = StringUtils.isNotBlank( boolean hasEntityType = StringUtils.isNotBlank(
itemService.getMetadataFirstValue(version.getItem(), "dspace", "entity", "type", Item.ANY)); itemService.getMetadataFirstValue(version.getItem(), "dspace", "entity", "type", Item.ANY));
if (isBlockEntity && hasEntityType) { if (isBlockEntity && hasEntityType) {

View File

@@ -57,9 +57,7 @@ public class CanEditVersionFeature implements AuthorizationFeature {
} }
Version version = versioningService.getVersion(context, (((VersionRest) object).getId())); Version version = versioningService.getVersion(context, (((VersionRest) object).getId()));
if (Objects.nonNull(version) && Objects.nonNull(version.getItem())) { if (Objects.nonNull(version) && Objects.nonNull(version.getItem())) {
String stringBlockEntity = configurationService.getProperty("versioning.block.entity"); boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
boolean isBlockEntity = StringUtils.isNotBlank(stringBlockEntity) ?
Boolean.valueOf(stringBlockEntity) : true;
boolean hasEntityType = StringUtils.isNotBlank( boolean hasEntityType = StringUtils.isNotBlank(
itemService.getMetadataFirstValue(version.getItem(), "dspace", "entity", "type", Item.ANY)); itemService.getMetadataFirstValue(version.getItem(), "dspace", "entity", "type", Item.ANY));
if (isBlockEntity && hasEntityType) { if (isBlockEntity && hasEntityType) {

View File

@@ -53,9 +53,7 @@ public class CanManageVersionsFeature implements AuthorizationFeature {
} }
Item item = itemService.find(context, UUID.fromString(((ItemRest) object).getUuid())); Item item = itemService.find(context, UUID.fromString(((ItemRest) object).getUuid()));
if (Objects.nonNull(item)) { if (Objects.nonNull(item)) {
String stringBlockEntity = configurationService.getProperty("versioning.block.entity"); boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
boolean isBlockEntity = StringUtils.isNotBlank(stringBlockEntity) ?
Boolean.valueOf(stringBlockEntity) : true;
boolean hasEntityType = StringUtils.isNotBlank(itemService. boolean hasEntityType = StringUtils.isNotBlank(itemService.
getMetadataFirstValue(item, "dspace", "entity", "type", Item.ANY)); getMetadataFirstValue(item, "dspace", "entity", "type", Item.ANY));
if (isBlockEntity && hasEntityType) { if (isBlockEntity && hasEntityType) {

View File

@@ -15,13 +15,9 @@ import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.model.VersionHistoryRest; import org.dspace.app.rest.model.VersionHistoryRest;
import org.dspace.app.rest.projection.Projection; import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.utils.ContextUtil; import org.dspace.app.rest.utils.ContextUtil;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.services.ConfigurationService;
import org.dspace.services.RequestService; import org.dspace.services.RequestService;
import org.dspace.services.model.Request; import org.dspace.services.model.Request;
import org.dspace.versioning.Version;
import org.dspace.versioning.VersionHistory; import org.dspace.versioning.VersionHistory;
import org.dspace.versioning.service.VersionHistoryService; import org.dspace.versioning.service.VersionHistoryService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -38,12 +34,6 @@ public class VersionHistoryConverter implements DSpaceConverter<VersionHistory,
@Autowired @Autowired
private RequestService requestService; private RequestService requestService;
@Autowired
private AuthorizeService authorizeService;
@Autowired
private ConfigurationService configurationService;
@Autowired @Autowired
private VersionHistoryService versionHistoryService; private VersionHistoryService versionHistoryService;
@@ -51,12 +41,16 @@ public class VersionHistoryConverter implements DSpaceConverter<VersionHistory,
public VersionHistoryRest convert(VersionHistory modelObject, Projection projection) { public VersionHistoryRest convert(VersionHistory modelObject, Projection projection) {
Context context = getContext(); Context context = getContext();
VersionHistoryRest versionHistoryRest = new VersionHistoryRest(); VersionHistoryRest versionHistoryRest = new VersionHistoryRest();
try {
versionHistoryRest.setId(modelObject.getID()); versionHistoryRest.setId(modelObject.getID());
if (Objects.nonNull(context.getCurrentUser())) { if (Objects.nonNull(context.getCurrentUser())) {
if (canSeeDraftVersion(context, modelObject)) { if (versionHistoryService.canSeeDraftVersion(context, modelObject)) {
versionHistoryRest.setDraftVersion(modelObject.hasDraftVersion()); versionHistoryRest.setDraftVersion(modelObject.hasDraftVersion());
} }
} }
} catch (SQLException e) {
log.error(e.getMessage(), e);
}
return versionHistoryRest; return versionHistoryRest;
} }
@@ -65,25 +59,6 @@ public class VersionHistoryConverter implements DSpaceConverter<VersionHistory,
return VersionHistory.class; return VersionHistory.class;
} }
private boolean canSeeDraftVersion(Context context, VersionHistory versionHistory) {
try {
Version version = versionHistoryService.getLatestVersion(context, versionHistory);
if (Objects.nonNull(version)) {
EPerson submitter = version.getItem().getSubmitter();
boolean isAdmin = authorizeService.isAdmin(context);
boolean canCreateVersion = configurationService
.getBooleanProperty("versioning.submitterCanCreateNewVersion");
if (!isAdmin && !(canCreateVersion && Objects.equals(submitter, context.getCurrentUser()))) {
return false;
}
return true;
}
} catch (SQLException e) {
log.error(e.getMessage(), e);
}
return false;
}
/** /**
* Retrieves the context from the request * Retrieves the context from the request
* If not request is found, will return null * If not request is found, will return null

View File

@@ -1,28 +0,0 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
* @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.it)
*/
@ResponseStatus(value = HttpStatus.FORBIDDEN, reason = "Forbidden request")
public class DSpaceForbiddenException extends RuntimeException {
private static final long serialVersionUID = 8869331967657914409L;
public DSpaceForbiddenException(String message, Throwable cause) {
super(message, cause);
}
public DSpaceForbiddenException(String message) {
super(message);
}
}

View File

@@ -57,11 +57,11 @@ public class VersionHistoryDraftVersionLinkRepository extends AbstractDSpaceRest
Projection projection) throws SQLException { Projection projection) throws SQLException {
Context context = obtainContext(); Context context = obtainContext();
if (Objects.isNull(versionHistoryId) || versionHistoryId < 0) { if (Objects.isNull(versionHistoryId) || versionHistoryId < 0) {
throw new DSpaceBadRequestException("Provied id is not correct!"); throw new DSpaceBadRequestException("Provided id is not correct!");
} }
VersionHistory versionHistory = versionHistoryService.find(context, versionHistoryId); VersionHistory versionHistory = versionHistoryService.find(context, versionHistoryId);
if (Objects.isNull(versionHistory)) { if (Objects.isNull(versionHistory)) {
throw new ResourceNotFoundException("No such versio found"); throw new ResourceNotFoundException("No such version found");
} }
Version oldestVersion = versionHistoryService.getLatestVersion(context, versionHistory); Version oldestVersion = versionHistoryService.getLatestVersion(context, versionHistory);

View File

@@ -15,7 +15,6 @@ import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.converter.ConverterService; import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.exception.DSpaceBadRequestException; import org.dspace.app.rest.exception.DSpaceBadRequestException;
import org.dspace.app.rest.exception.DSpaceForbiddenException;
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException; import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
import org.dspace.app.rest.exception.UnprocessableEntityException; import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.VersionRest; import org.dspace.app.rest.model.VersionRest;
@@ -113,16 +112,15 @@ public class VersionRestRepository extends DSpaceRestRepository<VersionRest, Int
boolean hasEntityType = StringUtils.isNotBlank(itemService. boolean hasEntityType = StringUtils.isNotBlank(itemService.
getMetadataFirstValue(item, "dspace", "entity", "type", Item.ANY)); getMetadataFirstValue(item, "dspace", "entity", "type", Item.ANY));
String stringBlockEntity = configurationService.getProperty("versioning.block.entity"); boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
EPerson submitter = item.getSubmitter(); EPerson submitter = item.getSubmitter();
boolean isAdmin = authorizeService.isAdmin(context); boolean isAdmin = authorizeService.isAdmin(context);
boolean canCreateVersion = configurationService.getBooleanProperty("versioning.submitterCanCreateNewVersion"); boolean canCreateVersion = configurationService.getBooleanProperty("versioning.submitterCanCreateNewVersion");
boolean isBlockEntity = StringUtils.isNotBlank(stringBlockEntity) ? Boolean.valueOf(stringBlockEntity) : true;
if (!isAdmin && !(canCreateVersion && Objects.equals(submitter, context.getCurrentUser())) || if (!isAdmin && !(canCreateVersion && Objects.equals(submitter, context.getCurrentUser())) ||
(hasEntityType && isBlockEntity)) { (hasEntityType && isBlockEntity)) {
throw new DSpaceForbiddenException(""); throw new AuthorizeException();
} }
WorkflowItem workflowItem = null; WorkflowItem workflowItem = null;
@@ -140,7 +138,8 @@ public class VersionRestRepository extends DSpaceRestRepository<VersionRest, Int
} }
if (Objects.nonNull(workflowItem) || Objects.nonNull(workspaceItem)) { if (Objects.nonNull(workflowItem) || Objects.nonNull(workspaceItem)) {
throw new UnprocessableEntityException(""); throw new UnprocessableEntityException("It is not possible to create a new version"
+ " if the latest one in submisssion!");
} }
Version version = StringUtils.isNotBlank(summary) ? Version version = StringUtils.isNotBlank(summary) ?
@@ -168,8 +167,8 @@ public class VersionRestRepository extends DSpaceRestRepository<VersionRest, Int
break; break;
case "add": case "add":
if (StringUtils.isNotBlank(version.getSummary())) { if (StringUtils.isNotBlank(version.getSummary())) {
throw new DSpaceBadRequestException("The 'summary' property is setted with value:" throw new DSpaceBadRequestException("The 'summary' already contains the value: "
+ version.getSummary() + ", it is not possible to add new value"); + version.getSummary() + ", it is not possible to add a new value.");
} }
version.setSummary(operation.getValue().toString()); version.setSummary(operation.getValue().toString());
break; break;

View File

@@ -33,6 +33,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* Methods of this class are used on PreAuthorize annotations
* to convert input parameters.
*
* @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.it) * @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.it)
*/ */
@Component(value = "extractorOf") @Component(value = "extractorOf")

View File

@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicReference;
import org.dspace.app.rest.matcher.VersionHistoryMatcher; import org.dspace.app.rest.matcher.VersionHistoryMatcher;
import org.dspace.app.rest.matcher.VersionMatcher; import org.dspace.app.rest.matcher.VersionMatcher;
import org.dspace.app.rest.matcher.WorkflowItemMatcher;
import org.dspace.app.rest.matcher.WorkspaceItemMatcher; import org.dspace.app.rest.matcher.WorkspaceItemMatcher;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest; import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
@@ -29,6 +30,7 @@ import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder; import org.dspace.builder.CommunityBuilder;
import org.dspace.builder.ItemBuilder; import org.dspace.builder.ItemBuilder;
import org.dspace.builder.VersionBuilder; import org.dspace.builder.VersionBuilder;
import org.dspace.builder.WorkflowItemBuilder;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.content.Community; import org.dspace.content.Community;
import org.dspace.content.Item; import org.dspace.content.Item;
@@ -39,6 +41,7 @@ import org.dspace.versioning.Version;
import org.dspace.versioning.VersionHistory; import org.dspace.versioning.VersionHistory;
import org.dspace.versioning.service.VersionHistoryService; import org.dspace.versioning.service.VersionHistoryService;
import org.dspace.versioning.service.VersioningService; import org.dspace.versioning.service.VersioningService;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -380,6 +383,119 @@ public class VersionHistoryRestRepositoryIT extends AbstractControllerIntegratio
.andExpect(status().isUnauthorized()); .andExpect(status().isUnauthorized());
} }
@Test
public void findDraftOfVersionNotFoundTest() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection test")
.build();
Item item = ItemBuilder.createItem(context, col)
.withTitle("Public test item")
.withIssueDate("2021-04-27")
.withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
VersionBuilder.createVersion(context, item, "test").build();
context.turnOffAuthorisationSystem();
String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(get("/api/versioning/versionhistories/" + Integer.MAX_VALUE + "/draftVersion"))
.andExpect(status().isNotFound());
}
@Test
public void findDraftOfVersionNoContentTest() throws Exception {
//disable file upload mandatory
configurationService.setProperty("webui.submit.upload.required", false);
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection test")
.withSubmitterGroup(admin)
.build();
Item item = ItemBuilder.createItem(context, col)
.withTitle("Public test item")
.withIssueDate("2021-04-27")
.withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
Version version = VersionBuilder.createVersion(context, item, "test").build();
VersionHistory vh = versionHistoryService.findByItem(context, version.getItem());
context.turnOffAuthorisationSystem();
AtomicReference<Integer> idRef = new AtomicReference<Integer>();
String tokenAdmin = getAuthToken(admin.getEmail(), password);
// retrieve the workspace item
getClient(tokenAdmin).perform(get("/api/submission/workspaceitems/search/item")
.param("uuid", String.valueOf(version.getItem().getID())))
.andExpect(status().isOk())
.andDo(result -> idRef.set(read(result.getResponse().getContentAsString(), "$.id")));
// submit the workspaceitem to complete the deposit
getClient(tokenAdmin).perform(post(BASE_REST_SERVER_URL + "/api/workflow/workflowitems")
.content("/api/submission/workspaceitems/" + idRef.get())
.contentType(textUriContentType))
.andExpect(status().isCreated());
getClient(tokenAdmin).perform(get("/api/versioning/versionhistories/" + vh.getID() + "/draftVersion"))
.andExpect(status().isNoContent());
}
@Test
public void findWorkflowItemOfDraftVersionAdminTest() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection 1")
.withWorkflowGroup(1, admin)
.build();
Item item = ItemBuilder.createItem(context, col)
.withTitle("Public test item")
.withIssueDate("2021-04-27")
.withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
XmlWorkflowItem witem = WorkflowItemBuilder.createWorkflowItem(context, col)
.withTitle("Workflow Item 1")
.withIssueDate("2017-10-17")
.withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
Version version = VersionBuilder.createVersion(context, item, "test").build();
version.setItem(witem.getItem());
VersionHistory vh = versionHistoryService.findByItem(context, version.getItem());
context.turnOffAuthorisationSystem();
String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(get("/api/versioning/versionhistories/" + vh.getID() + "/draftVersion"))
.andExpect(jsonPath("$", Matchers.is(
WorkflowItemMatcher.matchItemWithTitleAndDateIssuedAndSubject(witem,
"Workflow Item 1", "2017-10-17", "ExtraEntry"))));
}
@Test @Test
public void findWorkspaceItemOfDraftVersionLoggedUserTest() throws Exception { public void findWorkspaceItemOfDraftVersionLoggedUserTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -412,7 +528,7 @@ public class VersionHistoryRestRepositoryIT extends AbstractControllerIntegratio
} }
@Test @Test
public void findVersionsOfVersionHistoryCheckPaginationAfterDelitingOfVersionTest() throws Exception { public void findVersionsOfVersionHistoryCheckPaginationAfterDeletingOfVersionTest() throws Exception {
//disable file upload mandatory //disable file upload mandatory
configurationService.setProperty("webui.submit.upload.required", false); configurationService.setProperty("webui.submit.upload.required", false);
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();

View File

@@ -8,6 +8,7 @@
package org.dspace.app.rest; package org.dspace.app.rest;
import static com.jayway.jsonpath.JsonPath.read; import static com.jayway.jsonpath.JsonPath.read;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath; import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static org.hamcrest.Matchers.emptyOrNullString;
import static org.hamcrest.Matchers.emptyString; import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
@@ -293,6 +294,46 @@ public class VersionRestRepositoryIT extends AbstractControllerIntegrationTest {
} }
} }
@Test
public void createFirstVersionWithoutSummaryTest() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection test")
.build();
Item item = ItemBuilder.createItem(context, col)
.withTitle("Public test item")
.withIssueDate("2021-04-27")
.withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
context.restoreAuthSystemState();
AtomicReference<Integer> idRef = new AtomicReference<Integer>();
String adminToken = getAuthToken(admin.getEmail(), password);
try {
getClient(adminToken).perform(post("/api/versioning/versions")
.contentType(MediaType.parseMediaType(RestMediaTypes.TEXT_URI_LIST_VALUE))
.content("/api/core/items/" + item.getID()))
.andExpect(status().isCreated())
.andExpect(jsonPath("$", Matchers.allOf(
hasJsonPath("$.version", is(2)),
hasJsonPath("$.summary", emptyOrNullString()),
hasJsonPath("$.submitterName", is("first (admin) last (admin)")),
hasJsonPath("$.type", is("version"))
)))
.andDo(result -> idRef.set(read(result.getResponse().getContentAsString(), "$.id")));
} finally {
VersionBuilder.delete(idRef.get());
}
}
@Test @Test
public void createFirstVersionItemBadRequestTest() throws Exception { public void createFirstVersionItemBadRequestTest() throws Exception {
String adminToken = getAuthToken(admin.getEmail(), password); String adminToken = getAuthToken(admin.getEmail(), password);

View File

@@ -409,7 +409,7 @@ public class CanCreateVersionFeatureIT extends AbstractControllerIntegrationTest
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
configurationService.setProperty("versioning.submitterCanCreateNewVersion", true); configurationService.setProperty("versioning.submitterCanCreateNewVersion", true);
configurationService.setProperty("versioning.block.entity", ""); configurationService.setProperty("versioning.block.entity", null);
Community rootCommunity = CommunityBuilder.createCommunity(context) Community rootCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community") .withName("Parent Community")
@@ -417,7 +417,6 @@ public class CanCreateVersionFeatureIT extends AbstractControllerIntegrationTest
Collection col = CollectionBuilder.createCollection(context, rootCommunity) Collection col = CollectionBuilder.createCollection(context, rootCommunity)
.withName("Collection 1") .withName("Collection 1")
.withAdminGroup(eperson)
.withSubmitterGroup(eperson) .withSubmitterGroup(eperson)
.build(); .build();