From 0dddbf78db8f1e4e058a2d345c76d79d9a191c8a Mon Sep 17 00:00:00 2001 From: Mykhaylo Boychuk Date: Fri, 24 Nov 2023 13:01:21 +0100 Subject: [PATCH] [CST-12108] porting missing code --- .../service/impl/QAEventServiceImpl.java | 10 ++++++---- .../impl/CanDeleteVersionFeature.java | 3 --- .../app/rest/converter/QATopicConverter.java | 2 +- .../repository/QATopicRestRepository.java | 20 ++++++++----------- dspace/config/spring/api/qaevents.xml | 2 +- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/qaevent/service/impl/QAEventServiceImpl.java b/dspace-api/src/main/java/org/dspace/qaevent/service/impl/QAEventServiceImpl.java index 070f688935bf..0ab6f43cdbfc 100644 --- a/dspace-api/src/main/java/org/dspace/qaevent/service/impl/QAEventServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/qaevent/service/impl/QAEventServiceImpl.java @@ -242,14 +242,15 @@ public List findAllTopics(Context context, long offset, long count) { @Override public List findAllTopicsBySource(Context context, String source, long offset, long count) { - - if (source != null && isNotSupportedSource(source)) { - return null; + var currentUser = context.getCurrentUser(); + if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { + return List.of(); } + Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source); SolrQuery solrQuery = new SolrQuery(); solrQuery.setRows(0); - solrQuery.setQuery("*:*"); + solrQuery.setQuery(securityQuery.orElse("*:*")); solrQuery.setFacet(true); solrQuery.setFacetMinCount(1); solrQuery.setFacetLimit((int) (offset + count)); @@ -269,6 +270,7 @@ public List findAllTopicsBySource(Context context, String source, long continue; } QATopic topic = new QATopic(); + topic.setSource(source); topic.setKey(c.getName()); topic.setTotalEvents(c.getCount()); topic.setLastEvent(new Date()); diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/authorization/impl/CanDeleteVersionFeature.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/authorization/impl/CanDeleteVersionFeature.java index c20668fcc551..15438a5e9aa4 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/authorization/impl/CanDeleteVersionFeature.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/authorization/impl/CanDeleteVersionFeature.java @@ -15,7 +15,6 @@ import org.dspace.app.rest.model.ItemRest; import org.dspace.app.rest.model.VersionRest; import org.dspace.app.rest.projection.DefaultProjection; -import org.dspace.content.service.ItemService; import org.dspace.core.Context; import org.dspace.services.ConfigurationService; import org.dspace.versioning.Version; @@ -34,8 +33,6 @@ description = "It can be used to verify if the user can delete a version of an Item") public class CanDeleteVersionFeature extends DeleteFeature { - @Autowired - private ItemService itemService; @Autowired private ItemConverter itemConverter; @Autowired diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/QATopicConverter.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/QATopicConverter.java index efa32baba224..f12094d25712 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/QATopicConverter.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/QATopicConverter.java @@ -31,7 +31,7 @@ public Class getModelClass() { public QATopicRest convert(QATopic modelObject, Projection projection) { QATopicRest rest = new QATopicRest(); rest.setProjection(projection); - rest.setId(modelObject.getKey().replace("/", "!")); + rest.setId(modelObject.getSource() + ":" + modelObject.getKey().replace("/", "!")); rest.setName(modelObject.getKey()); rest.setLastEvent(modelObject.getLastEvent()); rest.setTotalEvents(modelObject.getTotalEvents()); diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/QATopicRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/QATopicRestRepository.java index 2c3d3a1ad9b8..1e5a47cbec55 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/QATopicRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/QATopicRestRepository.java @@ -12,6 +12,7 @@ import org.dspace.app.rest.Parameter; import org.dspace.app.rest.SearchRestMethod; +import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException; import org.dspace.app.rest.model.QATopicRest; import org.dspace.core.Context; import org.dspace.qaevent.QATopic; @@ -34,6 +35,11 @@ public class QATopicRestRepository extends DSpaceRestRepository findAll(Context context, Pageable pageable) { + throw new RepositoryMethodNotImplementedException("Method not allowed!", ""); + } + @Override @PreAuthorize("hasPermission(#id, 'QUALITYASSURANCETOPIC', 'READ')") public QATopicRest findOne(Context context, String id) { @@ -44,21 +50,11 @@ public QATopicRest findOne(Context context, String id) { return converter.toRest(topic, utils.obtainProjection()); } - @Override - @PreAuthorize("hasAuthority('ADMIN')") - public Page findAll(Context context, Pageable pageable) { - List topics = qaEventService.findAllTopics(context, pageable.getOffset(), pageable.getPageSize()); - long count = qaEventService.countTopics(); - if (topics == null) { - return null; - } - return converter.toRestPage(topics, pageable, count, utils.obtainProjection()); - } - @SearchRestMethod(name = "bySource") @PreAuthorize("hasAuthority('AUTHENTICATED')") - public Page findBySource(Context context, @Parameter(value = "source", required = true) String source, + public Page findBySource(@Parameter(value = "source", required = true) String source, Pageable pageable) { + Context context = obtainContext(); List topics = qaEventService.findAllTopicsBySource(context, source, pageable.getOffset(), pageable.getPageSize()); long count = qaEventService.countTopicsBySource(context, source); diff --git a/dspace/config/spring/api/qaevents.xml b/dspace/config/spring/api/qaevents.xml index 14c411996921..8c2964871aa3 100644 --- a/dspace/config/spring/api/qaevents.xml +++ b/dspace/config/spring/api/qaevents.xml @@ -85,7 +85,7 @@ - original_id:{0} AND '{'!join from=search.resourceid to=resource_uuid fromIndex=${solr.multicorePrefix}search'}'*:* + original_id:{0}