mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Community request: fake EPerson from configuration.
This commit is contained in:
@@ -102,10 +102,15 @@ public class XmlWorkflowCuratorServiceImpl
|
||||
Curator curator = new Curator();
|
||||
curator.setReporter(reporter);
|
||||
c.turnOffAuthorisationSystem();
|
||||
boolean wasAnonymous = false;
|
||||
if (null == c.getCurrentUser()) { // We need someone to email
|
||||
c.setCurrentUser(ePersonService.findAnAdministrator(c));
|
||||
wasAnonymous = true;
|
||||
c.setCurrentUser(ePersonService.getSystemEPerson(c));
|
||||
}
|
||||
boolean failedP = curate(curator, c, wfi);
|
||||
if (wasAnonymous) {
|
||||
c.setCurrentUser(null);
|
||||
}
|
||||
c.restoreAuthSystemState();
|
||||
return failedP;
|
||||
}
|
||||
|
@@ -116,19 +116,28 @@ public class EPersonServiceImpl extends DSpaceObjectServiceImpl<EPerson> impleme
|
||||
return ePersonDAO.findByID(context, EPerson.class, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fake EPerson which can receive email. Its address will be the
|
||||
* value of "mail.admin", or "postmaster" if all else fails.
|
||||
* @param c
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
@Override
|
||||
public EPerson findAnAdministrator(Context c)
|
||||
public EPerson getSystemEPerson(Context c)
|
||||
throws SQLException {
|
||||
List<EPerson> contacts = groupService.findByName(c, Group.ADMIN).getMembers();
|
||||
EPerson currentUser;
|
||||
if (contacts.isEmpty()) {
|
||||
log.warn("Administrators group is empty");
|
||||
currentUser = findByEmail(c, configurationService.getProperty("mail.admin"));
|
||||
// Null if no such EPerson
|
||||
} else {
|
||||
currentUser = contacts.get(0);
|
||||
String adminEmail = configurationService.getProperty("mail.admin");
|
||||
if (null == adminEmail) {
|
||||
adminEmail = "postmaster"; // Last-ditch attempt to send *somewhere*
|
||||
}
|
||||
return currentUser;
|
||||
EPerson systemEPerson = findByEmail(c, adminEmail);
|
||||
|
||||
if (null == systemEPerson) {
|
||||
systemEPerson = new EPerson();
|
||||
systemEPerson.setEmail(adminEmail);
|
||||
}
|
||||
|
||||
return systemEPerson;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -13,6 +13,7 @@ import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Item;
|
||||
@@ -158,15 +159,16 @@ public interface EPersonService extends DSpaceObjectService<EPerson>, DSpaceObje
|
||||
throws SQLException;
|
||||
|
||||
/**
|
||||
* Try very hard to find an administrator's account. Might return a member
|
||||
* of the Administrators group, or an account with a configured email
|
||||
* address.
|
||||
* The "System EPerson" is a fake account that exists only to receive email.
|
||||
* It has an email address that should be presumed usable. It does not
|
||||
* exist in the database and is not complete.
|
||||
*
|
||||
* @param context current DSpace session.
|
||||
* @return a presumed administrator account, or null if none could be found.
|
||||
* @return an EPerson that can presumably receive email.
|
||||
* @throws SQLException
|
||||
*/
|
||||
public EPerson findAnAdministrator(Context context)
|
||||
@NotNull
|
||||
public EPerson getSystemEPerson(Context context)
|
||||
throws SQLException;
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user