Skip to content

Commit 24ad849

Browse files
TUL/ The context user is set to current subscriber (#747)
* The context user is set to current subscriber * Updated comment * Fixed checktyle issue
1 parent cc6320d commit 24ad849

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationServiceImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public SubscriptionEmailNotificationServiceImpl(Map<String, DSpaceObjectUpdates>
6767
public void perform(Context context, DSpaceRunnableHandler handler, String subscriptionType, String frequency) {
6868
List<IndexableObject> communityItems = new ArrayList<>();
6969
List<IndexableObject> collectionsItems = new ArrayList<>();
70+
EPerson currentEperson = context.getCurrentUser();
7071
try {
7172
List<Subscription> subscriptions =
7273
findAllSubscriptionsBySubscriptionTypeAndFrequency(context, subscriptionType, frequency);
@@ -77,7 +78,10 @@ public void perform(Context context, DSpaceRunnableHandler handler, String subsc
7778
for (Subscription subscription : subscriptions) {
7879
DSpaceObject dSpaceObject = subscription.getDSpaceObject();
7980
EPerson ePerson = subscription.getEPerson();
80-
81+
// Set the current user to the subscribed eperson because the Solr query checks
82+
// the permissions of the current user in the ANONYMOUS group.
83+
// If there is no user (i.e., `current user = null`), it will send an email with no new items.
84+
context.setCurrentUser(ePerson);
8185
if (!authorizeService.authorizeActionBoolean(context, ePerson, dSpaceObject, READ, true)) {
8286
iterator++;
8387
continue;
@@ -126,6 +130,8 @@ public void perform(Context context, DSpaceRunnableHandler handler, String subsc
126130
handler.handleException(e);
127131
context.abort();
128132
}
133+
// Reset the current user because it was changed to subscriber eperson
134+
context.setCurrentUser(currentEperson);
129135
}
130136

131137
@SuppressWarnings("rawtypes")

0 commit comments

Comments
 (0)