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

changing owner of data overlay should change order index

parent 2639f6f3
Pipeline #13954 passed with stage
in 11 minutes and 35 seconds
minerva (14.0.0~beta.2) unstable; urgency=low
* Small improvement: info window contains information about overlay No (#919)
* Bug fix: exported SBML passes online validation (#831)
* Bug fix: changing owner of data overlay should change order index (#945)
* Bug fix: allow user to remove own comments (#931)
* Bug fix: validation of project name length is provided (#950)
* Bug fix: after reducing privileges on himself interface is refreshed (#948)
......
......@@ -181,6 +181,7 @@ public class OverlayRestImpl extends BaseRestImpl {
if (overlayData == null) {
throw new QueryException("overlay field cannot be undefined");
}
List<User> reorderUsers = new ArrayList<>();
try {
Layout layout = getOverlay(projectId, overlayId);
for (String key : overlayData.keySet()) {
......@@ -202,8 +203,17 @@ public class OverlayRestImpl extends BaseRestImpl {
layout.setGoogleLicenseConsent((Boolean) overlayData.get("googleLicenseConsent"));
} else if (key.equalsIgnoreCase("creator")) {
if ("".equals(value)) {
if (layout.getCreator() != null) {
reorderUsers.add(layout.getCreator());
}
layout.setCreator(null);
} else {
if (layout.getCreator() == null) {
reorderUsers.add(getUserService().getUserByLogin((String) value));
} else if (!layout.getCreator().getLogin().equals(value)) {
reorderUsers.add(getUserService().getUserByLogin((String) value));
reorderUsers.add(layout.getCreator());
}
layout.setCreator(getUserService().getUserByLogin((String) value));
}
} else {
......@@ -211,6 +221,9 @@ public class OverlayRestImpl extends BaseRestImpl {
}
}
layoutDao.update(layout);
for (User user : reorderUsers) {
reorderOverlays(user, layout.getProject());
}
return getOverlayById(layout.getProject().getProjectId(), overlayId);
} catch (NumberFormatException e) {
throw new QueryException("invliad overlay id", e);
......@@ -231,7 +244,12 @@ public class OverlayRestImpl extends BaseRestImpl {
User owner = layout.getCreator();
Project project = layout.getProject();
layoutService.removeLayout(layout, null);
reorderOverlays(owner, project);
return okStatus();
}
private void reorderOverlays(User owner, Project project) {
List<Layout> overlays = layoutService.getLayoutsByProject(project).stream()
.filter(lay -> lay.getCreator() == owner).collect(Collectors.toList());
......@@ -243,7 +261,6 @@ public class OverlayRestImpl extends BaseRestImpl {
layoutService.updateLayout(overlay);
}
}
return okStatus();
}
public Map<String, Object> addOverlay(String projectId, String name, String description, String content,
......
package lcsb.mapviewer.web;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
......@@ -101,7 +102,7 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
@Test
public void testListPublicOverlaysOverlaysWhenCreatorEmpty() throws Exception {
Layout layout= createOverlay(project, null);
Layout layout = createOverlay(project, null);
layout.setPublicLayout(true);
layoutDao.add(layout);
......@@ -122,7 +123,7 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
@Test
public void testListNonPublicOverlaysOverlaysWhenCreatorEmpty() throws Exception {
Layout layout= createOverlay(project, null);
Layout layout = createOverlay(project, null);
layout.setPublicLayout(true);
layoutDao.add(layout);
......@@ -1169,7 +1170,7 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
overlay2.setOrderIndex(2);
Layout overlay3 = createOverlay(user);
overlay3.setOrderIndex(3);
layoutDao.update(overlay1);
layoutDao.update(overlay2);
layoutDao.update(overlay3);
......@@ -1194,7 +1195,7 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
overlay2.setOrderIndex(2);
Layout overlay3 = createOverlay(null);
overlay3.setOrderIndex(3);
layoutDao.update(overlay1);
layoutDao.update(overlay2);
layoutDao.update(overlay3);
......@@ -1211,5 +1212,38 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
assertEquals(2, overlay3.getOrderIndex());
}
@Test
public void testChangeOrderAfterChaningOwner() throws Exception {
User user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD);
User admin = userService.getUserByLogin(BUILT_IN_TEST_ADMIN_LOGIN);
Layout overlay1 = createOverlay(user);
overlay1.setOrderIndex(1);
Layout overlay2 = createOverlay(user);
overlay2.setOrderIndex(2);
Layout overlay3 = createOverlay(admin);
overlay3.setOrderIndex(1);
Layout overlay4 = createOverlay(admin);
overlay4.setOrderIndex(2);
String body = "{\"overlay\":{\"creator\":\"" + admin.getLogin() + "\"}}";
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = patch("/projects/" + TEST_PROJECT + "/overlays/" + overlay1.getId())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
assertEquals("Order of overlays wasn't updated for original owner of overlay", 1, overlay2.getOrderIndex());
assertTrue(overlay1.getOrderIndex() == 1 || overlay3.getOrderIndex() == 1);
assertTrue(overlay1.getOrderIndex() == 2 || overlay3.getOrderIndex() == 2);
assertEquals(3, overlay4.getOrderIndex());
}
}
Markdown is supported
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