added indexing for ADMIN policies

This commit is contained in:
Mykhaylo Boychuk
2020-02-28 16:16:18 +01:00
parent b15001b54e
commit f7a12ab3d3

View File

@@ -8,6 +8,7 @@
package org.dspace.discovery;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;
@@ -18,7 +19,11 @@ import org.apache.solr.common.SolrInputDocument;
import org.dspace.authorize.ResourcePolicy;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.authorize.service.ResourcePolicyService;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CollectionService;
import org.dspace.content.service.CommunityService;
import org.dspace.core.Constants;
@@ -77,6 +82,29 @@ public class SolrServiceResourceRestrictionPlugin implements SolrServiceIndexPlu
//remove the policy from the cache to save memory
context.uncacheEntity(resourcePolicy);
}
// also index ADMIN policies as ADMIN permissions provides READ access
// going up through the hierarchy for communities, collections and items
while (dso != null) {
if (dso instanceof Community || dso instanceof Collection || dso instanceof Item) {
List<ResourcePolicy> policiesAdmin = authorizeService
.getPoliciesActionFilter(context, dso, Constants.ADMIN);
for (ResourcePolicy resourcePolicy : policiesAdmin) {
String fieldValue;
if (resourcePolicy.getGroup() != null) {
// We have a group add it to the value
fieldValue = "g" + resourcePolicy.getGroup().getID();
} else {
// We have an eperson add it to the value
fieldValue = "e" + resourcePolicy.getEPerson().getID();
}
document.addField("read", fieldValue);
// remove the policy from the cache to save memory
context.uncacheEntity(resourcePolicy);
}
}
dso = ContentServiceFactory.getInstance().getDSpaceObjectService(dso).getParentObject(context, dso);
}
} catch (SQLException e) {
log.error(LogManager.getHeader(context, "Error while indexing resource policies",
"DSpace object: (id " + dso.getID() + " type " + dso.getType() + ")"));