Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@ public void delete(Context context, EPerson ePerson, boolean cascade)
throw new AuthorizeException(
"You must be an admin to delete an EPerson");
}
// Admin cannot delete himself/herself
if (!context.ignoreAuthorization()) {
EPerson currentUser = context.getCurrentUser();
if (currentUser != null && ePerson.getID().equals(currentUser.getID())) {
throw new IllegalStateException(
"You, as admin user, cannot delete yourself");
}
}
// Get all workflow-related groups that the current EPerson belongs to
Set<Group> workFlowGroups = getAllWorkFlowGroups(context, ePerson);
for (Group group: workFlowGroups) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ protected void delete(Context context, UUID id) throws AuthorizeException {
} catch (EmptyWorkflowGroupException e) {
throw new RESTEmptyWorkflowGroupException(e);
} catch (IllegalStateException e) {
throw new UnprocessableEntityException(e.getMessage(), e);
throw new DSpaceBadRequestException(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,20 @@ public void deleteForbidden() throws Exception {
.andExpect(status().isOk());
}

@Test
public void deleteYourselfForbidden() throws Exception {
// login as admin
String adminToken = getAuthToken(admin.getEmail(), password);

// Deleting yourself is forbidden
getClient(adminToken).perform(delete("/api/eperson/epersons/" + admin.getID()))
.andExpect(status().isBadRequest());

// Verify the admin is still here
getClient(adminToken).perform(get("/api/eperson/epersons/" + admin.getID()))
.andExpect(status().isOk());
}

@Test
public void deleteViolatingWorkFlowConstraints() throws Exception {
// We turn off the authorization system in order to create the structure as defined below
Expand Down
Loading