Skip to content

Commit

Permalink
#1213 Only delete user when they are not owner of collections or items
Browse files Browse the repository at this point in the history
  • Loading branch information
haarli committed May 9, 2022
1 parent 23e2525 commit ece7b6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,9 @@ public static final String getItemsWithoutLicenseInCollectionAndSubCollections(U
+ "FILTER NOT EXISTS {?s <http://imeji.org/terms/license> ?license}}";
return sparqlQuery;
}


public static final String selectCreatorOrModifiedBy(String userUri) {
return "SELECT ?s WHERE { ?s <" + ImejiNamespaces.CREATOR + ">|<" + ImejiNamespaces.MODIFIED_BY + "> <" + userUri + ">}";
}
}
12 changes: 8 additions & 4 deletions src/main/java/de/mpg/imeji/logic/security/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/Users.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
</div>
</ui:fragment>
<ui:fragment rendered="#{UsersBean.group != null}">
Expand Down

0 comments on commit ece7b6a

Please sign in to comment.