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

Merge branch '417-terms-of-use' into 'devel_11.1.x-clean'

Resolve "Terms of use"

See merge request piotr.gawron/minerva!310
parents e7ce0dac 34f97077
......@@ -13,6 +13,7 @@ var ConfigurationType = {
SIMPLE_COLOR_VAL: "SIMPLE_COLOR_VAL",
SEARCH_DISTANCE: "SEARCH_DISTANCE",
SEARCH_RESULT_NUMBER: "SEARCH_RESULT_NUMBER",
TERMS_OF_USE: "TERMS_OF_USE",
USER_MANUAL_FILE: "USER_MANUAL_FILE",
};
......
......@@ -652,6 +652,17 @@ ServerConnector.getModels = function (projectId) {
return models;
});
};
/**
* TODO REMOVE when API v12 appears (this is just a workaround)
*/
ServerConnector.updateTermsOfUse = function (user, value) {
var self = this;
var url = ServerConnector.getUserUrl({login:user.getLogin()});
url += "/updateTermsOfUse?value=" + value;
return self.readFile(url);
};
ServerConnector.getProject = function (projectId) {
var queryParams = {};
var filterParams = {};
......
......@@ -458,6 +458,13 @@ OverlayPanel.prototype.openAddOverlayDialog = function () {
content.appendChild(contentInput);
content.appendChild(guiUtils.createNewLine());
var consentCheckbox = document.createElement("input");
consentCheckbox.type = "checkbox";
content.appendChild(consentCheckbox);
content.appendChild(guiUtils.createLabel("I am aware that this map is displayed under the terms of the <a href='https://cloud.google.com/maps-platform/terms/' target='_blank'>license of Google Maps Platform</a> and I agree to these terms. " +
"In particular, I warrant that this dataset does not contain Protected Health Information (as defined in and subject to HIPAA). "));
var buttons = [{
text: "UPLOAD",
click: function () {
......@@ -477,6 +484,7 @@ OverlayPanel.prototype.openAddOverlayDialog = function () {
name: nameInput.value,
description: descriptionInput.value,
content: fileContent,
googleLicenseConsent: consentCheckbox.checked,
filename: fileInput.value
};
GuiConnector.showProcessing();
......
......@@ -14,6 +14,7 @@ function User(javaObject) {
this.setMinColor(javaObject.minColor);
this.setMaxColor(javaObject.maxColor);
this.setSimpleColor(javaObject.simpleColor);
this.setTermsOfUseConsent(javaObject.termsOfUseConsent);
}
User.prototype.setLogin = function(login) {
......@@ -88,4 +89,12 @@ User.prototype.getPrivileges = function() {
return this._privileges;
};
User.prototype.setTermsOfUseConsent = function(termsOfUseConsent) {
this._termsOfUseConsent = termsOfUseConsent;
};
User.prototype.isTermsOfUseConsent = function() {
return this._termsOfUseConsent;
};
module.exports = User;
......@@ -57,6 +57,54 @@ function processUrlGetParams(params) {
}
function requestConsent(user, termsOfUseUrl) {
var dialog = document.createElement("div");
var dialogContent = document.createElement("div");
dialogContent.appendChild(functions.createElement({
type: "span",
content: "I agree to the minerva <a href='" + termsOfUseUrl + "' target='_blank'>Terms of Use</a>."
}));
var checkbox = functions.createElement({type: "input", inputType: "checkbox", style: "float: left"});
var okButton = functions.createElement({
type: "button",
content: "OK",
className: "ui-button ui-corner-all ui-widget",
onclick: function () {
return ServerConnector.updateTermsOfUse(user, $(checkbox).is(':checked')).then(function () {
$(dialog).dialog("close");
}).catch(GuiConnector.alert);
}
});
var cancelButton = functions.createElement({
type: "button",
content: "I disagree",
className: "ui-button ui-corner-all ui-widget",
onclick: function () {
return ServerConnector.logout().catch(GuiConnector.alert);
}
});
$(okButton).prop("disabled", true);
$(checkbox).change(function () {
$(okButton).prop("disabled", !$(checkbox).is(':checked'));
});
dialogContent.appendChild(checkbox);
dialogContent.appendChild(okButton);
dialogContent.appendChild(cancelButton);
dialog.appendChild(dialogContent);
document.body.appendChild(dialog);
$(dialog).dialog({
classes: {
"ui-dialog": "ui-state-error"
},
modal: true,
closeOnEscape: false,
title: "Terms of Use"
}).siblings('.ui-dialog-titlebar').css("background", "red");
$(".ui-dialog-titlebar-close", $(dialog).dialog().siblings('.ui-dialog-titlebar')).hide();
$(dialog).dialog("open");
}
function insertGoogleAnalyticsCode() {
return ServerConnector.getConfigurationParam(ConfigurationType.GOOGLE_ANALYTICS_IDENTIFIER).then(
function (identifier) {
......@@ -553,9 +601,14 @@ function create(params) {
return customMap.openSubmap(submapId);
}
}).then(function () {
return ServerConnector.getLoggedUser();
}).then(function (user) {
if (leftPanel.isGoogleLicenseConsentRequired()) {
GuiConnector.alert("Some data overlays doesn't have consent to the terms of the <a href='https://cloud.google.com/maps-platform/terms/' target='_blank'>license of Google Maps Platform</a>. To be able to visualize them you must edit data overlay. ")
}
if (user.getLogin() !== "anonymous" && !user.isTermsOfUseConsent()) {
requestConsent(user, params.getConfiguration().getOption(ConfigurationType.TERMS_OF_USE));
}
var result = createResult(customMap);
if (params.isDebug()) {
......
......@@ -165,6 +165,11 @@ public enum ConfigurationElementType {
+ "(\"General overlays\") on this MINERVA server contain Protected Health Information (as defined in and subject to HIPAA).",
"", ConfigurationElementEditType.STRING, false),
/**
* File where legend 4/4 is stored.
*/
TERMS_OF_USE("Terms of use file", "resources/other/terms_of_use.pdf", ConfigurationElementEditType.URL, false),
;
/**
......
......@@ -92,6 +92,9 @@ public class User implements Serializable {
*/
private boolean removed = false;
@Column(name="terms_of_use_consent")
private boolean termsOfUseConsent = false;
/**
* Set of user privileges.
*/
......@@ -333,4 +336,12 @@ public class User implements Serializable {
this.simpleColor = simpleColor;
}
public boolean isTermsOfUseConsent() {
return termsOfUseConsent;
}
public void setTermsOfUseConsent(boolean termsOfUseConsent) {
this.termsOfUseConsent = termsOfUseConsent;
}
}
alter table user_table add column terms_of_use_consent boolean default false;
......@@ -101,9 +101,10 @@ public class OverlayController extends BaseController {
@RequestParam(value = "description") String description, //
@RequestParam(value = "content") String content, //
@RequestParam(value = "filename") String filename, //
@RequestParam(value = "googleLicenseConsent") String googleLicenseConsent, //
@RequestParam(value = "type", defaultValue = "") String type //
) throws SecurityException, QueryException, IOException {
return overlayRestImp.addOverlay(token, projectId, name, description, content, filename, type);
return overlayRestImp.addOverlay(token, projectId, name, description, content, filename, type, googleLicenseConsent);
}
@RequestMapping(value = "/projects/{projectId}/overlays/{overlayId}", method = { RequestMethod.DELETE }, produces = { MediaType.APPLICATION_JSON_VALUE })
......
......@@ -212,7 +212,7 @@ public class OverlayRestImpl extends BaseRestImpl {
this.layoutDao = layoutDao;
}
public LayoutView addOverlay(String token, String projectId, String name, String description, String content, String filename, String type)
public LayoutView addOverlay(String token, String projectId, String name, String description, String content, String filename, String type, String googleLicenseConsent)
throws SecurityException, QueryException, IOException {
AuthenticationToken authenticationToken = getUserService().getToken(token);
User user = getUserService().getUserByToken(token);
......@@ -239,7 +239,7 @@ public class OverlayRestImpl extends BaseRestImpl {
LayoutView layout = layoutService.createLayout(
new CreateLayoutParams()
.async(false).colorInputStream(stream).description(description).layoutFileName(filename).model(model).name(name).user(user)
.colorSchemaType(colorSchemaType).directory("."));
.colorSchemaType(colorSchemaType).directory(".").googleLicenseConsent(googleLicenseConsent.equalsIgnoreCase("true")));
return layoutService.getLayoutById(model, Integer.valueOf(layout.getIdObject()), authenticationToken);
} catch (InvalidColorSchemaException e) {
throw new QueryException(e.getMessage(), e);
......
......@@ -92,6 +92,18 @@ public class UserController extends BaseController {
return result;
}
/**
* TODO remove when API 12 will be released!!!
*/
@RequestMapping(value = "/users/{login:.+}/updateTermsOfUse", method = { RequestMethod.GET, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
public Map<String, Object> updateTermsOfUse(@CookieValue(value = Configuration.AUTH_TOKEN) String token,
@PathVariable(value = "login") String login, //
@RequestParam(value = "value") String value, //
HttpServletResponse response //
) throws SecurityException, ObjectNotFoundException {
return userRest.updateTermsOfUse(token, login, value);
}
/**
* @return the userService
* @see #userService
......
......@@ -79,6 +79,7 @@ public class UserRestImpl {
columnsSet.add("simpleColor");
columnsSet.add("removed");
columnsSet.add("privileges");
columnsSet.add("termsOfUseConsent");
} else {
for (String str : columns.split(",")) {
columnsSet.add(str);
......@@ -110,6 +111,8 @@ public class UserRestImpl {
value = user.getSimpleColor();
} else if (column.equals("removed")) {
value = user.isRemoved();
} else if (column.equals("termsofuseconsent")) {
value = user.isTermsOfUseConsent();
} else if (column.equals("privileges") && admin) {
value = preparePrivileges(user);
} else {
......@@ -172,4 +175,19 @@ public class UserRestImpl {
this.layoutService = layoutService;
}
public Map<String, Object> updateTermsOfUse(String token, String login, String value) throws SecurityException, ObjectNotFoundException {
User ownUserData = userService.getUserByToken(token);
if (ownUserData == null || ownUserData.getLogin().equals("anonymous")) {
throw new ObjectNotFoundException("User doesn't exist");
}
if (!ownUserData.getLogin().equals(login)) {
throw new SecurityException("Access denied");
}
ownUserData.setTermsOfUseConsent(value.equalsIgnoreCase("true"));
userService.updateUser(ownUserData);
Set<String> columnSet = createUserColumnSet("");
return prepareUse(ownUserData, columnSet, true);
}
}
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