Commit 8611235f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'devel_12.1.x' into HEAD

parents c38115bf 34fbf66d
......@@ -7,6 +7,20 @@ minerva (12.2.0~alpha.0) stable; urgency=medium
highligh
minerva (12.1.4) stable; urgency=medium
* Bug fix: no check for limit on custom data overlays fixed
* Bug fix: error message improved when there is privilege problem during
data overlay upload
* Bug fix: upload of data overlay from admin panel didn't work
* Bug fix: add project button is disabled when user doesn't have proper
privileges ("Add project" privilege)
* Bug fix: there are no more extra markers due to map wrapping
* Bug fix: upload of the project failed when another project was removed
during upload
* Bug fix: word wrapping fixed in overlay table for long overlay names
-- Piotr Gawron <piotr.gawron@uni.lu> Fri, 28 Dec 2018 14:00:00 +0200
minerva (12.1.3) stable; urgency=medium
* Bug fix: add project button is disabled when user has no privileges
* Bug fix: projectId was missing in the edit window
......
......@@ -926,6 +926,10 @@ https://www.w3schools.com/css/tryit.asp?filename=trycss_tooltip
overflow-x: hidden;
}
.minerva-overlay-panel td, .minerva-overlay-panel th {
word-break: break-word;
}
.minerva-search-data-hidden {
display: none;
}
......
......@@ -2165,7 +2165,7 @@ ServerConnector.addOverlay = function (params) {
return self.sendPostRequest(self.addOverlayUrl(queryParams), data);
}).then(function (content) {
return new DataOverlay(JSON.parse(content));
});
}).catch(self.processNetworkError);
};
/**
......
......@@ -7,6 +7,7 @@ var GuiConnector = require('../GuiConnector');
var GuiUtils = require('./leftPanel/GuiUtils');
var DataOverlay = require('../map/data/DataOverlay');
var NetworkError = require('../NetworkError');
var SecurityError = require('../SecurityError');
var OverlayParser = require('../map/OverlayParser');
......@@ -295,6 +296,8 @@ AddOverlayDialog.prototype.open = function () {
if (error instanceof NetworkError && error.statusCode === HttpStatus.BAD_REQUEST) {
var errorMessage = JSON.parse(error.content);
GuiConnector.alert("Problematic input: <br/>" + errorMessage.reason);
} else if (error instanceof SecurityError) {
GuiConnector.alert("You cannot add more overlays");
} else {
GuiConnector.alert(error);
}
......
......@@ -1033,7 +1033,7 @@ EditProjectDialog.prototype.removeOverlay = function (overlayId) {
/**
*
* @returns {Promise}
* @returns {Promise<AddOverlayDialog>}
*/
EditProjectDialog.prototype.openAddOverlayDialog = function () {
var self = this;
......@@ -1044,13 +1044,16 @@ EditProjectDialog.prototype.openAddOverlayDialog = function () {
project: self.getProject(),
customMap: null,
element: document.createElement("div"),
configuration: self.getConfiguration()
configuration: self.getConfiguration(),
serverConnector: self.getServerConnector()
});
self._addOverlayDialog.addListener("onAddOverlay", function () {
return self.refreshOverlays();
});
return self._addOverlayDialog.init().then(function () {
return self._addOverlayDialog.open();
}).then(function(){
return self._addOverlayDialog;
});
};
......
......@@ -191,7 +191,7 @@ MapsAdminPanel.prototype.init = function () {
return self.getServerConnector().getLoggedUser();
}).then(function (user) {
var configuration = self.getConfiguration();
var canAddProject = user.hasPrivilege(configuration.getPrivilegeType(PrivilegeType.PROJECT_MANAGEMENT));
var canAddProject = user.hasPrivilege(configuration.getPrivilegeType(PrivilegeType.ADD_MAP));
$("[name='addProject']", self.getElement()).attr("disabled", !canAddProject);
});
};
......
......@@ -26,24 +26,28 @@ function OpenLayerCanvas(element, options) {
self._markerLayer = new ol.layer.Vector({
source: new ol.source.Vector({
wrapX: false,
features: []
})
});
self._rectangleLayer = new ol.layer.Vector({
source: new ol.source.Vector({
wrapX: false,
features: []
})
});
self._polylineLayer = new ol.layer.Vector({
source: new ol.source.Vector({
wrapX: false,
features: []
})
});
self._drawingLayer = new ol.layer.Vector({
source: new ol.source.Vector({
wrapX: false,
features: []
}),
style: new ol.style.Style({
......
......@@ -34,6 +34,7 @@ PrivilegeType.CONFIGURATION_MANAGE = 'CONFIGURATION_MANAGE';
PrivilegeType.MANAGE_GENOMES = 'MANAGE_GENOMES';
PrivilegeType.MANAGE_PLUGINS = 'MANAGE_PLUGINS';
PrivilegeType.PROJECT_MANAGEMENT = 'PROJECT_MANAGEMENT';
PrivilegeType.ADD_MAP = 'ADD_MAP';
PrivilegeType.USER_MANAGEMENT = 'USER_MANAGEMENT';
/**
......
......@@ -122,8 +122,11 @@ describe('EditProjectDialog', function () {
return createDialog().then(function (result) {
dialog = result;
return dialog.openAddOverlayDialog();
}).then(function (overlayDialog) {
overlayDialog.setFileContent("X");
return $("button:contains('UPLOAD')").click();
}).then(function () {
dialog.destroy();
return dialog.destroy();
});
});
......
......@@ -13,6 +13,10 @@ import lcsb.mapviewer.api.RestTestFunctions;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.layout.ColorSchemaType;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.user.ObjectPrivilege;
import lcsb.mapviewer.model.user.Privilege;
import lcsb.mapviewer.model.user.PrivilegeType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.services.interfaces.IProjectService;
......@@ -32,7 +36,11 @@ public class OverlayRestImplTest extends RestTestFunctions {
@Test
public void testAddDataOverlay() throws Exception {
try {
createProject("testFiles/model/sample.xml", projectId);
User admin = userService.getUserByLogin("admin");
Project project = createProject("testFiles/model/sample.xml", projectId);
userService.setUserPrivilege(admin, new Privilege(100, PrivilegeType.CUSTOM_LAYOUTS, admin));
userService.setUserPrivilege(admin, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, admin));
Map<String, Object> result = overlayRest.addOverlay(adminToken, projectId, "x", "desc", "s1", null, null,
ColorSchemaType.GENERIC.name(), "true");
Gson gson = new Gson();
......@@ -45,11 +53,12 @@ public class OverlayRestImplTest extends RestTestFunctions {
}
}
private void createProject(String string, String projectId) throws Exception {
private Project createProject(String string, String projectId) throws Exception {
Project project = new Project(projectId);
Model model = super.getModelForFile(string, false);
project.addModel(model);
projectDao.add(project);
return project;
}
}
......@@ -120,9 +120,9 @@ public class LayoutService implements ILayoutService {
}
@Override
public boolean userCanAddLayout(Model model, User user) {
public boolean userCanAddLayout(Project project, User user) {
// if we don't have privileges to view the object then we cannot add layouts
if (!userService.userHasPrivilege(user, PrivilegeType.VIEW_PROJECT, model.getProject())) {
if (!userService.userHasPrivilege(user, PrivilegeType.VIEW_PROJECT, project)) {
return false;
}
long count = getAvailableCustomLayoutsNumber(user);
......@@ -394,7 +394,11 @@ public class LayoutService implements ILayoutService {
}
@Override
public Layout createLayout(final CreateLayoutParams params) throws IOException, InvalidColorSchemaException {
public Layout createLayout(final CreateLayoutParams params)
throws IOException, InvalidColorSchemaException, SecurityException {
if (!userCanAddLayout(params.getProject(), params.getUser())) {
throw new SecurityException("You cannot add more overlays");
}
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> parameters = TextFileUtils.getHeaderParametersFromFile(params.getColorInputStream());
if (parameters.get(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE) == null && params.getColorSchemaType() != null) {
......
......@@ -754,6 +754,7 @@ public class ProjectService implements IProjectService {
UploadedFileEntry file = params.getProjectFile();
project.setInputData(file);
addUsers(project, params);
createModel(params, project);
Model originalModel = project.getModels().iterator().next().getModel();
......@@ -764,7 +765,6 @@ public class ProjectService implements IProjectService {
.execute();
}
addUsers(project, params);
createImages(project, params);
for (Layout layout : project.getLayouts()) {
......
......@@ -309,14 +309,14 @@ public interface ILayoutService {
/**
* Returns true if user can add layout to the model.
*
* @param model
* to which model user wants to add layout
* @param project
* to which project user wants to add layout
* @param user
* who wants to add layout
* @return <code>true</code> if user can add layout, <code>false</code>
* otherwise
*/
boolean userCanAddLayout(Model model, User user);
boolean userCanAddLayout(Project project, User user);
/**
* Returns true if user can remove layout from the model.
......@@ -380,9 +380,10 @@ public interface ILayoutService {
* thrown when there are problems with files
* @throws InvalidColorSchemaException
* if the coloring source is invalid
* @throws SecurityException
* @throws CommandExecutionException
*/
Layout createLayout(CreateLayoutParams params) throws IOException, InvalidColorSchemaException;
Layout createLayout(CreateLayoutParams params) throws IOException, InvalidColorSchemaException, SecurityException;
/**
* Create layout based on the data in the parameter. Layout will contain set of
......
......@@ -130,14 +130,14 @@ public class LayoutServiceTest extends ServiceTestFunctions {
public void testUserCanAddLayout() throws Exception {
try {
int initialSize = project.getLayouts().size();
assertFalse(layoutService.userCanAddLayout(model, user));
assertFalse(layoutService.userCanAddLayout(project, user));
userService.setUserPrivilege(user, new Privilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
assertFalse(layoutService.userCanAddLayout(model, user));
assertFalse(layoutService.userCanAddLayout(project, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
assertTrue(layoutService.userCanAddLayout(model, user));
assertTrue(layoutService.userCanAddLayout(project, user));
CreateLayoutParams params = new CreateLayoutParams().name("Test").
directory("testDir").
......@@ -146,15 +146,15 @@ public class LayoutServiceTest extends ServiceTestFunctions {
user(user);
Layout row = layoutService.createLayout(params);
assertFalse(layoutService.userCanAddLayout(model, user));
assertFalse(layoutService.userCanAddLayout(project, user));
userService.setUserPrivilege(user, new Privilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
assertFalse(layoutService.userCanAddLayout(model, user));
assertFalse(layoutService.userCanAddLayout(project, user));
userService.setUserPrivilege(user, new Privilege(2, PrivilegeType.CUSTOM_LAYOUTS, user));
assertTrue(layoutService.userCanAddLayout(model, user));
assertTrue(layoutService.userCanAddLayout(project, user));
assertTrue(layoutService.userCanRemoveLayout(row, user));
......@@ -172,6 +172,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
public void testGetAvailable() throws Exception {
try {
userService.setUserPrivilege(user, new Privilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
assertEquals(1, layoutService.getAvailableCustomLayoutsNumber(user));
CreateLayoutParams params = new CreateLayoutParams().name("Test").
......@@ -201,6 +202,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
assertEquals(0, layouts.size());
userService.setUserPrivilege(user, new Privilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
CreateLayoutParams params = new CreateLayoutParams().name("Test").
directory("testDir").
......@@ -235,6 +237,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
assertEquals(0, layouts.size());
userService.setUserPrivilege(user, new Privilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
CreateLayoutParams params = new CreateLayoutParams().name("Test").
directory("testDir").
......@@ -271,6 +274,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
assertEquals(0, layouts.size());
userService.setUserPrivilege(user, new Privilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
CreateLayoutParams params = new CreateLayoutParams().name("Test").
directory("testDir").
project(project).
......@@ -371,6 +375,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
assertEquals(0, layouts.size());
userService.setUserPrivilege(user, new Privilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
CreateLayoutParams params = new CreateLayoutParams().name("Test").
directory("testDir").
project(project).
......@@ -404,6 +409,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
assertEquals(0, layouts.size());
userService.setUserPrivilege(user, new Privilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
ByteArrayInputStream bais = new ByteArrayInputStream(
"name reactionIdentifier Color\ns1 #CC0000\ns2 #CCCC00\n re1 #CCCC00\n"
.getBytes(StandardCharsets.UTF_8));
......@@ -503,6 +509,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
try {
String layoutId = "Test";
userService.setUserPrivilege(user, new Privilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
CreateLayoutParams params = new CreateLayoutParams().name(layoutId).
directory("testDir").
project(project).
......@@ -526,6 +533,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
try {
String layoutId = "Test";
userService.setUserPrivilege(user, new Privilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
CreateLayoutParams params = new CreateLayoutParams().name(layoutId).
directory("testDir").
project(project).
......
......@@ -59,6 +59,7 @@ import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.model.user.ConfigurationOption;
import lcsb.mapviewer.model.user.ObjectPrivilege;
import lcsb.mapviewer.model.user.PrivilegeType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.model.user.UserAnnotationSchema;
......@@ -114,7 +115,7 @@ public class ProjectServiceTest extends ServiceTestFunctions {
}
@Test
public void test() throws Exception {
public void testGetAllProjects() throws Exception {
try {
List<Project> projects = projectService.getAllProjects(adminToken);
......@@ -146,6 +147,73 @@ public class ProjectServiceTest extends ServiceTestFunctions {
}
}
@Test
public void testUserPrivilegeChangeDuringUpload() throws Exception {
try {
User admin = userService.getUserByToken(adminToken);
Project defaultProject = projectService.getAllProjects().get(0);
userService.setUserPrivilege(admin,
new ObjectPrivilege(defaultProject, 1, PrivilegeType.EDIT_COMMENTS_PROJECT, admin));
admin = userService.getUserByToken(adminToken);
String project_id = "test_id";
Thread addProjectThread = new Thread(new Runnable() {
@Override
public void run() {
try {
projectService.createProject(createProjectParams("testFiles/sample.xml").projectId(project_id));
} catch (Exception e) {
e.printStackTrace();
}
}
});
addProjectThread.start();
Thread dropPrivilegesThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(100);
userService.dropPrivilegesForObjectType(PrivilegeType.VIEW_PROJECT, defaultProject.getId());
} catch (Exception e) {
e.printStackTrace();
}
}
});
dropPrivilegesThread.start();
dropPrivilegesThread.join();
addProjectThread.join();
Project project = projectService.getProjectByProjectId(project_id, adminToken);
assertEquals(ProjectStatus.DONE, project.getStatus());
Thread removeProjectThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Project project = projectService.getProjectByProjectId(project_id, adminToken);
assertEquals(ProjectStatus.DONE, project.getStatus());
projectService.removeProject(project, null, false, adminToken);
} catch (Exception e) {
e.printStackTrace();
}
}
});
removeProjectThread.start();
removeProjectThread.join();
assertNull(projectService.getProjectByProjectId(project_id, adminToken));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testUpdater() throws Exception {
try {
......
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