diff --git a/src/main/java/de/mpg/imeji/logic/search/jenasearch/JenaCustomQueries.java b/src/main/java/de/mpg/imeji/logic/search/jenasearch/JenaCustomQueries.java index e03b2aeb3..f1b23534c 100644 --- a/src/main/java/de/mpg/imeji/logic/search/jenasearch/JenaCustomQueries.java +++ b/src/main/java/de/mpg/imeji/logic/search/jenasearch/JenaCustomQueries.java @@ -702,4 +702,9 @@ public static final String getItemsWithoutLicenseInCollectionAndSubCollections(U + "FILTER NOT EXISTS {?s ?license}}"; return sparqlQuery; } + + + public static final String selectCreatorOrModifiedBy(String userUri) { + return "SELECT ?s WHERE { ?s <" + ImejiNamespaces.CREATOR + ">|<" + ImejiNamespaces.MODIFIED_BY + "> <" + userUri + ">}"; + } } diff --git a/src/main/java/de/mpg/imeji/logic/security/user/UserService.java b/src/main/java/de/mpg/imeji/logic/security/user/UserService.java index 4ead12e2e..8d7d2fcdf 100644 --- a/src/main/java/de/mpg/imeji/logic/security/user/UserService.java +++ b/src/main/java/de/mpg/imeji/logic/security/user/UserService.java @@ -10,15 +10,12 @@ import java.util.Map; import java.lang.reflect.Field; +import de.mpg.imeji.exceptions.*; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; import org.jose4j.lang.JoseException; -import de.mpg.imeji.exceptions.ImejiException; -import de.mpg.imeji.exceptions.NotFoundException; -import de.mpg.imeji.exceptions.QuotaExceededException; -import de.mpg.imeji.exceptions.UnprocessableError; import de.mpg.imeji.logic.config.Imeji; import de.mpg.imeji.logic.db.reader.ReaderFacade; import de.mpg.imeji.logic.model.CollectionImeji; @@ -128,6 +125,13 @@ public User create(User u, USER_TYPE type) throws ImejiException { * @throws ImejiException */ public void delete(User user) throws ImejiException { + final Search search = SearchFactory.create(); // default is JENA + final List results = search.searchString(JenaCustomQueries.selectCreatorOrModifiedBy(user.getId().toString()), null, null, + Search.SEARCH_FROM_START_INDEX, Search.GET_ALL_RESULTS).getResults(); + if (results != null && results.size() > 0) { + throw new WorkflowException("User cannot be deleted, as they own or modified collections", + "User cannot be deleted, as they own or modified collections"); + } controller.delete(user); } diff --git a/src/main/webapp/Users.xhtml b/src/main/webapp/Users.xhtml index 60ca8bc88..83f00283a 100644 --- a/src/main/webapp/Users.xhtml +++ b/src/main/webapp/Users.xhtml @@ -102,7 +102,8 @@ confirmationText="#{msg.confirmation_delete_user}: #{user.person.completeName} (#{user.email})?" submitLabel="#{lbl.user_admin_delete}" dialogId="deleteUser#{row.index}" identifierName="email" - identifierValue="#{user.email}" /> + identifierValue="#{user.email}" + reRender=":imj_pageMessageArea"/>