Skip to content
Snippets Groups Projects
Commit 51f9417c authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Delete account endpoint

parent 3e310add
No related branches found
No related tags found
No related merge requests found
...@@ -322,8 +322,6 @@ public class UserBean { ...@@ -322,8 +322,6 @@ public class UserBean {
// Summaries // Summaries
deleteForecastSummary.setParameter("forecastConfigurationId", forecastConfiguration.getForecastConfigurationId()).executeUpdate(); deleteForecastSummary.setParameter("forecastConfigurationId", forecastConfiguration.getForecastConfigurationId()).executeUpdate();
System.out.println("forecastConfiguration " + forecastConfiguration.getForecastConfigurationId() + " should be removed now");
// Configurations // Configurations
em.remove(forecastConfiguration); em.remove(forecastConfiguration);
...@@ -383,9 +381,6 @@ public class UserBean { ...@@ -383,9 +381,6 @@ public class UserBean {
obs.setLastEditedBy(archiveUser.getUserId()); obs.setLastEditedBy(archiveUser.getUserId());
} }
// Messages // Messages
for(MessageLocale ml:userResources.getMessageLocales()) for(MessageLocale ml:userResources.getMessageLocales())
{ {
......
...@@ -1455,6 +1455,53 @@ public class LogicService { ...@@ -1455,6 +1455,53 @@ public class LogicService {
return Response.status(Status.BAD_REQUEST).entity("INPUT ERROR: " + ex.getMessage()).build(); return Response.status(Status.BAD_REQUEST).entity("INPUT ERROR: " + ex.getMessage()).build();
} }
} }
/**
* Allows a user to delete their account
* @param keepData if true, move all data to default user.
* @return
*/
@DELETE
@Path("user/deleteme")
public Response deleteMe(@QueryParam("keepData") Boolean keepData) {
// Authentication
// Either valid UUID or session
VipsLogicUser user = userBean.getUserFromUUID(httpServletRequest);
if(user == null)
{
user = (VipsLogicUser) httpServletRequest.getSession().getAttribute("user");
}
if(user == null)
{
return Response.status(Status.UNAUTHORIZED).entity("You are not authorized to perform this operation").build();
}
// If it's an archive user, do NOT delete it!
if(user.getOrganizationId().getArchiveUser() != null && user.getOrganizationId().getArchiveUser().getUserId().equals(user.getUserId()))
{
return Response.status(Status.BAD_REQUEST).entity("User is an archive user for organization " + user.getOrganizationId().getOrganizationName() + ". Can't delete it").build();
}
try {
if (keepData != null && keepData) {
// Get default user for organization
VipsLogicUser archiveUser = user.getOrganizationId().getArchiveUser();
if (archiveUser == null) {
return Response.status(Status.BAD_REQUEST).entity("Your organization " + user.getOrganizationId().getOrganizationName() + " has not defined a default user for archiving your data. Please contact your systems administrator to fix this.").build();
}
userBean.transferUserResources(user, archiveUser);
} else {
userBean.deleteUserResources(user);
}
// Delete the user
userBean.deleteUser(user);
return Response.status(Status.NO_CONTENT).build();
}
catch(DeleteUserException ex)
{
return Response.serverError().entity(ex.getMessage()).build();
}
}
/** /**
* Get the client to use for calling VIPSCoreManager REST services programmatically * Get the client to use for calling VIPSCoreManager REST services programmatically
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment