Skip to content
Snippets Groups Projects
Commit 6dede0ce authored by Sebastian Listl's avatar Sebastian Listl :speech_balloon:
Browse files

Workflow webservices workaround considering corrupt calls

(cherry picked from commit 42eda3a7)
parent 59462d94
No related branches found
No related tags found
No related merge requests found
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) : [];
......
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);
......
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 || "[]";
......
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);
......
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment