Fix issues in policy UI

revert-70aa11f8
charitha 8 years ago
parent 589ba9c40b
commit 40c59c2f16

@ -582,6 +582,30 @@ var userModule = function () {
return permissions; return permissions;
}; };
/**
* Add new role with permissions.
*
* @param roleName Name of the role
* @param users List of users to assign the role
* @param permissions List of permissions
*/
publicMethods.addRole = function (roleName, users, permissions) {
var carbon = require('carbon');
var tenantId = carbon.server.tenantId();
var url = carbon.server.address('https') + "/admin/services";
var server = new carbon.server.Server(url);
var userManager = new carbon.user.UserManager(server, tenantId);
try {
if (!userManager.roleExists(roleName)) {
userManager.addRole(roleName, users, permissions);
} else {
log.info("Role exist with name: " + roleName);
}
} catch (e) {
throw e;
}
};
publicMethods.addPermissions = function (permissionList, path, init) { publicMethods.addPermissions = function (permissionList, path, init) {
var registry, carbon = require("carbon"); var registry, carbon = require("carbon");
var carbonServer = application.get("carbonServer"); var carbonServer = application.get("carbonServer");

@ -19,7 +19,6 @@
var carbonModule = require("carbon"); var carbonModule = require("carbon");
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var utility = require("/app/modules/utility.js")["utility"];
//noinspection JSUnresolvedFunction Server //noinspection JSUnresolvedFunction Server
var carbonServer = new carbonModule.server.Server({ var carbonServer = new carbonModule.server.Server({
@ -29,9 +28,12 @@ var carbonServer = new carbonModule.server.Server({
application.put("carbonServer", carbonServer); application.put("carbonServer", carbonServer);
//var permissions = { var permissions = {
// "/permission/admin/device-mgt/user": ["ui.execute"], "/permission/admin/device-mgt/devices": ["ui.execute"],
// "/permission/admin/manage/api/subscribe": ["ui.execute"] "/permission/admin/device-mgt/groups": ["ui.execute"],
//}; "/permission/admin/device-mgt/notifications": ["ui.execute"],
"/permission/admin/device-mgt/policies": ["ui.execute"],
"/permission/admin/manage/api/subscribe": ["ui.execute"]
};
//userModule.addRole("internal/devicemgt-user", ["admin"], permissions); userModule.addRole("internal/devicemgt-user", ["admin"], permissions);

@ -220,6 +220,7 @@ var savePolicy = function (policy, state) {
"description": policy["description"], "description": policy["description"],
"compliance": policy["selectedNonCompliantAction"], "compliance": policy["selectedNonCompliantAction"],
"ownershipType": "ANY", "ownershipType": "ANY",
"active": (state != "save"),
"profile": { "profile": {
"profileName": policy["policyName"], "profileName": policy["policyName"],
"deviceType": { "deviceType": {
@ -239,14 +240,8 @@ var savePolicy = function (policy, state) {
payload["roles"] = []; payload["roles"] = [];
} }
var serviceURL;
if (state == "save") {
serviceURL = "/devicemgt_admin/policies/inactive-policy"
} else if (state == "publish") {
serviceURL = "/devicemgt_admin/policies/active-policy"
}
invokerUtil.post( invokerUtil.post(
serviceURL, "/api/device-mgt/v1.0/policies",
payload, payload,
function (response) { function (response) {
response = JSON.parse(response); response = JSON.parse(response);

@ -22,7 +22,7 @@ function onRequest(context) {
var DTYPE_CONF_DEVICE_TYPE_KEY = "deviceType"; var DTYPE_CONF_DEVICE_TYPE_KEY = "deviceType";
var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label"; var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label";
var userModule = require("/app/modules/user.js")["userModule"]; var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var utility = require('/app/modules/utility.js').utility; var utility = require('/app/modules/utility.js').utility;
var response = userModule.getRoles(); var response = userModule.getRoles();
var wizardPage = {}; var wizardPage = {};

Loading…
Cancel
Save