From 4799fcca5fb1bfbb0f851abc63aabbf7a8f576e3 Mon Sep 17 00:00:00 2001 From: dilanua Date: Sat, 10 Sep 2016 06:30:06 +0530 Subject: [PATCH] Adding permissions to operation-bar UI --- .../operation-bar.hbs | 3 +- .../operation-bar.js | 73 +++++++++++++++++++ .../public/js/operation-bar.js | 22 +++++- 3 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs index e4a17d8f0..c8d704777 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs @@ -16,12 +16,13 @@ under the License. }} {{#zone "content"}} -
+
{{unit "mdm.unit.device.operation-mod"}}
{{/zone}} {{#zone "bottomJs"}} + {{js "js/operation-bar.js"}} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js new file mode 100644 index 000000000..d9390191f --- /dev/null +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +function onRequest(context) { + var log = new Log("mdm.unit.device.operation-bar"); + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var deviceType = context.uriParams.deviceType; + var viewModel = {}; + var permissions = []; + + // permission checks + if (deviceType == "android") { + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/android/ring")) { + permissions.push("DEVICE_RING"); + } + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/android/lock-devices")) { + permissions.push("DEVICE_LOCK"); + } + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/android/unlock-devices")) { + permissions.push("DEVICE_UNLOCK"); + } + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/android/location")) { + permissions.push("DEVICE_LOCATION"); + } + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/android/clear-password")) { + permissions.push("CLEAR_PASSWORD"); + } + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/android/reboot")) { + permissions.push("DEVICE_REBOOT"); + } + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/android/upgrade-firmware")) { + permissions.push("UPGRADE_FIRMWARE"); + } + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/android/mute")) { + permissions.push("DEVICE_MUTE"); + } + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/android/send-notification")) { + permissions.push("NOTIFICATION"); + } + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/android/change-lock-code")) { + permissions.push("CHANGE_LOCK_CODE"); + } + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/android/enterprise-wipe")) { + permissions.push("ENTERPRISE_WIPE"); + } + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/android/wipe")) { + permissions.push("WIPE_DATA"); + } + } else if (deviceType == "ios") { + + } else if (deviceType == "windows") { + + } + + viewModel["permissions"] = stringify(permissions); + + return viewModel; +} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js index 6d9ef5567..b609f3a70 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js @@ -21,8 +21,8 @@ */ var operations = '.wr-operations', - modalPopup = '.modal', - modalPopupContent = modalPopup + ' .modal-content', + modalPopup = '.wr-modalpopup', + modalPopupContent = modalPopup + ' .modalpopup-content', navHeight = $('#nav').height(), headerHeight = $('header').height(), offset = (headerHeight + navHeight), @@ -108,8 +108,21 @@ function loadOperationBar(deviceType) { //var serviceURL = "/mdm-admin/features/" + platformType; var serviceURL = "/api/device-mgt/v1.0/devices/" + platformType + "/*/features"; var successCallback = function (data) { + var permittedOpps = []; + var i; + var permissionList = $("#operations-mod").data("permissions"); + var totalFeatures = JSON.parse(data); + for (i = 0; i < permissionList.length; i++) { + var j; + for (j = 0; j < totalFeatures.length; j++) { + if (permissionList[i] == totalFeatures[j]["code"]) { + permittedOpps.push(totalFeatures[j]); + } + } + } + var viewModel = {}; - data = JSON.parse(data).filter(function (current) { + permittedOpps = permittedOpps.filter(function (current) { var iconName; switch (deviceType) { case platformTypeConstants.ANDROID: @@ -129,7 +142,8 @@ function loadOperationBar(deviceType) { return current; } }); - viewModel.features = data; + + viewModel.features = permittedOpps; var content = template(viewModel); $(".wr-operations").html(content); };