mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 06:23:10 +00:00
Merge pull request #1433 from tuub/DS-3240
DS-3240: comm/coll admins misses some functions and a propper navbar.
This commit is contained in:
@@ -418,6 +418,44 @@ public class AuthorizeServiceImpl implements AuthorizeService
|
||||
return groupService.isMember(c, Group.ADMIN);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCommunityAdmin(Context c) throws SQLException
|
||||
{
|
||||
EPerson e = c.getCurrentUser();
|
||||
|
||||
if (e != null)
|
||||
{
|
||||
List<ResourcePolicy> policies = resourcePolicyService.find(c, e,
|
||||
groupService.allMemberGroups(c, e),
|
||||
Constants.ADMIN, Constants.COMMUNITY);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(policies))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCollectionAdmin(Context c) throws SQLException
|
||||
{
|
||||
EPerson e = c.getCurrentUser();
|
||||
|
||||
if (e != null)
|
||||
{
|
||||
List<ResourcePolicy> policies = resourcePolicyService.find(c, e,
|
||||
groupService.allMemberGroups(c, e),
|
||||
Constants.ADMIN, Constants.COLLECTION);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(policies))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// policy manipulation methods
|
||||
|
@@ -107,6 +107,10 @@ public class ResourcePolicyServiceImpl implements ResourcePolicyService
|
||||
public List<ResourcePolicy> find(Context c, DSpaceObject dso, Group group, int action, int notPolicyID) throws SQLException {
|
||||
return resourcePolicyDAO.findByTypeIdGroupAction(c, dso, group, action, notPolicyID);
|
||||
}
|
||||
|
||||
public List<ResourcePolicy> find(Context c, EPerson e, List<Group> groups, int action, int type_id) throws SQLException{
|
||||
return resourcePolicyDAO.findByEPersonGroupTypeIdAction(c, e, groups, action, type_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an ResourcePolicy
|
||||
|
@@ -35,6 +35,8 @@ public interface ResourcePolicyDAO extends GenericDAO<ResourcePolicy> {
|
||||
public List<ResourcePolicy> findByDSoAndAction(Context context, DSpaceObject dso, int actionId) throws SQLException;
|
||||
|
||||
public List<ResourcePolicy> findByTypeIdGroupAction(Context context, DSpaceObject dso, Group group, int action, int notPolicyID) throws SQLException;
|
||||
|
||||
public List<ResourcePolicy> findByEPersonGroupTypeIdAction(Context context, EPerson e, List<Group> groups, int action, int type_id) throws SQLException;
|
||||
|
||||
public void deleteByDso(Context context, DSpaceObject dso) throws SQLException;
|
||||
|
||||
|
@@ -92,6 +92,19 @@ public class ResourcePolicyDAOImpl extends AbstractHibernateDAO<ResourcePolicy>
|
||||
|
||||
return list(criteria);
|
||||
}
|
||||
public List<ResourcePolicy> findByEPersonGroupTypeIdAction(Context context, EPerson e, List<Group> groups, int action, int type_id) throws SQLException
|
||||
{
|
||||
Criteria criteria = createCriteria(context, ResourcePolicy.class);
|
||||
criteria.add(Restrictions.and(
|
||||
Restrictions.eq("resourceTypeId", type_id),
|
||||
Restrictions.eq("actionId", action),
|
||||
(Restrictions.or(
|
||||
Restrictions.eq("eperson", e),
|
||||
Restrictions.in("epersonGroup", groups)
|
||||
))
|
||||
));
|
||||
return list(criteria);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByDso(Context context, DSpaceObject dso) throws SQLException
|
||||
|
@@ -179,6 +179,10 @@ public interface AuthorizeService {
|
||||
* @throws SQLException if database error
|
||||
*/
|
||||
public boolean isAdmin(Context c) throws SQLException;
|
||||
|
||||
public boolean isCommunityAdmin(Context c) throws SQLException;
|
||||
|
||||
public boolean isCollectionAdmin(Context c) throws SQLException;
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// policy manipulation methods
|
||||
|
@@ -36,6 +36,8 @@ public interface ResourcePolicyService extends DSpaceCRUDService<ResourcePolicy>
|
||||
public List<ResourcePolicy> find(Context c, DSpaceObject dso, Group group, int action, int notPolicyID) throws SQLException;
|
||||
|
||||
public List<ResourcePolicy> find(Context context, Group group) throws SQLException;
|
||||
|
||||
public List<ResourcePolicy> find(Context c, EPerson e, List<Group> groups, int action, int type_id) throws SQLException;
|
||||
|
||||
public String getActionText(ResourcePolicy resourcePolicy);
|
||||
|
||||
|
@@ -8,9 +8,12 @@
|
||||
package org.dspace.browse;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Constants;
|
||||
@@ -124,7 +127,9 @@ public class SolrBrowseDAO implements BrowseDAO
|
||||
private boolean distinct = false;
|
||||
|
||||
private String facetField;
|
||||
|
||||
|
||||
protected AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||
|
||||
// administrative attributes for this class
|
||||
|
||||
|
||||
@@ -207,6 +212,21 @@ public class SolrBrowseDAO implements BrowseDAO
|
||||
else if (!itemsDiscoverable)
|
||||
{
|
||||
query.addFilterQueries("discoverable:false");
|
||||
// TODO
|
||||
|
||||
try
|
||||
{
|
||||
if (!authorizeService.isAdmin(context)
|
||||
&& (authorizeService.isCommunityAdmin(context)
|
||||
|| authorizeService.isCollectionAdmin(context)))
|
||||
{
|
||||
query.addFilterQueries(searcher.createLocationQueryForAdministrableItems(context));
|
||||
}
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
log.error(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -105,7 +105,23 @@ public interface SearchService {
|
||||
*/
|
||||
DiscoverFilterQuery toFilterQuery(Context context, String field, String operator, String value) throws SQLException;
|
||||
|
||||
List<Item> getRelatedItems(Context context, Item item, DiscoveryMoreLikeThisConfiguration moreLikeThisConfiguration);
|
||||
List<Item> getRelatedItems(Context context, Item item, DiscoveryMoreLikeThisConfiguration moreLikeThisConfiguration);
|
||||
|
||||
/**
|
||||
* Method to create a Query that includes all
|
||||
* communities and collections a user may administrate.
|
||||
* If a user has the appropriate rights to administrate communities and/or
|
||||
* collections we want to look up all contents of those communities and/or
|
||||
* collections, ignoring the read policies of the items (e.g. to list all
|
||||
* private items of communities/collections the user administrate). This
|
||||
* method returns a query to filter for items that belongs to those
|
||||
* communities/collections only.
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
String createLocationQueryForAdministrableItems(Context context) throws SQLException;
|
||||
|
||||
/**
|
||||
* Transforms the metadata field of the given sort configuration into the indexed field which we can then use in our solr queries
|
||||
|
@@ -63,6 +63,10 @@ import java.sql.SQLException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||
|
||||
/**
|
||||
* SolrIndexer contains the methods that index Items and their metadata,
|
||||
@@ -687,6 +691,72 @@ public class SolrServiceImpl implements SearchService, IndexingService {
|
||||
|
||||
return locations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createLocationQueryForAdministrableItems(Context context)
|
||||
throws SQLException
|
||||
{
|
||||
StringBuilder locationQuery = new StringBuilder();
|
||||
|
||||
if (context.getCurrentUser() != null)
|
||||
{
|
||||
List<Group> groupList = EPersonServiceFactory.getInstance().getGroupService()
|
||||
.allMemberGroups(context, context.getCurrentUser());
|
||||
|
||||
List<ResourcePolicy> communitiesPolicies = AuthorizeServiceFactory.getInstance().getResourcePolicyService()
|
||||
.find(context, context.getCurrentUser(), groupList, Constants.ADMIN, Constants.COMMUNITY);
|
||||
|
||||
List<ResourcePolicy> collectionsPolicies = AuthorizeServiceFactory.getInstance().getResourcePolicyService()
|
||||
.find(context, context.getCurrentUser(), groupList, Constants.ADMIN, Constants.COLLECTION);
|
||||
|
||||
List<Collection> allCollections = new ArrayList<>();
|
||||
|
||||
for( ResourcePolicy rp: collectionsPolicies){
|
||||
Collection collection = ContentServiceFactory.getInstance().getCollectionService()
|
||||
.find(context, rp.getdSpaceObject().getID());
|
||||
allCollections.add(collection);
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(communitiesPolicies) || CollectionUtils.isNotEmpty(allCollections))
|
||||
{
|
||||
locationQuery.append("location:( ");
|
||||
|
||||
for (int i = 0; i< communitiesPolicies.size(); i++)
|
||||
{
|
||||
ResourcePolicy rp = communitiesPolicies.get(i);
|
||||
Community community = ContentServiceFactory.getInstance().getCommunityService()
|
||||
.find(context, rp.getdSpaceObject().getID());
|
||||
|
||||
locationQuery.append("m").append(community.getID());
|
||||
|
||||
if (i != (communitiesPolicies.size() - 1)) {
|
||||
locationQuery.append(" OR ");
|
||||
}
|
||||
allCollections.addAll(ContentServiceFactory.getInstance().getCommunityService()
|
||||
.getAllCollections(context, community));
|
||||
}
|
||||
|
||||
Iterator<Collection> collIter = allCollections.iterator();
|
||||
|
||||
if (communitiesPolicies.size() > 0 && allCollections.size() > 0) {
|
||||
locationQuery.append(" OR ");
|
||||
}
|
||||
|
||||
while (collIter.hasNext()) {
|
||||
locationQuery.append("l").append(collIter.next().getID());
|
||||
|
||||
if (collIter.hasNext()) {
|
||||
locationQuery.append(" OR ");
|
||||
}
|
||||
}
|
||||
locationQuery.append(")");
|
||||
} else {
|
||||
log.warn("We have a collection or community admin with ID: " + context.getCurrentUser().getID()
|
||||
+ " without any administrable collection or community!");
|
||||
}
|
||||
}
|
||||
return locationQuery.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the document to the index under the appropriate handle.
|
||||
|
@@ -7,11 +7,18 @@
|
||||
*/
|
||||
package org.dspace.discovery;
|
||||
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.solr.client.solrj.SolrQuery;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
import org.dspace.authorize.service.ResourcePolicyService;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
@@ -22,7 +29,11 @@ import org.dspace.eperson.service.GroupService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
|
||||
/**
|
||||
* Restriction plugin that ensures that indexes all the resource policies.
|
||||
@@ -39,7 +50,13 @@ public class SolrServiceResourceRestrictionPlugin implements SolrServiceIndexPlu
|
||||
@Autowired(required = true)
|
||||
protected AuthorizeService authorizeService;
|
||||
@Autowired(required = true)
|
||||
protected CommunityService communityService;
|
||||
@Autowired(required = true)
|
||||
protected CollectionService collectionService;
|
||||
@Autowired(required = true)
|
||||
protected GroupService groupService;
|
||||
@Autowired(required = true)
|
||||
protected ResourcePolicyService resourcePolicyService;
|
||||
|
||||
@Override
|
||||
public void additionalIndex(Context context, DSpaceObject dso, SolrInputDocument document) {
|
||||
@@ -86,7 +103,16 @@ public class SolrServiceResourceRestrictionPlugin implements SolrServiceIndexPlu
|
||||
resourceQuery.append(" OR g").append(group.getID());
|
||||
}
|
||||
|
||||
resourceQuery.append(")");
|
||||
resourceQuery.append(")");
|
||||
|
||||
if(authorizeService.isCommunityAdmin(context)
|
||||
|| authorizeService.isCollectionAdmin(context))
|
||||
{
|
||||
resourceQuery.append(" OR ");
|
||||
resourceQuery.append(DSpaceServicesFactory.getInstance()
|
||||
.getServiceManager().getServiceByName(SearchService.class.getName(), SearchService.class)
|
||||
.createLocationQueryForAdministrableItems(context));
|
||||
}
|
||||
|
||||
solrQuery.addFilterQuery(resourceQuery.toString());
|
||||
}
|
||||
|
Reference in New Issue
Block a user