mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 14:33:09 +00:00
103818 Extend ItemServiceTest#testMoveItemToCollectionWithMoreRestrictiveReadPolicy
This commit is contained in:
@@ -963,13 +963,18 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
|||||||
}
|
}
|
||||||
// TODO: should we also throw an exception if no DEFAULT_ITEM_READ?
|
// TODO: should we also throw an exception if no DEFAULT_ITEM_READ?
|
||||||
|
|
||||||
|
boolean removeCurrentReadRPBitstream =
|
||||||
|
replaceReadRPWithCollectionRP && defaultCollectionBitstreamPolicies.size() > 0;
|
||||||
|
boolean removeCurrentReadRPBundle =
|
||||||
|
replaceReadRPWithCollectionRP && defaultCollectionBundlePolicies.size() > 0;
|
||||||
|
|
||||||
// remove all policies from bundles, add new ones
|
// remove all policies from bundles, add new ones
|
||||||
// Remove bundles
|
// Remove bundles
|
||||||
List<Bundle> bunds = item.getBundles();
|
List<Bundle> bunds = item.getBundles();
|
||||||
for (Bundle mybundle : bunds) {
|
for (Bundle mybundle : bunds) {
|
||||||
// If collection has default READ policies, remove the bitstream's READ policies.
|
// If collection has default READ policies, remove the bundle's READ policies.
|
||||||
if (replaceReadRPWithCollectionRP && defaultCollectionBitstreamPolicies.size() > 0) {
|
if (removeCurrentReadRPBundle) {
|
||||||
authorizeService.removePoliciesActionFilter(context, item, Constants.READ);
|
authorizeService.removePoliciesActionFilter(context, mybundle, Constants.READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if come from InstallItem: remove all submission/workflow policies
|
// if come from InstallItem: remove all submission/workflow policies
|
||||||
@@ -979,6 +984,11 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
|||||||
addDefaultPoliciesNotInPlace(context, mybundle, defaultCollectionBundlePolicies);
|
addDefaultPoliciesNotInPlace(context, mybundle, defaultCollectionBundlePolicies);
|
||||||
|
|
||||||
for (Bitstream bitstream : mybundle.getBitstreams()) {
|
for (Bitstream bitstream : mybundle.getBitstreams()) {
|
||||||
|
// If collection has default READ policies, remove the bundle's READ policies.
|
||||||
|
if (removeCurrentReadRPBitstream) {
|
||||||
|
authorizeService.removePoliciesActionFilter(context, bitstream, Constants.READ);
|
||||||
|
}
|
||||||
|
|
||||||
// if come from InstallItem: remove all submission/workflow policies
|
// if come from InstallItem: remove all submission/workflow policies
|
||||||
removeAllPoliciesAndAddDefault(context, bitstream, defaultItemPolicies,
|
removeAllPoliciesAndAddDefault(context, bitstream, defaultItemPolicies,
|
||||||
defaultCollectionBitstreamPolicies);
|
defaultCollectionBitstreamPolicies);
|
||||||
|
@@ -39,6 +39,7 @@ import org.dspace.builder.RelationshipTypeBuilder;
|
|||||||
import org.dspace.builder.RequestItemBuilder;
|
import org.dspace.builder.RequestItemBuilder;
|
||||||
import org.dspace.builder.ResourcePolicyBuilder;
|
import org.dspace.builder.ResourcePolicyBuilder;
|
||||||
import org.dspace.content.Bitstream;
|
import org.dspace.content.Bitstream;
|
||||||
|
import org.dspace.content.Bundle;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.Community;
|
import org.dspace.content.Community;
|
||||||
import org.dspace.content.EntityType;
|
import org.dspace.content.EntityType;
|
||||||
@@ -786,22 +787,47 @@ public class ItemServiceTest extends AbstractIntegrationTestWithDatabase {
|
|||||||
.createItem(context, permissive)
|
.createItem(context, permissive)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Verify that the item has exactly one READ policy, for the anonymous group.
|
Bitstream bitstream = BitstreamBuilder.createBitstream(context, item, InputStream.nullInputStream())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Bundle bundle = item.getBundles("ORIGINAL").get(0);
|
||||||
|
|
||||||
|
// Verify that the item, bundle and bitstream each have exactly one READ policy, for the anonymous group.
|
||||||
assertEquals(
|
assertEquals(
|
||||||
List.of(anonymous),
|
List.of(anonymous),
|
||||||
authorizeService.getPoliciesActionFilter(context, item, Constants.READ)
|
authorizeService.getPoliciesActionFilter(context, item, Constants.READ)
|
||||||
.stream().map(ResourcePolicy::getGroup).collect(Collectors.toList())
|
.stream().map(ResourcePolicy::getGroup).collect(Collectors.toList())
|
||||||
);
|
);
|
||||||
|
assertEquals(
|
||||||
|
List.of(anonymous),
|
||||||
|
authorizeService.getPoliciesActionFilter(context, bundle, Constants.READ)
|
||||||
|
.stream().map(ResourcePolicy::getGroup).collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
List.of(anonymous),
|
||||||
|
authorizeService.getPoliciesActionFilter(context, bitstream, Constants.READ)
|
||||||
|
.stream().map(ResourcePolicy::getGroup).collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
|
||||||
// Move the item to the restrictive collection, making sure to inherit default policies.
|
// Move the item to the restrictive collection, making sure to inherit default policies.
|
||||||
itemService.move(context, item, permissive, restrictive, true);
|
itemService.move(context, item, permissive, restrictive, true);
|
||||||
|
|
||||||
// Verify that the item has exactly one READ policy, but now for the admin group.
|
// Verify that the item, bundle and bitstream each have exactly one READ policy, but now for the admin group.
|
||||||
assertEquals(
|
assertEquals(
|
||||||
List.of(admin),
|
List.of(admin),
|
||||||
authorizeService.getPoliciesActionFilter(context, item, Constants.READ)
|
authorizeService.getPoliciesActionFilter(context, item, Constants.READ)
|
||||||
.stream().map(ResourcePolicy::getGroup).collect(Collectors.toList())
|
.stream().map(ResourcePolicy::getGroup).collect(Collectors.toList())
|
||||||
);
|
);
|
||||||
|
assertEquals(
|
||||||
|
List.of(anonymous),
|
||||||
|
authorizeService.getPoliciesActionFilter(context, bundle, Constants.READ)
|
||||||
|
.stream().map(ResourcePolicy::getGroup).collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
List.of(anonymous),
|
||||||
|
authorizeService.getPoliciesActionFilter(context, bitstream, Constants.READ)
|
||||||
|
.stream().map(ResourcePolicy::getGroup).collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user