|
|
|
@ -59,17 +59,17 @@ var userModule = function () {
|
|
|
|
|
privateMethods.callBackend = function (url, method) {
|
|
|
|
|
if (constants["HTTP_GET"] == method) {
|
|
|
|
|
return serviceInvokers.XMLHttp.get(url,
|
|
|
|
|
function (backendResponse) {
|
|
|
|
|
var response = {};
|
|
|
|
|
response.content = backendResponse.responseText;
|
|
|
|
|
if (backendResponse.status == 200) {
|
|
|
|
|
response.status = "success";
|
|
|
|
|
} else if (backendResponse.status == 400 || backendResponse.status == 401 ||
|
|
|
|
|
backendResponse.status == 404 || backendResponse.status == 500) {
|
|
|
|
|
response.status = "error";
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
function (backendResponse) {
|
|
|
|
|
var response = {};
|
|
|
|
|
response.content = backendResponse.responseText;
|
|
|
|
|
if (backendResponse.status == 200) {
|
|
|
|
|
response.status = "success";
|
|
|
|
|
} else if (backendResponse.status == 400 || backendResponse.status == 401 ||
|
|
|
|
|
backendResponse.status == 404 || backendResponse.status == 500) {
|
|
|
|
|
response.status = "error";
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
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
|
|
|
|
|
* @param username
|
|
|
|
@ -151,7 +180,7 @@ var userModule = function () {
|
|
|
|
|
try {
|
|
|
|
|
utility.startTenantFlow(carbonUser);
|
|
|
|
|
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
|
|
|
|
|
encodeURIComponent(username);
|
|
|
|
|
encodeURIComponent(username);
|
|
|
|
|
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
|
|
|
|
response["content"] = parse(response.content);
|
|
|
|
|
response["userDomain"] = carbonUser.domain;
|
|
|
|
@ -173,7 +202,7 @@ var userModule = function () {
|
|
|
|
|
try {
|
|
|
|
|
utility.startTenantFlow(carbonUser);
|
|
|
|
|
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
|
|
|
|
|
encodeURIComponent(username) + "/roles";
|
|
|
|
|
encodeURIComponent(username) + "/roles";
|
|
|
|
|
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
|
|
|
|
if (response.status == "success") {
|
|
|
|
|
response.content = parse(response.content).roles;
|
|
|
|
@ -223,7 +252,7 @@ var userModule = function () {
|
|
|
|
|
try {
|
|
|
|
|
utility.startTenantFlow(carbonUser);
|
|
|
|
|
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"]);
|
|
|
|
|
if (response.status == "success") {
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
@ -253,7 +312,7 @@ var userModule = function () {
|
|
|
|
|
try {
|
|
|
|
|
utility.startTenantFlow(carbonUser);
|
|
|
|
|
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"]);
|
|
|
|
|
if (response.status == "success") {
|
|
|
|
|
response.content = parse(response.content).roles;
|
|
|
|
@ -270,7 +329,7 @@ var userModule = function () {
|
|
|
|
|
* Get Platforms.
|
|
|
|
|
* @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 () {
|
|
|
|
|
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
|
|
|
|
var utility = require("/app/modules/utility.js")["utility"];
|
|
|
|
@ -306,7 +365,7 @@ var userModule = function () {
|
|
|
|
|
try {
|
|
|
|
|
utility.startTenantFlow(carbonUser);
|
|
|
|
|
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
|
|
|
|
|
"/roles/" + encodeURIComponent(roleName);
|
|
|
|
|
"/roles/" + encodeURIComponent(roleName);
|
|
|
|
|
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
|
|
|
|
if (response.status == "success") {
|
|
|
|
|
response.content = parse(response.content);
|
|
|
|
|