use group-by-path to avoid searching and filtering by hand

This commit is contained in:
Marco Lettere 2024-06-21 12:54:18 +02:00
parent b2ba5d3674
commit f2149e680d
1 changed files with 4 additions and 15 deletions

View File

@ -17,7 +17,7 @@
"user" : "${workflow.input.user}",
"group" : "${workflow.input.group}",
"evaluatorType" : "javascript",
"expression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; if(e($.user) || e($.group)) throw('User and Group must not be empty'); function f(){ var path = $.group.startsWith('%2F') ? $.group.split('%2F').slice(1) : [$.group]; return { 'tree' : Java.to(path, 'java.lang.String[]'), 'name' : path.slice(path.length-1)[0], 'search' : encodeURIComponent(path.slice(path.length-1)[0])}} f()"
"expression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; if(e($.user) || e($.group)) throw('User and Group must not be empty'); function f(){ var path = $.group.startsWith('%2F') ? $.group.split('%2F').slice(1) : [$.group]; return { 'path' : path.join('/'), 'name' : path.slice(path.length-1)[0], 'search' : encodeURIComponent(path.slice(path.length-1)[0])}} f()"
}
},
{
@ -63,23 +63,12 @@
"taskReferenceName" : "look_up_groups",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/groups?search=${init.output.result.search}",
"url" : "${init.input.keycloak_admin}/group-by-path/${init.output.result.path}",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json"
}
}
},
{
"name": "INLINE_TASK",
"taskReferenceName": "extract_group",
"type": "INLINE",
"inputParameters": {
"tree" : "${init.output.result.tree}",
"groups" : "${look_up_groups.output.body}",
"expression": "function selectByPath(groups, path, level) { for (var i=0; i < groups.length; i++) {if (groups[i].name === path[level]) {if (level === path.length - 1) return groups[i];return selectByPath(groups[i].subGroups, path, level+1)}} return null; } function f() { return { 'group' : selectByPath($.groups, $.tree, 0)}} f()",
"evaluatorType" : "javascript"
}
}
]
]
@ -95,7 +84,7 @@
"taskReferenceName": "check_user_group_existance",
"inputParameters": {
"user": "${lookup_fork_join.output.lookup_user.body[0]}",
"group" : "${lookup_fork_join.output.extract_group.result.group}"
"group" : "${lookup_fork_join.output.lookup_group.body.id}"
},
"type": "SWITCH",
"evaluatorType" : "javascript",
@ -107,7 +96,7 @@
"taskReferenceName" : "assign_user_to_group",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/users/${lookup_fork_join.output.lookup_user.body[0].id}/groups/${lookup_fork_join.output.extract_group.result.group.id}",
"url" : "${init.input.keycloak_admin}/users/${lookup_fork_join.output.lookup_user.body[0].id}/groups/${lookup_fork_join.output.lookup_group.body.id}",
"method" : "PUT",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}"