From 1bc11702a5e89cf7b167e036b75314185c01cc17 Mon Sep 17 00:00:00 2001 From: "m.lettere" Date: Thu, 30 May 2024 21:40:53 +0200 Subject: [PATCH] refactored to use exact and briefRepresentation for users --- defaults/main.yaml | 4 ++-- templates/user-group_created.json.j2 | 17 +++-------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/defaults/main.yaml b/defaults/main.yaml index b2aa8a6..c9edb93 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -2,12 +2,12 @@ workflows: # - create-user-add-to-vre # - group_deleted - # - user-group_created + - user-group_created # - user-group-role_created # - group_created # - invitation-accepted # - user-group_deleted - - user-group-role_deleted + # - user-group-role_deleted # - delete-user-account # - keycloak_delete_account # - role_deleted diff --git a/templates/user-group_created.json.j2 b/templates/user-group_created.json.j2 index 0df985a..7d195a3 100644 --- a/templates/user-group_created.json.j2 +++ b/templates/user-group_created.json.j2 @@ -42,7 +42,7 @@ "taskReferenceName" : "lookup_user", "type" : "SIMPLE", "inputParameters" : { - "url" : "${init.input.keycloak_admin}/users?username=${workflow.input.user}", + "url" : "${init.input.keycloak_admin}/users?username=${workflow.input.user}&exact=true&briefRepresentation=true", "method" : "GET", "headers" : { "Authorization" : "Bearer ${authorize.output.body.access_token}", @@ -50,22 +50,11 @@ } } }, - { - "name": "INLINE_TASK", - "taskReferenceName": "select_user", - "inputParameters": { - "foundusers": "${lookup_user.output.body}", - "username": "${workflow.input.user}", - "evaluatorType" : "javascript", - "expression": "function f(){for(var i=0; i < $.foundusers.length;i++){if($.foundusers[i]['username'] == $.username) return $.foundusers[i]}} f()" - }, - "type": "INLINE" - }, { "name": "check_user_existance", "taskReferenceName": "check_user_existance", "inputParameters": { - "user": "${select_user.output.result}" + "user": "${lookup_user.output.body[0]}" }, "type": "SWITCH", "evaluatorType" : "javascript", @@ -122,7 +111,7 @@ "taskReferenceName" : "assign_user_to_group", "type" : "SIMPLE", "inputParameters" : { - "url" : "${init.input.keycloak_admin}/users/${select_user.output.result.id}/groups/${extract_group.output.result.group.id}", + "url" : "${init.input.keycloak_admin}/users/${lookup_user.output.body[0].id}/groups/${extract_group.output.result.group.id}", "method" : "PUT", "headers" : { "Authorization" : "Bearer ${authorize.output.body.access_token}"