Commit b6bc3ffa authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1301-overlays-not-removed-when-user-deleted' into 'devel_15.0.x'

removing user removes also data overlays

See merge request !1210
parents 7f1ab133 4b525d0a
Pipeline #29131 passed with stage
in 13 minutes and 7 seconds
......@@ -8,6 +8,7 @@ minerva (15.0.2) stable; urgency=medium
additional reactant/product (#1303)
* Bug fix: coordinates of children in compact complexes in CellDesigner were
wrong (#1304)
* Bug fix: user data overlays were not removed when user was deleted (#1301)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 29 Jun 2020 11:00:00 +0200
......
......@@ -6,6 +6,7 @@ import org.springframework.stereotype.Repository;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.BaseDao;
@Repository
......@@ -33,4 +34,12 @@ public class LayoutDao extends BaseDao<Layout> {
}
return null;
}
public List<Layout> getLayoutsByUser(User user) {
List<Layout> layouts = getElementsByParameter("creator_id", user.getId());
for (Layout layout : layouts) {
refresh(layout);
}
return layouts;
}
}
......@@ -103,7 +103,7 @@ public class UserController extends BaseController {
@PreAuthorize("hasAuthority('IS_ADMIN')")
@DeleteMapping(value = "/{login:.+}")
public Map<String, Object> removeUser(@PathVariable(value = "login") String login) throws QueryException {
public Map<String, Object> removeUser(@PathVariable(value = "login") String login) throws Exception {
return userRest.removeUser(login);
}
......
package lcsb.mapviewer.api.users;
import java.io.IOException;
import java.util.*;
import org.apache.logging.log4j.LogManager;
......@@ -17,10 +18,12 @@ import lcsb.mapviewer.api.*;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.security.Privilege;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.*;
import lcsb.mapviewer.model.user.annotator.*;
import lcsb.mapviewer.services.interfaces.ILayoutService;
@Transactional
@Service
......@@ -32,10 +35,12 @@ public class UserRestImpl extends BaseRestImpl {
@SuppressWarnings("unused")
private Logger logger = LogManager.getLogger(UserRestImpl.class);
private PasswordEncoder passwordEncoder;
private ILayoutService overlayService;
@Autowired
public UserRestImpl(PasswordEncoder passwordEncoder) {
public UserRestImpl(PasswordEncoder passwordEncoder, ILayoutService overlayService) {
this.passwordEncoder = passwordEncoder;
this.overlayService = overlayService;
}
public Map<String, Object> getUser(String login, String columns)
......@@ -720,13 +725,17 @@ public class UserRestImpl extends BaseRestImpl {
return getUser(login, "");
}
public Map<String, Object> removeUser(String login) throws QueryException {
public Map<String, Object> removeUser(String login) throws QueryException, IOException {
User user = getUserService().getUserByLogin(login);
if (user == null) {
throw new ObjectNotFoundException("user doesn't exists");
} else if (user.getLogin().equals(Configuration.ANONYMOUS_LOGIN)) {
throw new OperationNotAllowedException("guest account cannot be removed");
}
List<Layout> overlays = overlayService.getLayoutsByUser(user);
for (Layout layout : overlays) {
overlayService.removeLayout(layout, null);
}
getUserService().deleteUser(user);
return okStatus();
}
......
......@@ -840,4 +840,9 @@ public class LayoutService implements ILayoutService {
}
return result;
}
@Override
public List<Layout> getLayoutsByUser(User user) {
return layoutDao.getLayoutsByUser(user);
}
}
......@@ -425,4 +425,6 @@ public interface ILayoutService {
}
}
List<Layout> getLayoutsByUser(User user);
}
......@@ -30,6 +30,7 @@ import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.persist.dao.map.LayoutDao;
import lcsb.mapviewer.services.interfaces.IConfigurationService;
import lcsb.mapviewer.services.interfaces.IUserService;
......@@ -56,6 +57,9 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
@Autowired
private ProjectDao projectDao;
@Autowired
private LayoutDao layoutDao;
@Before
public void setup() {
user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD);
......@@ -438,4 +442,23 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
.andExpect(status().isForbidden());
}
@Test
public void removeUserWithLayouts() throws Exception {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
Project project = new Project("test_project");
project.setOwner(userService.getUserByLogin(BUILT_IN_TEST_ADMIN_LOGIN));
projectDao.add(project);
createOverlay(project, user);
RequestBuilder request = delete("/users/" + user.getLogin())
.session(session);
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
assertEquals(0, layoutDao.getLayoutsByProject(project).size());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment