Using permissionsUtil.hasPermission for clientside permission check

revert-70aa11f8
Rasika Perera 8 years ago
parent b1b6b94570
commit fbe423b824

@ -18,6 +18,7 @@
{{unit "cdmf.unit.ui.title" pageTitle="Device Management"}} {{unit "cdmf.unit.ui.title" pageTitle="Device Management"}}
{{unit "cdmf.unit.data-tables-extended"}} {{unit "cdmf.unit.data-tables-extended"}}
{{unit "cdmf.unit.lib.ui-permissions-utility"}}
{{#zone "breadcrumbs"}} {{#zone "breadcrumbs"}}
<li> <li>

@ -29,7 +29,6 @@ function InitiateViewOption(url) {
(function () { (function () {
var cache = {}; var cache = {};
var permissionSet = {};
var validateAndReturn = function (value) { var validateAndReturn = function (value) {
return (value == undefined || value == null) ? "Unspecified" : value; return (value == undefined || value == null) ? "Unspecified" : value;
}; };
@ -44,15 +43,6 @@ function InitiateViewOption(url) {
}, {}); }, {});
} }
}); });
//This method is used to setup permission for device listing
$.setPermission = function (permission) {
permissionSet[permission] = true;
};
$.hasPermission = function (permission) {
return permissionSet[permission];
};
})(); })();
/* /*
@ -78,13 +68,6 @@ $(document).ready(function () {
addDeviceSelectedClass(this); addDeviceSelectedClass(this);
}); });
var permissionList = $("#permission").data("permission");
for (var key in permissionList) {
if (permissionList.hasOwnProperty(key)) {
$.setPermission(key);
}
}
/* for device list sorting drop down */ /* for device list sorting drop down */
$(".ctrl-filter-type-switcher").popover({ $(".ctrl-filter-type-switcher").popover({
html: true, html: true,
@ -168,11 +151,11 @@ function toTitleCase(str) {
function loadDevices(searchType, searchParam) { function loadDevices(searchType, searchParam) {
var serviceURL; var serviceURL;
if (groupName && groupOwner && $.hasPermission("LIST_OWN_DEVICES")) { if (groupName && groupOwner && permissionsUtil.hasPermission("LIST_OWN_DEVICES")) {
serviceURL = "/api/device-mgt/v1.0/groups/owner/" + groupOwner + "/name/" + groupName + "/devices"; serviceURL = "/api/device-mgt/v1.0/groups/owner/" + groupOwner + "/name/" + groupName + "/devices";
} else if ($.hasPermission("LIST_DEVICES")) { } else if (permissionsUtil.hasPermission("LIST_DEVICES")) {
serviceURL = "/api/device-mgt/v1.0/devices"; serviceURL = "/api/device-mgt/v1.0/devices";
} else if ($.hasPermission("LIST_OWN_DEVICES")) { } else if (permissionsUtil.hasPermission("LIST_OWN_DEVICES")) {
//Get authenticated users devices //Get authenticated users devices
serviceURL = "/api/device-mgt/v1.0/users/devices?username=" + currentUser; serviceURL = "/api/device-mgt/v1.0/users/devices?username=" + currentUser;
} else { } else {
@ -227,6 +210,38 @@ function loadDevices(searchType, searchParam) {
return type; return type;
} }
function analyticsEnabled(type) {
var deviceTypes = deviceListing.data("deviceTypes");
for (var i = 0; i < deviceTypes.length; i++) {
if (deviceTypes[i].type == type) {
var analyticsEnabled = deviceTypes[i].analyticsEnabled;
if (analyticsEnabled == undefined) {
// By default it should be enabled
return true;
}
// In JS Boolean("false") returns TRUE => http://stackoverflow.com/a/264037/1560536
return (analyticsEnabled == "true");
}
}
return true;
}
function groupingEnabled(type) {
var deviceTypes = deviceListing.data("deviceTypes");
for (var i = 0; i < deviceTypes.length; i++) {
if (deviceTypes[i].type == type) {
var groupingEnabled = deviceTypes[i].groupingEnabled;
if (groupingEnabled == undefined) {
// By default it should be enabled
return true;
}
// In JS Boolean("false") returns TRUE => http://stackoverflow.com/a/264037/1560536
return (analyticsEnabled == "true");
}
}
return true;
}
var columns = [ var columns = [
{ {
targets: 0, targets: 0,
@ -251,7 +266,8 @@ function loadDevices(searchType, searchParam) {
return html; return html;
} }
}, },
{targets: 2, {
targets: 2,
data: 'user', data: 'user',
class: 'fade-edge remove-padding-top', class: 'fade-edge remove-padding-top',
}, },
@ -292,7 +308,7 @@ function loadDevices(searchType, searchParam) {
class: 'fade-edge remove-padding-top', class: 'fade-edge remove-padding-top',
render: function (status, type, row, meta) { render: function (status, type, row, meta) {
if (getDeviceTypeCategory(row.deviceType) == 'mobile') { if (getDeviceTypeCategory(row.deviceType) == 'mobile') {
return row.enrolmentInfo.ownership; return row.ownership;
} else { } else {
return null; return null;
} }
@ -313,15 +329,19 @@ function loadDevices(searchType, searchParam) {
' class="btn padding-reduce-on-grid-view"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' ' class="btn padding-reduce-on-grid-view"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>'
+ +
'<i class="fw fw-view fw-stack-1x"></i></span><span class="hidden-xs hidden-on-grid-view">View</span></a>'; '<i class="fw fw-view fw-stack-1x"></i></span><span class="hidden-xs hidden-on-grid-view">View</span></a>';
html += '<a href="device/' + deviceType + '/analytics?deviceId=' + deviceIdentifier + '&deviceName='
if (analyticsEnabled(row.deviceType)) {
html +=
'<a href="device/' + deviceType + '/analytics?deviceId=' + deviceIdentifier + '&deviceName='
+ row.name + '" ' + + row.name + '" ' +
'data-click-event="remove-form" class="btn padding-reduce-on-grid-view"><span class="fw-stack">' 'data-click-event="remove-form" class="btn padding-reduce-on-grid-view"><span class="fw-stack">'
+ +
'<i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-statistics fw-stack-1x"></i></span>' '<i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-statistics fw-stack-1x"></i></span>'
+ +
'<span class="hidden-xs hidden-on-grid-view">Analytics</span>'; '<span class="hidden-xs hidden-on-grid-view">Analytics</span>';
}
if (!groupName || !groupOwner) { if (groupingEnabled(deviceType) && (!groupName || !groupOwner)) {
html += html +=
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view group-device-link" ' '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view group-device-link" '
+ +
@ -528,7 +548,7 @@ function hidePopup() {
$(modalPopupContent).html(""); $(modalPopupContent).html("");
$(modalPopupContent).removeClass("operation-data"); $(modalPopupContent).removeClass("operation-data");
$(modalPopup).modal('hide'); $(modalPopup).modal('hide');
$('body').removeClass('modal-open').css('padding-right','0px'); $('body').removeClass('modal-open').css('padding-right', '0px');
$('.modal-backdrop').remove(); $('.modal-backdrop').remove();
} }
@ -553,9 +573,9 @@ function attachDeviceEvents() {
showPopup(); showPopup();
var serviceURL; var serviceURL;
if ($.hasPermission("LIST_ALL_GROUPS")) { if (permissionsUtil.hasPermission("LIST_ALL_GROUPS")) {
serviceURL = "/api/device-mgt/v1.0/groups/all"; serviceURL = "/api/device-mgt/v1.0/groups/all";
} else if ($.hasPermission("LIST_GROUPS")) { } else if (permissionsUtil.hasPermission("LIST_GROUPS")) {
//Get authenticated users groups //Get authenticated users groups
serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser + "/all"; serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser + "/all";
} }

@ -19,6 +19,7 @@
{{unit "cdmf.unit.ui.content.title" pageHeader="Groups"}} {{unit "cdmf.unit.ui.content.title" pageHeader="Groups"}}
{{unit "cdmf.unit.lib.data-table"}} {{unit "cdmf.unit.lib.data-table"}}
{{unit "cdmf.unit.lib.ui-permissions-utility"}}
{{#zone "breadcrumbs"}} {{#zone "breadcrumbs"}}
<li> <li>

@ -82,26 +82,13 @@ function toTitleCase(str) {
}); });
} }
(function () {
var permissionSet = {};
//This method is used to setup permission for device listing
$.setPermission = function (permission) {
permissionSet[permission] = true;
};
$.hasPermission = function (permission) {
return permissionSet[permission];
};
})();
function loadGroups() { function loadGroups() {
var groupListing = $("#group-listing"); var groupListing = $("#group-listing");
var currentUser = groupListing.data("currentUser"); var currentUser = groupListing.data("currentUser");
var serviceURL; var serviceURL;
if ($.hasPermission("LIST_ALL_GROUPS")) { if (permissionsUtil.hasPermission("LIST_ALL_GROUPS")) {
serviceURL = "/devicemgt_admin/groups"; serviceURL = "/devicemgt_admin/groups";
} else if ($.hasPermission("LIST_GROUPS")) { } else if (permissionsUtil.hasPermission("LIST_GROUPS")) {
//Get authenticated users groups //Get authenticated users groups
serviceURL = "/devicemgt_admin/groups/user/" + currentUser; serviceURL = "/devicemgt_admin/groups/user/" + currentUser;
} else { } else {

Loading…
Cancel
Save