Skip to content

Commit

Permalink
[CST-12108] introduced withdrawn&reinstate group & sent email to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Micheleboychuk committed Jan 24, 2024
1 parent 96ee430 commit 7f32714
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@
package org.dspace.correctiontype;

import static org.dspace.content.QAEvent.DSPACE_USERS_SOURCE;
import static org.dspace.correctiontype.WithdrawnCorrectionType.WITHDRAWAL_REINSTATE_GROUP;

import java.sql.SQLException;
import java.util.Date;
import java.util.Objects;
import java.util.UUID;

import com.google.gson.Gson;
import org.apache.commons.lang3.StringUtils;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Item;
import org.dspace.content.QAEvent;
import org.dspace.core.Context;
import org.dspace.eperson.Group;
import org.dspace.eperson.service.GroupService;
import org.dspace.qaevent.service.QAEventService;
import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO;
import org.dspace.qaevent.service.dto.QAMessageDTO;
import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -35,18 +43,37 @@ public class ReinstateCorrectionType implements CorrectionType, InitializingBean
private String topic;
private String creationForm;

@Autowired
private GroupService groupService;
@Autowired
private QAEventService qaEventService;
@Autowired
private AuthorizeService authorizeService;
@Autowired
private ConfigurationService configurationService;

@Override
public boolean isAllowed(Context context, Item targetItem) throws SQLException {
if (!targetItem.isWithdrawn()) {
return false;
}
boolean isAdmin = authorizeService.isAdmin(context);
if (!currentUserIsMemberOfwithdrawalReinstateGroup(context) && !isAdmin) {
return false;
}
long tot = qaEventService.countSourcesByTarget(context, targetItem.getID());
return tot == 0;
}

private boolean currentUserIsMemberOfwithdrawalReinstateGroup(Context context) throws SQLException {
String withdrawalReinstateGroupUUID = configurationService.getProperty(WITHDRAWAL_REINSTATE_GROUP);
if (StringUtils.isBlank(withdrawalReinstateGroupUUID)) {
return false;
}
Group withdrawalReinstateGroup = groupService.find(context, UUID.fromString(withdrawalReinstateGroupUUID));
return Objects.nonNull(withdrawalReinstateGroup) && groupService.isMember(context, withdrawalReinstateGroup);
}

@Override
public boolean isAllowed(Context context, Item targetItem, Item relatedItem) throws AuthorizeException,
SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@

import java.sql.SQLException;
import java.util.Date;
import java.util.Objects;
import java.util.UUID;

import com.google.gson.Gson;
import org.apache.commons.lang3.StringUtils;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Item;
import org.dspace.content.QAEvent;
import org.dspace.core.Context;
import org.dspace.eperson.Group;
import org.dspace.eperson.service.GroupService;
import org.dspace.qaevent.service.QAEventService;
import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO;
import org.dspace.qaevent.service.dto.QAMessageDTO;
import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -33,14 +39,21 @@
*/
public class WithdrawnCorrectionType implements CorrectionType, InitializingBean {

public static final String WITHDRAWAL_REINSTATE_GROUP = "withdrawal.reinstate.group";

private String id;
private String topic;
private String creationForm;

@Autowired
private GroupService groupService;
@Autowired
private QAEventService qaEventService;
@Autowired
private AuthorizeService authorizeService;
@Autowired
private ConfigurationService configurationService;


@Override
public boolean isAllowed(Context context, Item targetItem) throws SQLException {
Expand All @@ -52,10 +65,23 @@ public boolean isAllowed(Context context, Item targetItem) throws SQLException {
} catch (AuthorizeException e) {
return false;
}
boolean isAdmin = authorizeService.isAdmin(context);
if (!currentUserIsMemberOfwithdrawalReinstateGroup(context) && !isAdmin) {
return false;
}
long tot = qaEventService.countSourcesByTarget(context, targetItem.getID());
return tot == 0;
}

private boolean currentUserIsMemberOfwithdrawalReinstateGroup(Context context) throws SQLException {
String withdrawalReinstateGroupUUID = configurationService.getProperty(WITHDRAWAL_REINSTATE_GROUP);
if (StringUtils.isBlank(withdrawalReinstateGroupUUID)) {
return false;
}
Group withdrawalReinstateGroup = groupService.find(context, UUID.fromString(withdrawalReinstateGroupUUID));
return Objects.nonNull(withdrawalReinstateGroup) && groupService.isMember(context, withdrawalReinstateGroup);
}

@Override
public QAEvent createCorrection(Context context, Item targetItem, QAMessageDTO reason) {
CorrectionTypeMessageDTO mesasge = (CorrectionTypeMessageDTO) reason;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -41,6 +42,8 @@
import org.dspace.content.QAEvent;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.dspace.core.Email;
import org.dspace.core.I18nUtil;
import org.dspace.eperson.EPerson;
import org.dspace.qaevent.QASource;
import org.dspace.qaevent.QATopic;
Expand All @@ -50,6 +53,8 @@
import org.dspace.qaevent.service.QAEventService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
Expand All @@ -63,6 +68,8 @@
*/
public class QAEventServiceImpl implements QAEventService {

private static final Logger log = LoggerFactory.getLogger(QAEventServiceImpl.class);

@Autowired(required = true)
protected ConfigurationService configurationService;

Expand Down Expand Up @@ -306,12 +313,27 @@ public void store(Context context, QAEvent dto) {
updateRequest.process(getSolr());

getSolr().commit();
sentEmailToAdminAboutNewRequest(dto);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public void sentEmailToAdminAboutNewRequest(QAEvent qaEvent) {
try {
Email email = Email.getEmail(I18nUtil.getEmailFilename(Locale.getDefault(), "qaevent_admin_notification"));
email.addRecipient(configurationService.getProperty("mail.admin"));
email.addArgument(qaEvent.getTopic());
email.addArgument(qaEvent.getTarget());
email.addArgument(qaEvent.getMessage());
email.send();
} catch (Exception e) {
log.warn("Error during sending email of Withdrawn/Reinstate request for item with uuid:"
+ qaEvent.getTarget(), e);
}
}

@Override
public QAEvent findEventByEventId(Context context, String eventId) {
SolrQuery solrQuery = new SolrQuery("*:*");
Expand Down
6 changes: 6 additions & 0 deletions dspace/config/dspace.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,12 @@ org.dspace.app.itemexport.life.span.hours = 48
# cumulative sizes are more than this entry the export is not kicked off
org.dspace.app.itemexport.max.size = 200

### Withdrawal&Reinstate correction Group ###
# Members of this group enabled to make requests for the Withdrawn or Reinstate of an item.
# By defaul this property is empty, so in the default behaviour no one will see the button to make these requests.
# If you want to give consent to everyone, just configure the uuid of the Anonymous group.
withdrawal.reinstate.group =

### Batch Item import settings ###
# The directory where the results of imports will be placed (mapfile, upload file)
org.dspace.app.batchitemimport.work.dir = ${dspace.dir}/imports
Expand Down
13 changes: 13 additions & 0 deletions dspace/config/emails/qaevent_admin_notification
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## E-mail sent to notify Administrator of new Withdrawn/Reinstate request
##
## Parameters: {0} Type of request 'topic'
## {1} resource id
## {2} reason
##
#set($subject = "Notification about ${params[0]} Request")

Item Details:

Type of request: ${params[0]}
Relatem to item with uuid: ${params[1]}
Reason: ${params[2]}

0 comments on commit 7f32714

Please sign in to comment.