Skip to content

Commit 4d59190

Browse files
author
Anders Breid
authored
Better indication that user must login to CRUD subscriptions (#218)
- Text added to notifications and Login icon, Login will be replaced with username when user is logged in - CRUD buttons for subscriptions have a mouseover popup indicating that user must login if user is not logged in - Icons on locked buttons will be a keylock when disabled
1 parent 4a4d9f7 commit 4d59190

File tree

12 files changed

+121
-36
lines changed

12 files changed

+121
-36
lines changed

src/functionaltest/java/com/ericsson/ei/frontend/TestSubscriptionCRUD.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public class TestSubscriptionCRUD extends TestBaseClass {
2525
private static final String SUBSCRIPTION_ENDPOINT = "/subscriptions";
2626
private static final String SUBSCRIPTION_DELETE_ENDPOINT = "/subscriptions/Subscription_1";
2727
private static final String SUBSCRIPTION_FILE_PATH = "src/functionaltest/resources/responses/subscription.json";
28-
private static final String ADMIN = "admin";
28+
private static final String USERNAME = "mySuperDuperBestUsernameEver";
29+
private static final String PASSWORD = "password";
2930
private static final String NOT_FOUND = "[]";
3031
private String subscriptionRequestBody;
3132
private String responseBodyPost;
@@ -44,7 +45,7 @@ public void init() throws Exception {
4445
backEndInstancesUtils.setDefaultBackEndInstance("test", "localhost", mockServerRule.getPort(), "", false);
4546
subscriptionRequestBody = getJSONStringFromFile(SUBSCRIPTION_FILE_PATH);
4647

47-
String auth = ADMIN + ":" + ADMIN;
48+
String auth = USERNAME + ":" + PASSWORD;
4849
encodedAuth = StringUtils.newStringUtf8(Base64.encodeBase64(auth.getBytes()));
4950
responseBodyPost = new JsonParser().parse("{\"msg\": \"Inserted Successfully\"," + "\"statusCode\": 200}").toString();
5051
responseBodyPut = new JsonParser().parse("{\"msg\": \"Updated Successfully\"," + "\"statusCode\": 200}").toString();

src/functionaltest/java/com/ericsson/ei/frontend/TestSubscriptionHandling.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ public void before() throws IOException {
7575

7676
@Test
7777
public void testSubscriptionButtons() throws Exception {
78-
setupMockEndpoints(false, "");
78+
final boolean security = false;
79+
final String username = "";
80+
setupMockEndpoints(security, username);
7981
removeAllSubscriptions();
8082
clickAndVerifyGetTemplateButton();
8183
uploadSubscriptions();
@@ -84,7 +86,9 @@ public void testSubscriptionButtons() throws Exception {
8486

8587
@Test
8688
public void testAddSubscriptionAndVerifyForm() throws Exception {
87-
setupMockEndpoints(false, "");
89+
final boolean security = false;
90+
final String username = "";
91+
setupMockEndpoints(security, username);
8892
loadAndRefreshSubscriptionPage();
8993
clickAddSubscriptionAndVerifyFormOpen();
9094
clickFormCancelAndVerifyFormClosed();
@@ -102,22 +106,28 @@ public void testAddSubscriptionAndVerifyForm() throws Exception {
102106

103107
@Test
104108
public void testSubscriptionHandlingWithLDAPDisabled() throws Exception {
105-
setupMockEndpoints(false, "");
109+
final boolean security = false;
110+
final String username = "";
111+
setupMockEndpoints(security, username);
106112
loadAndRefreshSubscriptionPage();
107113
verifyAuthorizedSubscriptionCRUD();
108114
verifyViewButtonOnSubscription();
109115
}
110116

111117
@Test
112118
public void testSubscriptionHandlingWithLDAPEnabledInvalidUser() throws Exception {
113-
setupMockEndpoints(true, "");
119+
final boolean security = true;
120+
final String username = "";
121+
setupMockEndpoints(security, username);
114122
loadAndRefreshSubscriptionPage();
115123
verifyUnauthorizedSubscriptionCRUD();
116124
}
117125

118126
@Test
119127
public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
120-
setupMockEndpoints(true, "ABCD");
128+
final boolean security = true;
129+
final String username = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
130+
setupMockEndpoints(security, username);
121131
loadAndRefreshSubscriptionPage();
122132
verifyAuthorizedSubscriptionCRUD();
123133
verifyUnauthorizedSubscriptionCRUD();

src/functionaltest/resources/responses/SubscriptionForUploadLDAP.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"aggregationtype":"eiffel-intelligence",
44
"created":1524037895385,
5-
"ldapUserName" : "ABCD",
5+
"ldapUserName" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
66
"notificationMeta":"http://eiffel-jenkins1:8080/job/ei-artifact-triggered-job/build",
77
"notificationType":"REST_POST",
88
"restPostBodyMediaType":"application/x-www-form-urlencoded",
@@ -59,7 +59,7 @@
5959
{
6060
"aggregationtype":"eiffel-intelligence",
6161
"created":1524223397628,
62-
"ldapUserName" : "ABCD",
62+
"ldapUserName" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
6363
"notificationMeta":"http://<MyHost:port>/api/doit",
6464
"notificationType":"REST_POST",
6565
"restPostBodyMediaType":"application/json",

src/main/resources/static/css/style.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
.card-standard {
2121
width: 25rem;
2222
}
23+
.top-nav-bar-text{
24+
color: #c1c1c1;
25+
padding-left: 0px;
26+
font-size: 90%;
27+
}
2328
.sticky-button-bar{
2429
position: -webkit-sticky; /* Safari */
2530
position: sticky;
@@ -83,7 +88,6 @@
8388
height: 45px;
8489
animation: spin 1s cubic-bezier(.86,0,.07,1) infinite;
8590
}
86-
8791
.cursor-pointer {
8892
cursor: pointer;
8993
}
@@ -132,6 +136,13 @@
132136
font-size: 12pt;
133137
color: #dc3545;
134138
}
139+
#login-nav-bar-text{
140+
max-width: 100px;
141+
min-width: 10px;
142+
white-space: nowrap;
143+
overflow: hidden;
144+
text-overflow:ellipsis;
145+
}
135146
/* The switch - the box around the slider */
136147
.switch {
137148
position: relative;

src/main/resources/static/css/ui.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ body {
188188
.nav-item .fa:hover {
189189
color: #fff;
190190
}
191+
.user-login-icon {
192+
color: #4FFD05 !important;
193+
}
194+
.user-login-icon:hover {
195+
color: #4FFD05 !important;
196+
}
191197
.nav-item[type="button"] {
192198
outline: 0;
193199
line-height: 0;
@@ -197,6 +203,7 @@ body {
197203
}
198204
.nav-link {
199205
padding: 0;
206+
padding-right: 10px !important;
200207
}
201208
.nav-link:focus {
202209
outline: 0;

src/main/resources/static/js/common.js

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,28 +239,63 @@ function viewModel(backendInstanceData) {
239239
// End ## Load Back end list ##
240240

241241
// Start ## Login and Security ##
242-
function doIfUserLoggedIn(user) {
243-
setCurrentUser(user);
242+
function functionsToExecuteIfUserIsLoggedIn(username) {
243+
setCurrentUser(username);
244+
showLoggedInUserInformation(username);
245+
unlockSubscriptionButtons();
246+
}
247+
248+
function showLoggedInUserInformation(username) {
244249
$("#userItem").show();
245-
$("#userItem").addClass("user-login");
246-
$("#ldapUserName").text(user);
250+
$("#login-nav-bar-icon").addClass("user-login-icon");
251+
$("#login-nav-bar-text").text(cropUsername(username));
252+
$("#ldapUserName").text(username);
247253
$("#loginBlock").hide();
248254
$("#logoutBlock").show();
255+
}
256+
257+
function unlockSubscriptionButtons() {
258+
$(".logged-out-buttons").addClass("hidden_by_default");
259+
$(".logged-in-buttons").removeClass("hidden_by_default");
249260
$(".show_if_authorized").prop('disabled', false);
261+
$(".show_if_authorized").prop('title', "");
250262
}
251263

252-
function doIfUserLoggedOut() {
264+
function cropUsername(username) {
265+
var ellipsis = "...";
266+
267+
if (username.length <= getUsernameMaxDisplayLength()) {
268+
return username;
269+
}
270+
271+
var breakUsernameAtIndex = getUsernameMaxDisplayLength() - ellipsis.length;
272+
return username.substr(0, breakUsernameAtIndex) + ellipsis;
273+
}
274+
275+
function functionsToExecuteIfUserIsLoggedOut() {
253276
setCurrentUser("");
277+
showUserLoggedOutInformation();
278+
lockSubscriptionButtons();
279+
sessionStorage.setItem('errorsStore', []);
280+
}
281+
282+
function showUserLoggedOutInformation() {
254283
$("#userItem").show();
255-
$("#userItem").removeClass("user-login");
284+
$("#login-nav-bar-icon").removeClass("user-login-icon");
285+
$("#login-nav-bar-text").text("Login");
256286
$("#ldapUserName").text("Guest");
257287
$("#loginBlock").show();
258288
$("#logoutBlock").hide();
289+
}
290+
291+
function lockSubscriptionButtons() {
292+
$(".logged-out-buttons").removeClass("hidden_by_default");
293+
$(".logged-in-buttons").addClass("hidden_by_default");
259294
$(".show_if_authorized").prop('disabled', true);
260-
sessionStorage.setItem('errorsStore', []);
295+
$(".show_if_authorized").prop('title', 'Please login to enable!');
261296
}
262297

263-
function doIfSecurityOff() {
298+
function executeIfLdapIsDeactivated() {
264299
$("#userItem").hide();
265300
$("#ldapUserName").text("");
266301
}
@@ -273,11 +308,11 @@ function checkBackendSecured() {
273308
if (isLdapEnabled()) {
274309
checkLoggedInUser();
275310
} else {
276-
doIfSecurityOff();
311+
executeIfLdapIsDeactivated();
277312
}
278313
},
279314
error: function (XMLHttpRequest, textStatus, errorThrown) {
280-
doIfSecurityOff();
315+
executeIfLdapIsDeactivated();
281316
}
282317
};
283318
var ajaxHttpSender = new AjaxHttpSender();
@@ -288,10 +323,10 @@ function checkLoggedInUser() {
288323
var callback = {
289324
success: function (responseData, textStatus) {
290325
var userFromBackEnd = responseData.user;
291-
doIfUserLoggedIn(userFromBackEnd);
326+
functionsToExecuteIfUserIsLoggedIn(userFromBackEnd);
292327
},
293328
error: function (XMLHttpRequest, textStatus, errorThrown) {
294-
doIfUserLoggedOut();
329+
functionsToExecuteIfUserIsLoggedOut();
295330
}
296331
};
297332
var ajaxHttpSender = new AjaxHttpSender();

src/main/resources/static/js/global-variables.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ var table;
66
var subscriptionNameRegex = $('#subscriptionNameRegex').text();
77
var notificationMetaRegex = $('#notificationMetaRegex').text();
88

9+
// Minimum leangth is 4 due to ellipsis being 3 long
10+
var usernameMaxDisplayLength = 15;
11+
912
var backendEndpoints = {
1013
AUTH: "/auth",
1114
LOGIN: "/auth/login",
@@ -35,7 +38,7 @@ var statusText = {
3538
var backEndStatus = true;
3639
var backEndStatusUpdated = false;
3740
var previousBackEndStatus;
38-
var backEnsStatusTimerInterval;
41+
var backEndStatusTimerInterval;
3942
// End Status variables
4043

4144
// Start ## getters and setters
@@ -93,8 +96,8 @@ function isBackEndStatusChanged() {
9396
}
9497

9598
function setBackEndStatusTimerInterval() {
96-
if (backEnsStatusTimerInterval === undefined) {
97-
backEnsStatusTimerInterval = window.setInterval(function () { updateBackendStatus(); }, 15000);
99+
if (backEndStatusTimerInterval === undefined) {
100+
backEndStatusTimerInterval = window.setInterval(function () { updateBackendStatus(); }, 15000);
98101
}
99102
}
100103

@@ -110,4 +113,12 @@ function getNotificationMetaRegex() {
110113
return notificationMetaRegex;
111114
}
112115

116+
function getUsernameMaxDisplayLength() {
117+
if (usernameMaxDisplayLength < 4) {
118+
// Minimum leangth is 4 due to ellipsis being 3 long
119+
return 4;
120+
}
121+
return usernameMaxDisplayLength;
122+
}
123+
113124
// End ## getters and setters status handling

src/main/resources/static/js/login.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jQuery(document).ready(function () {
3838
success: function (responseData, textStatus) {
3939
var currentUser = JSON.parse(ko.toJSON(responseData)).user;
4040
$.jGrowl("Welcome " + currentUser, { sticky: false, theme: 'Notify' });
41-
doIfUserLoggedIn(currentUser);
41+
functionsToExecuteIfUserIsLoggedIn(currentUser);
4242
navigateToRoute('subscriptions');
4343
},
4444
error: function (XMLHttpRequest, textStatus, errorThrown) {

src/main/resources/static/js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jQuery(document).ready(function () {
1717
$("#logoutBtn").click(function () {
1818
var callback = {
1919
complete: function () {
20-
doIfUserLoggedOut();
20+
functionsToExecuteIfUserIsLoggedOut();
2121
navigateToRoute('*');
2222
}
2323
};

src/main/resources/static/js/status-handler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ function updateBackendStatus() {
8080
var callback = {
8181
error: function (XMLHttpRequest, textStatus, errorThrown) {
8282
if (XMLHttpRequest.status == 401) {
83-
doIfUserLoggedOut();
83+
functionsToExecuteIfUserIsLoggedOut();
8484
setBackEndStatusOk(true);
8585
} else {
86-
doIfSecurityOff();
86+
executeIfLdapIsDeactivated();
8787
setBackEndStatusOk(false);
8888
}
8989
},

0 commit comments

Comments
 (0)