Fixing EMM-EMM-1753

merge-requests/7/head
kamidu 8 years ago
parent 790ca36443
commit bfc04a7f16

@ -39,7 +39,7 @@ var userModule = function () {
* Get the carbon user object from the session. If not found - it will throw a user not found error. * Get the carbon user object from the session. If not found - it will throw a user not found error.
* @returns {object} carbon user object * @returns {object} carbon user object
*/ */
privateMethods.getCarbonUser = function () { publicMethods.getCarbonUser = function () {
var carbon = require("carbon"); var carbon = require("carbon");
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"];
@ -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.");
@ -176,7 +176,7 @@ var userModule = function () {
* @returns {object} a response object with status and content on success. * @returns {object} a response object with status and content on success.
*/ */
publicMethods.getUser = function (username) { publicMethods.getUser = function (username) {
var carbonUser = privateMethods.getCarbonUser(); var carbonUser = publicMethods.getCarbonUser();
var domain; var domain;
if (username.indexOf('/') > 0) { if (username.indexOf('/') > 0) {
domain = username.substr(0, username.indexOf('/')); domain = username.substr(0, username.indexOf('/'));
@ -185,7 +185,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);
if (domain) { if (domain) {
url += '?domain=' + domain; url += '?domain=' + domain;
} }
@ -206,7 +206,7 @@ var userModule = function () {
* @returns {object} a response object with status and content on success. * @returns {object} a response object with status and content on success.
*/ */
publicMethods.getRolesByUsername = function (username) { publicMethods.getRolesByUsername = function (username) {
var carbonUser = privateMethods.getCarbonUser(); var carbonUser = publicMethods.getCarbonUser();
var domain; var domain;
if (username.indexOf('/') > 0) { if (username.indexOf('/') > 0) {
domain = username.substr(0, username.indexOf('/')); domain = username.substr(0, username.indexOf('/'));
@ -215,7 +215,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";
if (domain) { if (domain) {
url += '?domain=' + domain; url += '?domain=' + domain;
} }
@ -268,7 +268,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;
@ -294,7 +294,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=1"; "/roles?offset=0&limit=1";
return serviceInvokers.XMLHttp.get( return serviceInvokers.XMLHttp.get(
url, function (responsePayload) { url, function (responsePayload) {
return parse(responsePayload["responseText"])["count"]; return parse(responsePayload["responseText"])["count"];
@ -328,7 +328,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;
@ -381,7 +381,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);

Loading…
Cancel
Save