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