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

info message about restricted access improved (there is a difference when you...

info message about restricted access improved (there is a difference when you are guest or logged user)
parent 0f6f40d8
Pipeline #3001 passed with stage
in 45 seconds
......@@ -175,6 +175,31 @@ GuiConnector.prototype.hideProcessing = function () {
$(self._processingDialog).dialog("close");
};
GuiConnector.prototype.getErrorMessageForError = function (error) {
var message = error;
if (message instanceof SecurityError) {
if (ServerConnector.getSessionData().getLogin() === "anonymous") {
message = error.message + "<p>Please <a href=\"login.xhtml?from=" + encodeURI(window.location.href) + "\">login</a> to access this resource</p>";
} else {
message = error.message + "<p>Please <a href=\"login.xhtml?from=" + encodeURI(window.location.href) + "\">login</a> " +
"as a different user or ask your administrator to change the permissions to access this resource.</p>";
}
} else if (message instanceof ValidationError) {
message = error.message;
} else if (message instanceof GuiMessageError) {
message = error.message;
} else if (message instanceof NetworkError && (error.message === "XHR error" || error.message === "Failed to fetch")) {
message = "File to big.<br>Please reduce file size or contact administrators.";
} else if (message instanceof ValidationError) {
message = error.message;
} else if (message instanceof GuiMessageError) {
message = error.message;
} else if (message instanceof Error) {
message = "Unexpected error occurred:<p>" + error.message + "</p>";
}
return message;
};
GuiConnector.prototype.alert = function (error) {
var self = returnThisOrSingleton(this);
logger.error(error);
......@@ -191,23 +216,7 @@ GuiConnector.prototype.alert = function (error) {
title: "ERROR"
}).siblings('.ui-dialog-titlebar').css("background", "red");
}
var message = error;
if (message instanceof SecurityError) {
message = error.message + "<p>Please <a href=\"login.xhtml?from=" + encodeURI(window.location.href) + "\">login</a> to access this resource</p>";
} else if (message instanceof ValidationError) {
message = error.message;
} else if (message instanceof GuiMessageError) {
message = error.message;
} else if (message instanceof NetworkError && (error.message === "XHR error" || error.message === "Failed to fetch")) {
message = "File to big.<br>Please reduce file size or contact administrators.";
} else if (message instanceof ValidationError) {
message = error.message;
} else if (message instanceof GuiMessageError) {
message = error.message;
} else if (message instanceof Error) {
message = "Unexpected error occurred:<p>" + error.message + "</p>";
}
self._errorDialogContent.innerHTML = message;
self._errorDialogContent.innerHTML = self.getErrorMessageForError(error);
$(self._errorDialog).dialog("open");
};
......
......@@ -3,6 +3,8 @@
require("./mocha-config");
var GuiConnector = require('../../main/js/GuiConnector');
var SecurityError = require('../../main/js/SecurityError');
var ServerConnector = require('./ServerConnector-mock');
var chai = require('chai');
var assert = chai.assert;
......@@ -35,6 +37,23 @@ describe('GuiConnector', function () {
});
connector.destroy();
});
describe('getErrorMessageForError', function () {
it('SecurityError when logged in', function () {
var connector = new (GuiConnector.constructor)();
ServerConnector.getSessionData().setLogin("testUser");
var message = connector.getErrorMessageForError(new SecurityError());
assert.ok(message.indexOf("ask your administrator")>=0);
connector.destroy();
});
it('SecurityError when not logged in', function () {
var connector = new (GuiConnector.constructor)();
ServerConnector.getSessionData().setLogin("anonymous");
var message = connector.getErrorMessageForError(new SecurityError());
assert.ok(message.indexOf("to access this resource")>=0);
connector.destroy();
});
});
it('info', function () {
var connector = new (GuiConnector.constructor)();
......@@ -64,7 +83,7 @@ describe('GuiConnector', function () {
};
connector.addWindowResizeEvent(handler);
connector.removeWindowResizeEvent(function(){
connector.removeWindowResizeEvent(function () {
});
assert.equal(1, logger.getWarnings().length);
......
{"status":"ok"}
\ No newline at end of file
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