Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #439 from xizi-xu/dashboardEnhancement
Browse files Browse the repository at this point in the history
Fix privileged users alerts and dashboard viewing issue
  • Loading branch information
bsura committed Feb 11, 2017
2 parents 7097970 + e27e501 commit 5fe3f85
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
9 changes: 5 additions & 4 deletions ArgusWeb/app/js/controllers/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ angular.module('argus.controllers.alerts', ['ngResource'])
usersList: []
};
var remoteUsername = Auth.getUsername();
var userPrivileged = Auth.isPrivileged();


$scope.getAlerts = function (shared) {
Expand All @@ -64,8 +65,8 @@ angular.module('argus.controllers.alerts', ['ngResource'])
};

function setAlertsAfterLoading (alerts, shared) {
alertLists.sharedList = TableListService.getListUnderTab(alerts, true, remoteUsername);
alertLists.usersList = TableListService.getListUnderTab(alerts, false, remoteUsername);
alertLists.sharedList = TableListService.getListUnderTab(alerts, true, remoteUsername, userPrivileged);
alertLists.usersList = TableListService.getListUnderTab(alerts, false, remoteUsername, userPrivileged);
$scope.alertsLoaded = true;
$scope.getAlerts(shared);
}
Expand Down Expand Up @@ -102,7 +103,7 @@ angular.module('argus.controllers.alerts', ['ngResource'])
Alerts.save(alert, function (result) {
// update both scope and session alerts
result.expression = "";
alertLists = TableListService.addItemToTableList(alertLists, 'alerts', result, remoteUsername);
alertLists = TableListService.addItemToTableList(alertLists, 'alerts', result, remoteUsername, userPrivileged);
$scope.getAlerts($scope.shared);
growl.success('Created "' + alert.name + '"');
}, function (error) {
Expand All @@ -112,7 +113,7 @@ angular.module('argus.controllers.alerts', ['ngResource'])

$scope.removeAlert = function (alert) {
Alerts.delete({alertId: alert.id}, function (result) {
alertLists = TableListService.deleteItemFromTableList(alertLists, 'alerts', alert, remoteUsername);
alertLists = TableListService.deleteItemFromTableList(alertLists, 'alerts', alert, remoteUsername, userPrivileged);
$scope.getAlerts($scope.shared);
growl.success('Deleted "' + alert.name + '"');
}, function (error) {
Expand Down
9 changes: 5 additions & 4 deletions ArgusWeb/app/js/controllers/dashboards.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ angular.module('argus.controllers.dashboards', ['ngResource', 'ui.codemirror'])
usersList: []
};
var remoteUsername = Auth.getUsername();
var userPrivileged = Auth.isPrivileged();

// TODO: refactor to DashboardService
$scope.getDashboards = function (shared) {
Expand All @@ -57,8 +58,8 @@ angular.module('argus.controllers.dashboards', ['ngResource', 'ui.codemirror'])
};

function setDashboardsAfterLoading (dashboards, shared) {
dashboardLists.sharedList = TableListService.getListUnderTab(dashboards, true, remoteUsername);
dashboardLists.usersList = TableListService.getListUnderTab(dashboards, false, remoteUsername);
dashboardLists.sharedList = TableListService.getListUnderTab(dashboards, true, remoteUsername, userPrivileged);
dashboardLists.usersList = TableListService.getListUnderTab(dashboards, false, remoteUsername, userPrivileged);
$scope.dashboardsLoaded = true;
$scope.getDashboards(shared);
}
Expand Down Expand Up @@ -89,7 +90,7 @@ angular.module('argus.controllers.dashboards', ['ngResource', 'ui.codemirror'])
Dashboards.save(dashboard, function (result) {
// update all dashboards
result.content = "";
dashboardLists = TableListService.addItemToTableList(dashboardLists, 'dashboards', result, remoteUsername);
dashboardLists = TableListService.addItemToTableList(dashboardLists, 'dashboards', result, remoteUsername, userPrivileged);
// update dashboards to be seen
$scope.getDashboards($scope.shared);
growl.success('Created "' + dashboard.name + '"');
Expand All @@ -102,7 +103,7 @@ angular.module('argus.controllers.dashboards', ['ngResource', 'ui.codemirror'])
$scope.deleteDashboard = function (dashboard) {
Dashboards.delete({dashboardId: dashboard.id}, function (result) {
// update all dashboards
dashboardLists = TableListService.deleteItemFromTableList(dashboardLists, 'dashboards', dashboard, remoteUsername);
dashboardLists = TableListService.deleteItemFromTableList(dashboardLists, 'dashboards', dashboard, remoteUsername, userPrivileged);
// update dashboards to be seen
$scope.getDashboards($scope.shared);
growl.success('Deleted "' + dashboard.name + '"');
Expand Down
12 changes: 6 additions & 6 deletions ArgusWeb/app/js/services/tableListService.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ angular.module('argus.services.tableListService', [])
});
};

this.getListUnderTab = function (allItems, shared, userName) {
this.getListUnderTab = function (allItems, shared, userName, userPrivileged) {
var i, result = [];
var totNum = allItems.length;
if(shared) {
Expand All @@ -22,25 +22,25 @@ angular.module('argus.services.tableListService', [])
}
} else {
for(i = 0; i < totNum; i++) {
if (allItems[i].ownerName === userName) {
if (allItems[i].ownerName === userName || userPrivileged) {
result.push(allItems[i]);
}
}
}
return result;
};

this.addItemToTableList = function (allList, propertyType, item, userName) {
this.addItemToTableList = function (allList, propertyType, item, userName, userPrivileged) {
$sessionStorage[propertyType].cachedData.push(item);
if (item.shared) allList.sharedList.push(item);
if (item.ownerName === userName) allList.usersList.push(item);
if (item.ownerName === userName || userPrivileged) allList.usersList.push(item);
return allList;
};

this.deleteItemFromTableList = function (allList, propertyType, item, userName) {
this.deleteItemFromTableList = function (allList, propertyType, item, userName, userPrivileged) {
$sessionStorage[propertyType].cachedData = this.deleteItemFromListHelper($sessionStorage[propertyType].cachedData, item);
if (item.shared) allList.sharedList = this.deleteItemFromListHelper(allList.sharedList, item);
if (item.ownerName === userName) allList.usersList = this.deleteItemFromListHelper(allList.usersList, item);
if (item.ownerName === userName || userPrivileged) allList.usersList = this.deleteItemFromListHelper(allList.usersList, item);
return allList;
};
}]);

0 comments on commit 5fe3f85

Please sign in to comment.