Skip to content
Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
abollini committed Oct 25, 2021
1 parent 0de9680 commit 277b499
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Expand Up @@ -920,8 +920,7 @@ public Group createDefaultReadGroup(Context context, Collection collection, Stri
int defaultRead)
throws SQLException, AuthorizeException {
Group role = groupService.create(context);
groupService.setName(role, "COLLECTION_" + collection.getID().toString() + "_" + typeOfGroupString +
"_DEFAULT_READ");
groupService.setName(role, getDefaultReadGroupName(collection, typeOfGroupString));

// Remove existing privileges from the anonymous group.
authorizeService.removePoliciesActionFilter(context, collection, defaultRead);
Expand All @@ -932,6 +931,12 @@ public Group createDefaultReadGroup(Context context, Collection collection, Stri
return role;
}

@Override
public String getDefaultReadGroupName(Collection collection, String typeOfGroupString) {
return "COLLECTION_" + collection.getID().toString() + "_" + typeOfGroupString +
"_DEFAULT_READ";
}

@Override
public List<Collection> findCollectionsWithSubmit(String q, Context context, Community community,
int offset, int limit) throws SQLException, SearchServiceException {
Expand Down
Expand Up @@ -360,6 +360,16 @@ public List<Collection> findAuthorized(Context context, Community community, int
Group createDefaultReadGroup(Context context, Collection collection, String typeOfGroupString, int defaultRead)
throws SQLException, AuthorizeException;

/**
* This method will return the name to give to the group created by the
* {@link #createDefaultReadGroup(Context, Collection, String, int)} method
*
* @param collection The DSpace collection to use in the name generation
* @param typeOfGroupString The type of group to use in the name generation
* @return the name to give to the group that hold default read for the collection
*/
String getDefaultReadGroupName(Collection collection, String typeOfGroupString);

/**
* Returns Collections for which the current user has 'submit' privileges.
* NOTE: for better performance, this method retrieves its results from an
Expand Down
20 changes: 16 additions & 4 deletions dspace-api/src/main/java/org/dspace/eperson/GroupServiceImpl.java
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -735,13 +736,24 @@ public DSpaceObject getParentObject(Context context, Group group) throws SQLExce
groups.add(group);
List<ResourcePolicy> policies = resourcePolicyService.find(context, null, groups,
Constants.DEFAULT_ITEM_READ, Constants.COLLECTION);
if (policies.size() > 0) {
return policies.get(0).getdSpaceObject();

Optional<ResourcePolicy> defaultPolicy = policies.stream().filter(p -> StringUtils.equals(
collectionService.getDefaultReadGroupName((Collection) p.getdSpaceObject(), "ITEM"),
group.getName())).findFirst();

if (defaultPolicy.isPresent()) {
return defaultPolicy.get().getdSpaceObject();
}
policies = resourcePolicyService.find(context, null, groups,
Constants.DEFAULT_BITSTREAM_READ, Constants.COLLECTION);
if (policies.size() > 0) {
return policies.get(0).getdSpaceObject();

defaultPolicy = policies.stream()
.filter(p -> StringUtils.equals(collectionService.getDefaultReadGroupName(
(Collection) p.getdSpaceObject(), "BITSTREAM"), group.getName()))
.findFirst();

if (defaultPolicy.isPresent()) {
return defaultPolicy.get().getdSpaceObject();
}
}
}
Expand Down

0 comments on commit 277b499

Please sign in to comment.