Fixed https://github.com/DSpace/DSpace/issues/10754 by setting the context user to the current subscriber

This commit is contained in:
jm
2025-05-16 15:56:55 +02:00
parent 440ac598ee
commit 6275d3b756

View File

@@ -67,6 +67,7 @@ public class SubscriptionEmailNotificationServiceImpl implements SubscriptionEma
public void perform(Context context, DSpaceRunnableHandler handler, String subscriptionType, String frequency) {
List<IndexableObject> communityItems = new ArrayList<>();
List<IndexableObject> collectionsItems = new ArrayList<>();
EPerson currentEperson = context.getCurrentUser();
try {
List<Subscription> subscriptions =
findAllSubscriptionsBySubscriptionTypeAndFrequency(context, subscriptionType, frequency);
@@ -77,7 +78,10 @@ public class SubscriptionEmailNotificationServiceImpl implements SubscriptionEma
for (Subscription subscription : subscriptions) {
DSpaceObject dSpaceObject = subscription.getDSpaceObject();
EPerson ePerson = subscription.getEPerson();
// Set the current user to the subscribed eperson because the Solr query checks
// the permissions of the current user in the ANONYMOUS group.
// If there is no user (i.e., `current user = null`), it will send an email with no new items.
context.setCurrentUser(ePerson);
if (!authorizeService.authorizeActionBoolean(context, ePerson, dSpaceObject, READ, true)) {
iterator++;
continue;
@@ -126,6 +130,8 @@ public class SubscriptionEmailNotificationServiceImpl implements SubscriptionEma
handler.handleException(e);
context.abort();
}
// Reset the current user because it was changed to subscriber eperson
context.setCurrentUser(currentEperson);
}
@SuppressWarnings("rawtypes")