diff --git a/process/workflowDeploy_rest/process.js b/process/workflowDeploy_rest/process.js index 82c3ed4a98aedf4504ec4d250b36a6d6f4e19f90..4b5a9c33f2b5ad99d586be23daac221fcfbeda08 100644 --- a/process/workflowDeploy_rest/process.js +++ b/process/workflowDeploy_rest/process.js @@ -1,3 +1,4 @@ +import("Workflow_lib"); import("system.workflow"); import("system.util"); @@ -6,7 +7,7 @@ function restpost (pRequest) var request = JSON.parse(pRequest); var processObj = JSON.parse(util.decodeBase64String(request.body)); - if (processObj && processObj.processXML) + if (processObj && processObj.processXML && WorkflowUtils.engineIsEnabled()) { var processIds = workflow.getProcessIds(processObj.processXML); processIds = processIds != null ? JSON.parse(processIds) : []; diff --git a/process/workflowRoles_rest/process.js b/process/workflowRoles_rest/process.js index dd60527468bec7b763a4a8a0b94fea46c88350c8..360a7522eaa827f434f49489f5111cab7f45495c 100644 --- a/process/workflowRoles_rest/process.js +++ b/process/workflowRoles_rest/process.js @@ -1,82 +1,102 @@ +import("Workflow_lib"); import("system.text"); import("system.tools"); function restget (pRequest) { - var request = JSON.parse(pRequest); + //Workaround for handling corrupt json. Remove when the json problem is fixed. + var request; + try + { + request = JSON.parse(pRequest); + } + catch (err) + { + pRequest = pRequest.replace(/"value"\s*?:\s*?"(\{\s*?".+?\})"/, function (foundStr, unescapedJson) + { + return '"value":"' + unescapedJson.replace(/"/g, '\\"') + '"'; + }); + request = JSON.parse(pRequest); + } + var header = request.header; var roleIds = header.Ids && JSON.parse(header.Ids); var userId = header.Userid; - if (userId) - { - //if a userId is present, get only the roles of that user - let user = tools.getUserByAttribute(tools.NAME, userId); - roleIds = user ? user[tools.ROLENAMES].slice() : []; - } + var roles = []; - var roles = tools.getAllRoles([tools.ROLE_PROJECT, tools.ROLE_CUSTOM], false); - roles = Object.keys(roles).map(function (role) + if (WorkflowUtils.engineIsEnabled()) { - var [title, type, desc, id] = roles[role]; - return { - name : title, - id : id, - type : type - }; - }); - - //object for handling filtering - var filter = { - EQUAL : "equal", - IGNORECASE : "ignoreCase", - IN : "in", - LIKE : "like", - LIKEIGNORECASE : "likeIgnoreCase", - - _filters : [], - addIfSet : function (pUserPropertyName, pFilterValue, pType) - { - if (pFilterValue && pFilterValue.length !== 0) - this.add(pUserPropertyName, pFilterValue, pType); - }, - add : function (pUserPropertyName, pFilterValue, pType) + if (userId) { - this._filters.push([pUserPropertyName, pFilterValue, pType]); - }, - check : function (pUser) + //if a userId is present, get only the roles of that user + let user = tools.getUserByAttribute(tools.NAME, userId); + roleIds = user ? user[tools.ROLENAMES].slice() : []; + } + + roles = tools.getAllRoles([tools.ROLE_PROJECT, tools.ROLE_CUSTOM], false); + roles = Object.keys(roles).map(function (role) { - return this._filters.every(function ([prop, value, type]) + var [title, type, desc, id] = roles[role]; + return { + name : title, + id : id, + type : type + }; + }); + + //object for handling filtering + var filter = { + EQUAL : "equal", + IGNORECASE : "ignoreCase", + IN : "in", + LIKE : "like", + LIKEIGNORECASE : "likeIgnoreCase", + + _filters : [], + addIfSet : function (pUserPropertyName, pFilterValue, pType) { - let userValue = pUser[prop] || ""; - let flags; - switch (type) + if (pFilterValue && pFilterValue.length !== 0) + this.add(pUserPropertyName, pFilterValue, pType); + }, + add : function (pUserPropertyName, pFilterValue, pType) + { + this._filters.push([pUserPropertyName, pFilterValue, pType]); + }, + check : function (pUser) + { + return this._filters.every(function ([prop, value, type]) { - case this.EQUAL: - return userValue == value; - case this.IGNORECASE: - return userValue.toUpperCase() == value.toUpperCase(); - case this.IN: - return value.indexOf(userValue) !== -1; - case this.LIKEIGNORECASE: - flags = "i"; - case this.LIKE: - value = text.replaceAll(value, {"%" : ".*", "_" : "."}); - return new RegExp(value, flags).test(userValue); - } - return false; - }, this); - } - }; - - //add the filters of the request to the filter object - filter.addIfSet("id", header.Id, filter.EQUAL); - filter.addIfSet("id", roleIds, filter.IN); - filter.addIfSet("name", header.Name, filter.EQUAL); - filter.addIfSet("name", header.Namelike, filter.LIKE); - filter.addIfSet("name", header.Namelikeignorecase, filter.LIKEIGNORECASE); - - roles = roles.filter(filter.check, filter); //do the filtering + let userValue = pUser[prop] || ""; + let flags; + switch (type) + { + case this.EQUAL: + return userValue == value; + case this.IGNORECASE: + return userValue.toUpperCase() == value.toUpperCase(); + case this.IN: + return value.indexOf(userValue) !== -1; + case this.LIKEIGNORECASE: + flags = "i"; + case this.LIKE: + value = text.replaceAll(value, {"%" : ".*", "_" : "."}); + return new RegExp(value, flags).test(userValue); + } + return false; + }, this); + } + }; + + //add the filters of the request to the filter object + filter.addIfSet("id", header.Id, filter.EQUAL); + filter.addIfSet("id", roleIds, filter.IN); + filter.addIfSet("name", header.Name, filter.EQUAL); + filter.addIfSet("name", header.Namelike, filter.LIKE); + filter.addIfSet("name", header.Namelikeignorecase, filter.LIKEIGNORECASE); + + roles = roles.filter(filter.check, filter); //do the filtering + } request.response.body = JSON.stringify(roles); diff --git a/process/workflowServiceTaskParams_rest/process.js b/process/workflowServiceTaskParams_rest/process.js index 15f2084ec4d54ef90ec3c8234dd434249fd9a416..529fdbf1cdd8ce6be48c6d209fa785452b504664 100644 --- a/process/workflowServiceTaskParams_rest/process.js +++ b/process/workflowServiceTaskParams_rest/process.js @@ -1,8 +1,23 @@ +import("Workflow_lib"); import("system.workflow"); function restget (pRequest) { - var request = JSON.parse(pRequest); + //Workaround for handling corrupt json. Remove when the json problem is fixed. + var request; + try + { + request = JSON.parse(pRequest); + } + catch (err) + { + pRequest = pRequest.replace(/"value"\s*?:\s*?"(\{\s*?".+?\})"/, function (foundStr, unescapedJson) + { + return '"value":"' + unescapedJson.replace(/"/g, '\\"') + '"'; + }); + request = JSON.parse(pRequest); + } + var jditoProcess = request.header.Jditoprocess; /* this is an object containing the values currently set in the modeler, it looks like this: @@ -12,7 +27,9 @@ function restget (pRequest) * } */ var currentValues = request.header.Currentvalues; - var parameters = workflow.getServiceTaskParameters(jditoProcess, currentValues); + var parameters = jditoProcess && WorkflowUtils.engineIsEnabled() + ? workflow.getServiceTaskParameters(jditoProcess, currentValues) + : null; request.response.body = parameters || "[]"; diff --git a/process/workflowServiceTasks_rest/process.js b/process/workflowServiceTasks_rest/process.js index 470717e7e185c7c7af401533042bcac29582bee1..0831b230247a2dae697df15869bf9613519ade48 100644 --- a/process/workflowServiceTasks_rest/process.js +++ b/process/workflowServiceTasks_rest/process.js @@ -1,3 +1,4 @@ +import("Workflow_lib"); import("Sql_lib"); import("system.project"); import("system.process"); @@ -5,15 +6,19 @@ import("system.process"); function restget (pRequest) { var request = JSON.parse(pRequest); + var serviceTasks = []; - var serviceTaskNames = process.getProcesses([process.VARIANT_WORKFLOW]); - var serviceTasks = project.getDataModels(project.DATAMODEL_KIND_PROCESS, serviceTaskNames).map(function (row) + if (WorkflowUtils.engineIsEnabled()) { - return { - id : row[0], - name : row[1] || row[0] - }; - }); + var serviceTaskNames = process.getProcesses([process.VARIANT_WORKFLOW]); + serviceTasks = project.getDataModels(project.DATAMODEL_KIND_PROCESS, serviceTaskNames).map(function (row) + { + return { + id : row[0], + name : row[1] || row[0] + }; + }); + } request.response.body = JSON.stringify(serviceTasks); diff --git a/process/workflowUsers_rest/process.js b/process/workflowUsers_rest/process.js index 99246ce894bff9755188ae39982a98d885d8eee5..c9368b9006e371c6c0ab80ab006a83b3d9a33a47 100644 --- a/process/workflowUsers_rest/process.js +++ b/process/workflowUsers_rest/process.js @@ -1,3 +1,4 @@ +import("Workflow_lib"); import("system.text"); import("system.vars"); import("system.logging"); @@ -10,7 +11,21 @@ function restget (pRequest) //minimum required length of the search pattern const MIN_SEARCHLENGTH = 0; - var request = JSON.parse(pRequest); + //Workaround for handling corrupt json. Remove when the json problem is fixed. + var request; + try + { + request = JSON.parse(pRequest); + } + catch (err) + { + pRequest = pRequest.replace(/"value"\s*?:\s*?"(\{\s*?".+?\})"/, function (foundStr, unescapedJson) + { + return '"value":"' + unescapedJson.replace(/"/g, '\\"') + '"'; + }); + request = JSON.parse(pRequest); + } + var header = request.header; var userFilter = header.Userfilter ? JSON.parse(header.Userfilter) @@ -95,7 +110,7 @@ function restget (pRequest) function _getUsers (pSearch) { //empty result if the search value does not have the minimal required length - if (pSearch !== undefined && pSearch.trim() < MIN_SEARCHLENGTH) + if ((pSearch !== undefined && pSearch.trim() < MIN_SEARCHLENGTH) || !WorkflowUtils.engineIsEnabled()) return []; //if the search value contains spaces, it will be split into individual words, every word must be found