Commit 3ad4baec authored by Piotr Gawron's avatar Piotr Gawron

Merge branch '611-custom-overlays' into 'devel_12.1.x'

Resolve "disable "Add overlay" button or improve error message `403` when number of custom layout is greater equal `CUSTOM_LAYOUTS`"

See merge request !558
parents 92e45bd6 2cc23c11
Pipeline #8010 passed with stage
in 1 minute and 53 seconds
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)
......
......@@ -2056,7 +2056,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');
......@@ -290,6 +291,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);
}
......
......@@ -387,8 +387,10 @@ public class LayoutService implements ILayoutService {
layoutDao.update(layout);
try {
getEmailSender().sendEmail("MapViewer status", "There was a problem with generating layout " + params.getName()
+ ". Contact administrator to solve this issue.", params.getUser());
getEmailSender().sendEmail("MapViewer status",
"There was a problem with generating layout " + params.getName()
+ ". Contact administrator to solve this issue.",
params.getUser());
} catch (MessagingException e1) {
logger.error("Problem with sending email", e1);
}
......@@ -411,7 +413,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.getModel(), params.getUser())) {
throw new SecurityException("You cannot add more overlays");
}
ColorSchemaReader reader = new ColorSchemaReader();
final Collection<ColorSchema> schemas = reader.readColorSchema(params.getColorInputStream(),
TextFileUtils.getHeaderParametersFromFile(params.getColorInputStream()));
......@@ -900,7 +906,7 @@ public class LayoutService implements ILayoutService {
@Override
public EmailSender getEmailSender() {
if (emailSender==null) {
if (emailSender == null) {
emailSender = new EmailSender(configurationService);
}
return emailSender;
......
......@@ -378,9 +378,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
......
......@@ -157,6 +157,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
public void testGetAvailable() throws Exception {
try {
userService.setUserPrivilege(user, new BasicPrivilege(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").//
......@@ -193,6 +194,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
assertEquals(0, layouts.size());
userService.setUserPrivilege(user, new BasicPrivilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
CreateLayoutParams params = new CreateLayoutParams().name("Test").//
directory("testDir").//
......@@ -227,6 +229,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
assertEquals(0, layouts.size());
userService.setUserPrivilege(user, new BasicPrivilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
CreateLayoutParams params = new CreateLayoutParams().name("Test").//
directory("testDir").//
......@@ -263,6 +266,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
assertEquals(0, layouts.size());
userService.setUserPrivilege(user, new BasicPrivilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
CreateLayoutParams params = new CreateLayoutParams().name("Test").//
directory("testDir").//
model(model).//
......@@ -364,6 +368,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
assertEquals(0, layouts.size());
userService.setUserPrivilege(user, new BasicPrivilege(1, PrivilegeType.CUSTOM_LAYOUTS, user));
userService.setUserPrivilege(user, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user));
CreateLayoutParams params = new CreateLayoutParams().name("Test").//
directory("testDir").//
model(model).//
......@@ -397,6 +402,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
assertEquals(0, layouts.size());
userService.setUserPrivilege(user, new BasicPrivilege(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));
......
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