Merge branch 'master' of https://github.com/wso2/carbon-device-mgt into theme-migration

4.x.x
Imesh Chandrasiri 8 years ago
commit 317252ebb0

@ -298,20 +298,20 @@ deviceModule = function () {
var url; var url;
if (uiPermissions.LIST_DEVICES) { if (uiPermissions.LIST_DEVICES) {
url = devicemgtProps["httpsURL"] + url = devicemgtProps["httpsURL"] +
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices/count"; devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices?offset=0&limit=1";
} else if (uiPermissions.LIST_OWN_DEVICES) { } else if (uiPermissions.LIST_OWN_DEVICES) {
url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/devices/user/" + carbonUser.username + "/count"; "/devices?offset=0&limit=1&user=" + carbonUser.username;
} else { } else {
log.error("Access denied for user: " + carbonUser.username); log.error("Access denied for user: " + carbonUser.username);
return -1; return -1;
} }
return serviceInvokers.XMLHttp.get( return serviceInvokers.XMLHttp.get(
url, function (responsePayload) { url, function (responsePayload) {
return responsePayload; return parse(responsePayload["responseText"])["count"];
}, },
function (responsePayload) { function (responsePayload) {
log.error(responsePayload); log.error(responsePayload["responseText"]);
return -1; return -1;
} }
); );

@ -138,6 +138,32 @@ policyModule = function () {
} }
}; };
/*
Get policies count from backend services.
*/
publicMethods.getPoliciesCount = function () {
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
if (!carbonUser) {
log.error("User object was not found in the session");
throw constants["ERRORS"]["USER_NOT_FOUND"];
}
try {
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/policies?offset=0&limit=1";
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
return parse(responsePayload["responseText"])["count"];
},
function (responsePayload) {
log.error(responsePayload["responseText"]);
return -1;
}
);
} catch (e) {
throw e;
}
};
/* /*
@Updated - used by getAllPolicies @Updated - used by getAllPolicies
*/ */

@ -141,6 +141,35 @@ var userModule = function () {
} }
}; };
/*
Get users count from backend services.
*/
publicMethods.getUsersCount = function () {
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
var utility = require("/app/modules/utility.js")["utility"];
if (!carbonUser) {
log.error("User object was not found in the session");
throw constants["ERRORS"]["USER_NOT_FOUND"];
}
try {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users?offset=0&limit=1";
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
return parse(responsePayload["responseText"])["count"];
},
function (responsePayload) {
log.error(responsePayload["responseText"]);
return -1;
}
);
} catch (e) {
throw e;
} finally {
utility.endTenantFlow();
}
};
/** /**
* Return a User object from the backend by calling the JAX-RS * Return a User object from the backend by calling the JAX-RS
* @param username * @param username
@ -236,6 +265,36 @@ var userModule = function () {
} }
}; };
/**
* Get User Roles count from user store (Internal roles not included).
*/
publicMethods.getRolesCount = function () {
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
var utility = require("/app/modules/utility.js")["utility"];
if (!carbonUser) {
log.error("User object was not found in the session");
throw constants["ERRORS"]["USER_NOT_FOUND"];
}
try {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles?offset=0&limit=1";
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
return parse(responsePayload["responseText"])["count"];
},
function (responsePayload) {
log.error(responsePayload["responseText"]);
return -1;
}
);
} catch (e) {
throw e;
} finally {
utility.endTenantFlow();
}
};
/* /*
@Updated @Updated
*/ */

@ -36,10 +36,12 @@ function onRequest() {
page.permissions = permissions; page.permissions = permissions;
page.enrollmentURL = devicemgtProps.enrollmentURL; page.enrollmentURL = devicemgtProps.enrollmentURL;
page.device_count = deviceModule.getDevicesCount(); page.device_count = deviceModule.getDevicesCount();
page.group_count = groupModule.getGroupCount(); //TODO: Enable Group Management Service API on CDMF
page.user_count = userModule.getUsers()["content"].length; //page.group_count = groupModule.getGroupCount();
page.policy_count = policyModule.getAllPolicies()["content"].length; page.group_count = -1;
page.role_count = userModule.getRoles()["content"].length; page.user_count = userModule.getUsersCount();
page.policy_count = policyModule.getPoliciesCount();
page.role_count = userModule.getRolesCount();
return page; return page;
} }
Loading…
Cancel
Save