mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +00:00
91680: Remove versioning.block.entity property
Versioning of DSpace entities is now properly supported, so from now on it is possible to create/edit versions of any item, regardless of whether it's an entity or not.
This commit is contained in:

committed by
Ben Bosman

parent
3a5766a5d2
commit
0edfbc9fae
@@ -10,7 +10,6 @@ import java.sql.SQLException;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.dspace.app.rest.authorization.AuthorizationFeature;
|
import org.dspace.app.rest.authorization.AuthorizationFeature;
|
||||||
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
|
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
|
||||||
import org.dspace.app.rest.model.BaseObjectRest;
|
import org.dspace.app.rest.model.BaseObjectRest;
|
||||||
@@ -58,13 +57,6 @@ 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)) {
|
||||||
// The property versioning.block.entity is used to disable versioning for items with EntityType
|
|
||||||
boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
|
|
||||||
boolean hasEntityType = StringUtils.isNotBlank(itemService.
|
|
||||||
getMetadataFirstValue(item, "dspace", "entity", "type", Item.ANY));
|
|
||||||
if (isBlockEntity && hasEntityType) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (authorizeService.isAdmin(context, item)) {
|
if (authorizeService.isAdmin(context, item)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -9,14 +9,12 @@ package org.dspace.app.rest.authorization.impl;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
|
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
|
||||||
import org.dspace.app.rest.converter.ItemConverter;
|
import org.dspace.app.rest.converter.ItemConverter;
|
||||||
import org.dspace.app.rest.model.BaseObjectRest;
|
import org.dspace.app.rest.model.BaseObjectRest;
|
||||||
import org.dspace.app.rest.model.ItemRest;
|
import org.dspace.app.rest.model.ItemRest;
|
||||||
import org.dspace.app.rest.model.VersionRest;
|
import org.dspace.app.rest.model.VersionRest;
|
||||||
import org.dspace.app.rest.projection.DefaultProjection;
|
import org.dspace.app.rest.projection.DefaultProjection;
|
||||||
import org.dspace.content.Item;
|
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.services.ConfigurationService;
|
import org.dspace.services.ConfigurationService;
|
||||||
@@ -57,12 +55,6 @@ 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);
|
||||||
boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
|
|
||||||
boolean hasEntityType = StringUtils.isNotBlank(
|
|
||||||
itemService.getMetadataFirstValue(version.getItem(), "dspace", "entity", "type", Item.ANY));
|
|
||||||
if (isBlockEntity && hasEntityType) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return super.isAuthorized(context, itemRest);
|
return super.isAuthorized(context, itemRest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,14 +9,11 @@ package org.dspace.app.rest.authorization.impl;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.dspace.app.rest.authorization.AuthorizationFeature;
|
import org.dspace.app.rest.authorization.AuthorizationFeature;
|
||||||
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
|
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
|
||||||
import org.dspace.app.rest.model.BaseObjectRest;
|
import org.dspace.app.rest.model.BaseObjectRest;
|
||||||
import org.dspace.app.rest.model.VersionRest;
|
import org.dspace.app.rest.model.VersionRest;
|
||||||
import org.dspace.authorize.service.AuthorizeService;
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
import org.dspace.content.Item;
|
|
||||||
import org.dspace.content.service.ItemService;
|
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.services.ConfigurationService;
|
import org.dspace.services.ConfigurationService;
|
||||||
import org.dspace.versioning.Version;
|
import org.dspace.versioning.Version;
|
||||||
@@ -37,8 +34,6 @@ public class CanEditVersionFeature implements AuthorizationFeature {
|
|||||||
|
|
||||||
public static final String NAME = "canEditVersion";
|
public static final String NAME = "canEditVersion";
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ItemService itemService;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AuthorizeService authorizeService;
|
private AuthorizeService authorizeService;
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -56,12 +51,6 @@ 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())) {
|
||||||
boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
|
|
||||||
boolean hasEntityType = StringUtils.isNotBlank(
|
|
||||||
itemService.getMetadataFirstValue(version.getItem(), "dspace", "entity", "type", Item.ANY));
|
|
||||||
if (isBlockEntity && hasEntityType) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return authorizeService.isAdmin(context, version.getItem());
|
return authorizeService.isAdmin(context, version.getItem());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,6 @@ import java.sql.SQLException;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.dspace.app.rest.authorization.AuthorizationFeature;
|
import org.dspace.app.rest.authorization.AuthorizationFeature;
|
||||||
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
|
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
|
||||||
import org.dspace.app.rest.model.BaseObjectRest;
|
import org.dspace.app.rest.model.BaseObjectRest;
|
||||||
@@ -54,12 +53,6 @@ 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)) {
|
||||||
boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
|
|
||||||
boolean hasEntityType = StringUtils.isNotBlank(itemService.
|
|
||||||
getMetadataFirstValue(item, "dspace", "entity", "type", Item.ANY));
|
|
||||||
if (isBlockEntity && hasEntityType) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return authorizeService.isAdmin(context, item);
|
return authorizeService.isAdmin(context, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -110,10 +110,6 @@ public class VersionRestRepository extends DSpaceRestRepository<VersionRest, Int
|
|||||||
throw new UnprocessableEntityException("The given URI list could not be properly parsed to one result");
|
throw new UnprocessableEntityException("The given URI list could not be properly parsed to one result");
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasEntityType = StringUtils.isNotBlank(itemService.
|
|
||||||
getMetadataFirstValue(item, "dspace", "entity", "type", Item.ANY));
|
|
||||||
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");
|
||||||
@@ -121,10 +117,6 @@ public class VersionRestRepository extends DSpaceRestRepository<VersionRest, Int
|
|||||||
if (!isAdmin && !(canCreateVersion && Objects.equals(submitter, context.getCurrentUser()))) {
|
if (!isAdmin && !(canCreateVersion && Objects.equals(submitter, context.getCurrentUser()))) {
|
||||||
throw new AuthorizeException("The logged user doesn't have the rights to create a new version.");
|
throw new AuthorizeException("The logged user doesn't have the rights to create a new version.");
|
||||||
}
|
}
|
||||||
if (hasEntityType && isBlockEntity) {
|
|
||||||
throw new AuthorizeException("You are trying to create a new version for an entity" +
|
|
||||||
" which is blocked by the configuration");
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkflowItem workflowItem = null;
|
WorkflowItem workflowItem = null;
|
||||||
WorkspaceItem workspaceItem = null;
|
WorkspaceItem workspaceItem = null;
|
||||||
|
@@ -720,38 +720,7 @@ public class VersionRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createFirstVersionItemWithentityTypeByAdminAndPropertyBlockEntityEnableTest() throws Exception {
|
public void createFirstVersionItemWithEntityTypeTest() throws Exception {
|
||||||
configurationService.setProperty("versioning.block.entity", true);
|
|
||||||
context.turnOffAuthorisationSystem();
|
|
||||||
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
|
||||||
.withName("Parent Community")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Collection col = CollectionBuilder.createCollection(context, rootCommunity)
|
|
||||||
.withName("Collection 1")
|
|
||||||
.withEntityType("Publication")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Item itemA = ItemBuilder.createItem(context, col)
|
|
||||||
.withTitle("Public item")
|
|
||||||
.withIssueDate("2021-04-19")
|
|
||||||
.withAuthor("Doe, John")
|
|
||||||
.withSubject("ExtraEntry")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
context.restoreAuthSystemState();
|
|
||||||
|
|
||||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
|
||||||
getClient(adminToken).perform(post("/api/versioning/versions")
|
|
||||||
.param("summary", "test summary!")
|
|
||||||
.contentType(MediaType.parseMediaType(RestMediaTypes.TEXT_URI_LIST_VALUE))
|
|
||||||
.content("/api/core/items/" + itemA.getID()))
|
|
||||||
.andExpect(status().isForbidden());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createFirstVersionItemWithEntityTypeAndPropertyBlockEntityDisabledTest() throws Exception {
|
|
||||||
configurationService.setProperty("versioning.block.entity", false);
|
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||||
.withName("Parent Community")
|
.withName("Parent Community")
|
||||||
@@ -793,9 +762,8 @@ public class VersionRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createFirstVersionItemWithEntityTypeBySubmitterAndPropertyBlockEntityDisabledTest() throws Exception {
|
public void createFirstVersionItemWithEntityTypeBySubmitterTest() throws Exception {
|
||||||
configurationService.setProperty("versioning.submitterCanCreateNewVersion", true);
|
configurationService.setProperty("versioning.submitterCanCreateNewVersion", true);
|
||||||
configurationService.setProperty("versioning.block.entity", false);
|
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
||||||
.withName("Parent Community")
|
.withName("Parent Community")
|
||||||
|
@@ -304,57 +304,9 @@ public class CanCreateVersionFeatureIT extends AbstractControllerIntegrationTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkCanCreateVersionFeatureAndPropertyBlockEntityEnableTest() throws Exception {
|
public void checkCanCreateVersionFeatureTest() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
configurationService.setProperty("versioning.block.entity", true);
|
|
||||||
|
|
||||||
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
|
||||||
.withName("Parent Community")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Collection col = CollectionBuilder.createCollection(context, rootCommunity)
|
|
||||||
.withName("Collection 1")
|
|
||||||
.withEntityType("Publication")
|
|
||||||
.withAdminGroup(eperson)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Item itemA = ItemBuilder.createItem(context, col)
|
|
||||||
.withTitle("Public item")
|
|
||||||
.withIssueDate("2021-04-19")
|
|
||||||
.withAuthor("Doe, John")
|
|
||||||
.withSubject("ExtraEntry")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
context.restoreAuthSystemState();
|
|
||||||
|
|
||||||
ItemRest itemRestA = itemConverter.convert(itemA, DefaultProjection.DEFAULT);
|
|
||||||
|
|
||||||
String tokenEPerson = getAuthToken(eperson.getEmail(), password);
|
|
||||||
String tokenAdmin = getAuthToken(admin.getEmail(), password);
|
|
||||||
String tokenUser = getAuthToken(user.getEmail(), password);
|
|
||||||
|
|
||||||
// define authorization that we know not exists
|
|
||||||
Authorization user2ItemA = new Authorization(user, canCreateVersionFeature, itemRestA);
|
|
||||||
Authorization admin2ItemA = new Authorization(admin, canCreateVersionFeature, itemRestA);
|
|
||||||
Authorization eperson2ItemA = new Authorization(eperson, canCreateVersionFeature, itemRestA);
|
|
||||||
|
|
||||||
getClient(tokenAdmin).perform(get("/api/authz/authorizations/" + admin2ItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
getClient(tokenUser).perform(get("/api/authz/authorizations/" + user2ItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
getClient(tokenEPerson).perform(get("/api/authz/authorizations/" + eperson2ItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void checkCanCreateVersionFeatureAndPropertyBlockEntityDisabledTest() throws Exception {
|
|
||||||
context.turnOffAuthorisationSystem();
|
|
||||||
|
|
||||||
configurationService.setProperty("versioning.block.entity", false);
|
|
||||||
|
|
||||||
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
||||||
.withName("Parent Community")
|
.withName("Parent Community")
|
||||||
.build();
|
.build();
|
||||||
@@ -396,51 +348,4 @@ public class CanCreateVersionFeatureIT extends AbstractControllerIntegrationTest
|
|||||||
.andExpect(status().isNotFound());
|
.andExpect(status().isNotFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void checkCanCreateVersionFeatureAndPropertyBlockEntityUnsetedTest() throws Exception {
|
|
||||||
context.turnOffAuthorisationSystem();
|
|
||||||
|
|
||||||
configurationService.setProperty("versioning.submitterCanCreateNewVersion", true);
|
|
||||||
configurationService.setProperty("versioning.block.entity", null);
|
|
||||||
|
|
||||||
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
|
||||||
.withName("Parent Community")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Collection col = CollectionBuilder.createCollection(context, rootCommunity)
|
|
||||||
.withName("Collection 1")
|
|
||||||
.withEntityType("Publication")
|
|
||||||
.withSubmitterGroup(eperson)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Item itemA = ItemBuilder.createItem(context, col)
|
|
||||||
.withTitle("Public item")
|
|
||||||
.withIssueDate("2021-04-19")
|
|
||||||
.withAuthor("Doe, John")
|
|
||||||
.withSubject("ExtraEntry")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
context.restoreAuthSystemState();
|
|
||||||
|
|
||||||
ItemRest itemRestA = itemConverter.convert(itemA, DefaultProjection.DEFAULT);
|
|
||||||
|
|
||||||
String tokenEPerson = getAuthToken(eperson.getEmail(), password);
|
|
||||||
String tokenAdmin = getAuthToken(admin.getEmail(), password);
|
|
||||||
String tokenUser = getAuthToken(user.getEmail(), password);
|
|
||||||
|
|
||||||
// define authorization that we know not exists
|
|
||||||
Authorization user2ItemA = new Authorization(user, canCreateVersionFeature, itemRestA);
|
|
||||||
Authorization admin2ItemA = new Authorization(admin, canCreateVersionFeature, itemRestA);
|
|
||||||
Authorization eperson2ItemA = new Authorization(eperson, canCreateVersionFeature, itemRestA);
|
|
||||||
|
|
||||||
getClient(tokenAdmin).perform(get("/api/authz/authorizations/" + admin2ItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
getClient(tokenUser).perform(get("/api/authz/authorizations/" + user2ItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
getClient(tokenEPerson).perform(get("/api/authz/authorizations/" + eperson2ItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@@ -28,7 +28,6 @@ import org.dspace.content.Item;
|
|||||||
import org.dspace.content.WorkspaceItem;
|
import org.dspace.content.WorkspaceItem;
|
||||||
import org.dspace.content.service.WorkspaceItemService;
|
import org.dspace.content.service.WorkspaceItemService;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.services.ConfigurationService;
|
|
||||||
import org.dspace.versioning.Version;
|
import org.dspace.versioning.Version;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -47,8 +46,6 @@ public class CanDeleteVersionFeatureIT extends AbstractControllerIntegrationTest
|
|||||||
@Autowired
|
@Autowired
|
||||||
private WorkspaceItemService workspaceItemService;
|
private WorkspaceItemService workspaceItemService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ConfigurationService configurationService;
|
|
||||||
@Autowired
|
|
||||||
private AuthorizationFeatureService authorizationFeatureService;
|
private AuthorizationFeatureService authorizationFeatureService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private org.dspace.content.service.InstallItemService installItemService;
|
private org.dspace.content.service.InstallItemService installItemService;
|
||||||
@@ -259,59 +256,9 @@ public class CanDeleteVersionFeatureIT extends AbstractControllerIntegrationTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canDeleteVersionFeatureAndPropertyBlockEntityEnableTest() throws Exception {
|
public void canDeleteVersionFeatureTest() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
configurationService.setProperty("versioning.block.entity", true);
|
|
||||||
|
|
||||||
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
|
||||||
.withName("Parent Community")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Collection col = CollectionBuilder.createCollection(context, rootCommunity)
|
|
||||||
.withName("Collection 1")
|
|
||||||
.withEntityType("Publication")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Item itemA = ItemBuilder.createItem(context, col)
|
|
||||||
.withTitle("Public item")
|
|
||||||
.withIssueDate("2021-04-19")
|
|
||||||
.withAuthor("Doe, John")
|
|
||||||
.withSubject("ExtraEntry")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Version version = VersionBuilder.createVersion(context, itemA, "My test summary").build();
|
|
||||||
WorkspaceItem workspaceItem = workspaceItemService.findByItem(context, version.getItem());
|
|
||||||
installItemService.installItem(context, workspaceItem);
|
|
||||||
|
|
||||||
context.restoreAuthSystemState();
|
|
||||||
|
|
||||||
VersionRest versionRest = versionConverter.convert(version, DefaultProjection.DEFAULT);
|
|
||||||
|
|
||||||
String tokenEPerson = getAuthToken(eperson.getEmail(), password);
|
|
||||||
String tokenAdmin = getAuthToken(admin.getEmail(), password);
|
|
||||||
|
|
||||||
// define authorization that we know not exists
|
|
||||||
Authorization admin2ItemA = new Authorization(admin, canDeleteVersionFeature, versionRest);
|
|
||||||
Authorization eperson2ItemA = new Authorization(eperson, canDeleteVersionFeature, versionRest);
|
|
||||||
Authorization anonymous2ItemA = new Authorization(null, canDeleteVersionFeature, versionRest);
|
|
||||||
|
|
||||||
getClient(tokenAdmin).perform(get("/api/authz/authorizations/" + admin2ItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
getClient(tokenEPerson).perform(get("/api/authz/authorizations/" + eperson2ItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
getClient().perform(get("/api/authz/authorizations/" + anonymous2ItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void canDeleteVersionFeatureAndPropertyBlockEntityDisabledTest() throws Exception {
|
|
||||||
context.turnOffAuthorisationSystem();
|
|
||||||
|
|
||||||
configurationService.setProperty("versioning.block.entity", false);
|
|
||||||
|
|
||||||
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
||||||
.withName("Parent Community")
|
.withName("Parent Community")
|
||||||
.build();
|
.build();
|
||||||
|
@@ -202,70 +202,7 @@ public class CanEditVersionFeatureIT extends AbstractControllerIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canEditVersionsFeatureByColAndComAdminsAndPropertyBlockEntityEnableTest() throws Exception {
|
public void canEditVersionsFeatureByColAndComAdminsTest2() throws Exception {
|
||||||
configurationService.setProperty("versioning.block.entity", true);
|
|
||||||
context.turnOffAuthorisationSystem();
|
|
||||||
EPerson adminComA = EPersonBuilder.createEPerson(context)
|
|
||||||
.withEmail("testComAdminA@test.com")
|
|
||||||
.withPassword(password)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
EPerson adminCol1 = EPersonBuilder.createEPerson(context)
|
|
||||||
.withEmail("testCol1Admin@test.com")
|
|
||||||
.withPassword(password)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
|
||||||
.withName("Parent Community")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Community subCommunityA = CommunityBuilder.createSubCommunity(context, rootCommunity)
|
|
||||||
.withName("Sub Community A")
|
|
||||||
.withAdminGroup(adminComA)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Collection col1 = CollectionBuilder.createCollection(context, subCommunityA)
|
|
||||||
.withName("Collection 1")
|
|
||||||
.withEntityType("Publication")
|
|
||||||
.withSubmitterGroup(eperson)
|
|
||||||
.withAdminGroup(adminCol1)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Item item = ItemBuilder.createItem(context, col1)
|
|
||||||
.withTitle("Public item")
|
|
||||||
.withIssueDate("2021-04-19")
|
|
||||||
.withAuthor("Doe, John")
|
|
||||||
.withSubject("ExtraEntry")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Version version = VersionBuilder.createVersion(context, item, "My test summary").build();
|
|
||||||
|
|
||||||
context.restoreAuthSystemState();
|
|
||||||
|
|
||||||
VersionRest versionRest = versionConverter.convert(version, DefaultProjection.DEFAULT);
|
|
||||||
|
|
||||||
String tokenAdmin = getAuthToken(admin.getEmail(), password);
|
|
||||||
String tokenAdminComA = getAuthToken(adminComA.getEmail(), password);
|
|
||||||
String tokenAdminCol1 = getAuthToken(adminCol1.getEmail(), password);
|
|
||||||
|
|
||||||
// define authorization that we know not exists
|
|
||||||
Authorization adminOfComAToVersion = new Authorization(adminComA, canEditVersionFeature, versionRest);
|
|
||||||
Authorization adminOfCol1ToVersion = new Authorization(adminCol1, canEditVersionFeature, versionRest);
|
|
||||||
Authorization adminToVersion = new Authorization(admin, canEditVersionFeature, versionRest);
|
|
||||||
|
|
||||||
getClient(tokenAdminComA).perform(get("/api/authz/authorizations/" + adminOfComAToVersion.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
getClient(tokenAdminCol1).perform(get("/api/authz/authorizations/" + adminOfCol1ToVersion.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
getClient(tokenAdmin).perform(get("/api/authz/authorizations/" + adminToVersion.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void canEditVersionsFeatureByColAndComAdminsAndPropertyBlockEntityDisabledTest() throws Exception {
|
|
||||||
configurationService.setProperty("versioning.block.entity", false);
|
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
EPerson adminComA = EPersonBuilder.createEPerson(context)
|
EPerson adminComA = EPersonBuilder.createEPerson(context)
|
||||||
.withEmail("testComAdminA@test.com")
|
.withEmail("testComAdminA@test.com")
|
||||||
|
@@ -28,7 +28,6 @@ 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;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.services.ConfigurationService;
|
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -47,9 +46,6 @@ public class CanManageVersionsFeatureIT extends AbstractControllerIntegrationTes
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ItemConverter itemConverter;
|
private ItemConverter itemConverter;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ConfigurationService configurationService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AuthorizationFeatureService authorizationFeatureService;
|
private AuthorizationFeatureService authorizationFeatureService;
|
||||||
|
|
||||||
@@ -207,180 +203,4 @@ public class CanManageVersionsFeatureIT extends AbstractControllerIntegrationTes
|
|||||||
.andExpect(status().isNotFound());
|
.andExpect(status().isNotFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void canManageVersionsFeatureAdminsAndPropertyBlockEntityEnableTest() throws Exception {
|
|
||||||
configurationService.setProperty("versioning.block.entity", true);
|
|
||||||
context.turnOffAuthorisationSystem();
|
|
||||||
EPerson adminComA = EPersonBuilder.createEPerson(context)
|
|
||||||
.withEmail("testComAdminA@test.com")
|
|
||||||
.withPassword(password)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
EPerson adminComB = EPersonBuilder.createEPerson(context)
|
|
||||||
.withEmail("testComBdminA@test.com")
|
|
||||||
.withPassword(password)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
EPerson adminCol1 = EPersonBuilder.createEPerson(context)
|
|
||||||
.withEmail("testCol1Admin@test.com")
|
|
||||||
.withPassword(password)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
EPerson adminCol2 = EPersonBuilder.createEPerson(context)
|
|
||||||
.withEmail("testCol2Admin@test.com")
|
|
||||||
.withPassword(password)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
|
||||||
.withName("Parent Community")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Community subCommunityA = CommunityBuilder.createSubCommunity(context, rootCommunity)
|
|
||||||
.withName("Sub Community A")
|
|
||||||
.withAdminGroup(adminComA)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
CommunityBuilder.createSubCommunity(context, rootCommunity)
|
|
||||||
.withName("Sub Community B")
|
|
||||||
.withAdminGroup(adminComB)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Collection col1 = CollectionBuilder.createCollection(context, subCommunityA)
|
|
||||||
.withName("Collection 1")
|
|
||||||
.withEntityType("Publication")
|
|
||||||
.withSubmitterGroup(eperson)
|
|
||||||
.withAdminGroup(adminCol1)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
CollectionBuilder.createCollection(context, subCommunityA)
|
|
||||||
.withName("Collection 2")
|
|
||||||
.withAdminGroup(adminCol2)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Item itemA = ItemBuilder.createItem(context, col1)
|
|
||||||
.withTitle("Public item")
|
|
||||||
.withIssueDate("2021-04-19")
|
|
||||||
.withAuthor("Doe, John")
|
|
||||||
.withSubject("ExtraEntry")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
context.restoreAuthSystemState();
|
|
||||||
|
|
||||||
ItemRest itemRestA = itemConverter.convert(itemA, DefaultProjection.DEFAULT);
|
|
||||||
|
|
||||||
String tokenAdminComA = getAuthToken(adminComA.getEmail(), password);
|
|
||||||
String tokenAdminComB = getAuthToken(adminComB.getEmail(), password);
|
|
||||||
String tokenAdminCol1 = getAuthToken(adminCol1.getEmail(), password);
|
|
||||||
String tokenAdminCol2 = getAuthToken(adminCol2.getEmail(), password);
|
|
||||||
|
|
||||||
// define authorization that we know not exists
|
|
||||||
Authorization adminOfComAToItemA = new Authorization(adminComA, canManageVersionsFeature, itemRestA);
|
|
||||||
Authorization adminOfCol1ToItemA = new Authorization(adminCol1, canManageVersionsFeature, itemRestA);
|
|
||||||
Authorization adminOfComBToItemA = new Authorization(adminComB, canManageVersionsFeature, itemRestA);
|
|
||||||
Authorization adminOfCol2ToItemA = new Authorization(adminCol2, canManageVersionsFeature, itemRestA);
|
|
||||||
|
|
||||||
getClient(tokenAdminComA).perform(get("/api/authz/authorizations/" + adminOfComAToItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
getClient(tokenAdminCol1).perform(get("/api/authz/authorizations/" + adminOfCol1ToItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
getClient(tokenAdminComB).perform(get("/api/authz/authorizations/" + adminOfComBToItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
getClient(tokenAdminCol2).perform(get("/api/authz/authorizations/" + adminOfCol2ToItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void canManageVersionsFeatureAdminsAndPropertyBlockEntityDisabledTest() throws Exception {
|
|
||||||
configurationService.setProperty("versioning.block.entity", false);
|
|
||||||
context.turnOffAuthorisationSystem();
|
|
||||||
EPerson adminComA = EPersonBuilder.createEPerson(context)
|
|
||||||
.withEmail("testComAdminA@test.com")
|
|
||||||
.withPassword(password)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
EPerson adminComB = EPersonBuilder.createEPerson(context)
|
|
||||||
.withEmail("testComBdminA@test.com")
|
|
||||||
.withPassword(password)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
EPerson adminCol1 = EPersonBuilder.createEPerson(context)
|
|
||||||
.withEmail("testCol1Admin@test.com")
|
|
||||||
.withPassword(password)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
EPerson adminCol2 = EPersonBuilder.createEPerson(context)
|
|
||||||
.withEmail("testCol2Admin@test.com")
|
|
||||||
.withPassword(password)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
|
||||||
.withName("Parent Community")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Community subCommunityA = CommunityBuilder.createSubCommunity(context, rootCommunity)
|
|
||||||
.withName("Sub Community A")
|
|
||||||
.withAdminGroup(adminComA)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
CommunityBuilder.createSubCommunity(context, rootCommunity)
|
|
||||||
.withName("Sub Community B")
|
|
||||||
.withAdminGroup(adminComB)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Collection col1 = CollectionBuilder.createCollection(context, subCommunityA)
|
|
||||||
.withName("Collection 1")
|
|
||||||
.withEntityType("Publication")
|
|
||||||
.withSubmitterGroup(eperson)
|
|
||||||
.withAdminGroup(adminCol1)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
CollectionBuilder.createCollection(context, subCommunityA)
|
|
||||||
.withName("Collection 2")
|
|
||||||
.withAdminGroup(adminCol2)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Item itemA = ItemBuilder.createItem(context, col1)
|
|
||||||
.withTitle("Public item")
|
|
||||||
.withIssueDate("2021-04-19")
|
|
||||||
.withAuthor("Doe, John")
|
|
||||||
.withSubject("ExtraEntry")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
context.restoreAuthSystemState();
|
|
||||||
|
|
||||||
ItemRest itemRestA = itemConverter.convert(itemA, DefaultProjection.DEFAULT);
|
|
||||||
|
|
||||||
String tokenAdminComA = getAuthToken(adminComA.getEmail(), password);
|
|
||||||
String tokenAdminComB = getAuthToken(adminComB.getEmail(), password);
|
|
||||||
String tokenAdminCol1 = getAuthToken(adminCol1.getEmail(), password);
|
|
||||||
String tokenAdminCol2 = getAuthToken(adminCol2.getEmail(), password);
|
|
||||||
|
|
||||||
// define authorizations that we know must exists
|
|
||||||
Authorization adminOfComAToItemA = new Authorization(adminComA, canManageVersionsFeature, itemRestA);
|
|
||||||
Authorization adminOfCol1ToItemA = new Authorization(adminCol1, canManageVersionsFeature, itemRestA);
|
|
||||||
|
|
||||||
// define authorization that we know not exists
|
|
||||||
Authorization adminOfComBToItemA = new Authorization(adminComB, canManageVersionsFeature, itemRestA);
|
|
||||||
Authorization adminOfCol2ToItemA = new Authorization(adminCol2, canManageVersionsFeature, itemRestA);
|
|
||||||
|
|
||||||
getClient(tokenAdminComA).perform(get("/api/authz/authorizations/" + adminOfComAToItemA.getID()))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(jsonPath("$", Matchers.is(
|
|
||||||
AuthorizationMatcher.matchAuthorization(adminOfComAToItemA))));
|
|
||||||
|
|
||||||
getClient(tokenAdminCol1).perform(get("/api/authz/authorizations/" + adminOfCol1ToItemA.getID()))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(jsonPath("$", Matchers.is(
|
|
||||||
AuthorizationMatcher.matchAuthorization(adminOfCol1ToItemA))));
|
|
||||||
|
|
||||||
getClient(tokenAdminComB).perform(get("/api/authz/authorizations/" + adminOfComBToItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
getClient(tokenAdminCol2).perform(get("/api/authz/authorizations/" + adminOfCol2ToItemA.getID()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@@ -20,7 +20,3 @@ versioning.item.history.include.submitter=false
|
|||||||
# If you want to allow submitters to create new versions of there items, set
|
# If you want to allow submitters to create new versions of there items, set
|
||||||
# the property submitterCanCreateNewVersion true.
|
# the property submitterCanCreateNewVersion true.
|
||||||
# versioning.submitterCanCreateNewVersion=false
|
# versioning.submitterCanCreateNewVersion=false
|
||||||
|
|
||||||
# The property versioning.block.entity is used to disable versioning
|
|
||||||
# for items with EntityType, the default value is true if it unset.
|
|
||||||
versioning.block.entity=false
|
|
||||||
|
Reference in New Issue
Block a user