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;
} }
); );

@ -79,14 +79,14 @@ policyModule = function () {
policyObjectToView["status"] = "Active/Updated"; policyObjectToView["status"] = "Active/Updated";
isUpdated = true; isUpdated = true;
} else if (policyObjectFromRestEndpoint["active"] == true && } else if (policyObjectFromRestEndpoint["active"] == true &&
policyObjectFromRestEndpoint["updated"] == false) { policyObjectFromRestEndpoint["updated"] == false) {
policyObjectToView["status"] = "Active"; policyObjectToView["status"] = "Active";
} else if (policyObjectFromRestEndpoint["active"] == false && } else if (policyObjectFromRestEndpoint["active"] == false &&
policyObjectFromRestEndpoint["updated"] == true) { policyObjectFromRestEndpoint["updated"] == true) {
policyObjectToView["status"] = "Inactive/Updated"; policyObjectToView["status"] = "Inactive/Updated";
isUpdated = true; isUpdated = true;
} else if (policyObjectFromRestEndpoint["active"] == false && } else if (policyObjectFromRestEndpoint["active"] == false &&
policyObjectFromRestEndpoint["updated"] == false) { policyObjectFromRestEndpoint["updated"] == false) {
policyObjectToView["status"] = "Inactive"; policyObjectToView["status"] = "Inactive";
} }
// push view-objects to list // push view-objects to list
@ -131,13 +131,39 @@ policyModule = function () {
} }
try { try {
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/policies?offset=0&limit=100"; "/policies?offset=0&limit=100";
return serviceInvokers.XMLHttp.get(url, privateMethods.handleGetAllPoliciesResponse); return serviceInvokers.XMLHttp.get(url, privateMethods.handleGetAllPoliciesResponse);
} catch (e) { } catch (e) {
throw e; throw e;
} }
}; };
/*
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
*/ */

@ -59,17 +59,17 @@ var userModule = function () {
privateMethods.callBackend = function (url, method) { privateMethods.callBackend = function (url, method) {
if (constants["HTTP_GET"] == method) { if (constants["HTTP_GET"] == method) {
return serviceInvokers.XMLHttp.get(url, return serviceInvokers.XMLHttp.get(url,
function (backendResponse) { function (backendResponse) {
var response = {}; var response = {};
response.content = backendResponse.responseText; response.content = backendResponse.responseText;
if (backendResponse.status == 200) { if (backendResponse.status == 200) {
response.status = "success"; response.status = "success";
} else if (backendResponse.status == 400 || backendResponse.status == 401 || } else if (backendResponse.status == 400 || backendResponse.status == 401 ||
backendResponse.status == 404 || backendResponse.status == 500) { backendResponse.status == 404 || backendResponse.status == 500) {
response.status = "error"; response.status = "error";
} }
return response; return response;
} }
); );
} else { } else {
log.error("Runtime error : This method only support HTTP GET requests."); log.error("Runtime error : This method only support HTTP GET requests.");
@ -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
@ -151,7 +180,7 @@ var userModule = function () {
try { try {
utility.startTenantFlow(carbonUser); utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
encodeURIComponent(username); encodeURIComponent(username);
var response = privateMethods.callBackend(url, constants["HTTP_GET"]); var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
response["content"] = parse(response.content); response["content"] = parse(response.content);
response["userDomain"] = carbonUser.domain; response["userDomain"] = carbonUser.domain;
@ -173,7 +202,7 @@ var userModule = function () {
try { try {
utility.startTenantFlow(carbonUser); utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
encodeURIComponent(username) + "/roles"; encodeURIComponent(username) + "/roles";
var response = privateMethods.callBackend(url, constants["HTTP_GET"]); var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") { if (response.status == "success") {
response.content = parse(response.content).roles; response.content = parse(response.content).roles;
@ -223,7 +252,7 @@ var userModule = function () {
try { try {
utility.startTenantFlow(carbonUser); utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles?offset=0&limit=100"; "/roles?offset=0&limit=100";
var response = privateMethods.callBackend(url, constants["HTTP_GET"]); var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") { if (response.status == "success") {
response.content = parse(response.content).roles; response.content = parse(response.content).roles;
@ -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
*/ */
@ -253,7 +312,7 @@ var userModule = function () {
try { try {
utility.startTenantFlow(carbonUser); utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles?user-store=" + userStore + "&limit=100"; "/roles?user-store=" + userStore + "&limit=100";
var response = privateMethods.callBackend(url, constants["HTTP_GET"]); var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") { if (response.status == "success") {
response.content = parse(response.content).roles; response.content = parse(response.content).roles;
@ -270,7 +329,7 @@ var userModule = function () {
* Get Platforms. * Get Platforms.
* @deprecated moved this device module under getDeviceTypes. * @deprecated moved this device module under getDeviceTypes.
*/ */
//TODO Move this piece of logic out of user.js to somewhere else appropriate. //TODO Move this piece of logic out of user.js to somewhere else appropriate.
publicMethods.getPlatforms = function () { publicMethods.getPlatforms = function () {
var carbonUser = session.get(constants["USER_SESSION_KEY"]); var carbonUser = session.get(constants["USER_SESSION_KEY"]);
var utility = require("/app/modules/utility.js")["utility"]; var utility = require("/app/modules/utility.js")["utility"];
@ -306,7 +365,7 @@ var userModule = function () {
try { try {
utility.startTenantFlow(carbonUser); utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles/" + encodeURIComponent(roleName); "/roles/" + encodeURIComponent(roleName);
var response = privateMethods.callBackend(url, constants["HTTP_GET"]); var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") { if (response.status == "success") {
response.content = parse(response.content); response.content = parse(response.content);

@ -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