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