From ea9cecb070a8d2d160509335b5fe4bbca47231d6 Mon Sep 17 00:00:00 2001 From: dcore94 Date: Tue, 23 Mar 2021 11:03:43 +0100 Subject: [PATCH] added email notifications --- defaults/main.yaml | 1 + templates/delete-user-account.json.j2 | 387 +++++++++++++++----------- 2 files changed, 221 insertions(+), 167 deletions(-) diff --git a/defaults/main.yaml b/defaults/main.yaml index e84bb89..eabae28 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -17,3 +17,4 @@ keycloak_auth: "c93501bd-abeb-4228-bc28-afac38877338" keycloak_auth_master: "7a64deb5-e8ea-4add-ba8d-26b339994cc9" liferay: "https://next.d4science.org/api/jsonws" liferay_auth: "bm90aWZpY2F0aW9uc0BkNHNjaWVuY2Uub3JnOmdjdWJlcmFuZG9tMzIx" +root_vo: "%2Fgcube" diff --git a/templates/delete-user-account.json.j2 b/templates/delete-user-account.json.j2 index 8d1481a..e23fed6 100644 --- a/templates/delete-user-account.json.j2 +++ b/templates/delete-user-account.json.j2 @@ -7,175 +7,228 @@ "ownerEmail" : "m.lettere@gmail.com", "inputParameters" : [ "userid" ], "tasks" : [ - { - "name": "LAMBDA_TASK", - "taskReferenceName": "init", - "type": "LAMBDA", - "inputParameters": { - "keycloak": "{{ keycloak }}/${workflow.input.realm}", - "keycloak_admin" : "{{ keycloak_admin }}/${workflow.input.realm}", - "liferay": "{{ liferay }}", - "liferay_auth": "{{ liferay_auth }}", - "keycloak_userid" : "${workflow.input.userid}", - "scriptExpression": "1 == 1" - } + { + "name": "LAMBDA_TASK", + "taskReferenceName": "init", + "type": "LAMBDA", + "inputParameters": { + "root_vo": "{{ root_vo }}", + "keycloak": "{{ keycloak }}/${workflow.input.realm}", + "keycloak_admin" : "{{ keycloak_admin }}/${workflow.input.realm}", + "liferay": "{{ liferay }}", + "liferay_auth": "{{ liferay_auth }}", + "keycloak_userid" : "${workflow.input.userid}", + "scriptExpression": "1 == 1" + } }, - { - "name" : "pyrest", - "taskReferenceName" : "authorize", - "type" : "SIMPLE", - "inputParameters" : { - "url" : "${init.input.keycloak}/protocol/openid-connect/token", - "method" : "POST", - "headers" : { - "Accept" : "application/json" - }, - "body" : { - "client_id" : "orchestrator", - "client_secret" : "{{ keycloak_auth }}", - "grant_type" : "client_credentials" - } - } - }, - { - "name" : "pyrest", - "taskReferenceName" : "lookup_user", - "type" : "SIMPLE", - "inputParameters" : { - "url" : "${init.input.keycloak_admin}/users/${init.input.keycloak_userid}", - "method" : "GET", - "headers" : { - "Authorization" : "Bearer ${authorize.output.body.access_token}", - "Accept" : "application/json" - } - } - }, - { - "name" : "fork_join", - "taskReferenceName" : "global_delete_user", - "type" : "FORK_JOIN", - "forkTasks" : [ - [ - { - "name" : "pyrest", - "taskReferenceName" : "lookup_lr_company", - "type" : "SIMPLE", - "inputParameters" : { - "url" : "${init.input.liferay}/company/get-company-by-web-id", - "method" : "GET", - "params" : { "webId" : "liferay.com"}, - "headers" : { - "Authorization" : "Basic ${init.input.liferay_auth}", - "Accept" : "application/json" - } - } - }, - { - "name" : "pyrest", - "taskReferenceName" : "lookup_lr_user_by_screenname", - "type" : "SIMPLE", - "inputParameters" : { - "url" : "${init.input.liferay}/user/get-user-by-screen-name", - "method" : "GET", - "params" : { - "companyId" : "${lookup_lr_company.output.body.companyId}", - "screenName" : "${lookup_user.output.body.username}" - }, - "headers" : { - "Authorization" : "Basic ${init.input.liferay_auth}", - "Accept" : "application/json" - } - } - }, - { - "name" : "pyrest", - "taskReferenceName" : "lookup_lr_user_groups", - "type" : "SIMPLE", - "inputParameters" : { - "url" : "${init.input.liferay}/group/get-user-sites-groups", - "method" : "GET", - "params" : { - "classNames" : "[\"com.liferay.portal.model.Group\"]", - "userId" : "${lookup_lr_user_by_screenname.output.body.userId}", - "max" : "-1" - }, - "headers" : { - "Authorization" : "Basic ${init.input.liferay_auth}", - "Accept" : "application/json" - } - } - }, - { - "name": "LAMBDA_TASK", - "taskReferenceName": "build_delete_group_tasks", - "type": "LAMBDA", - "inputParameters": { - "groups" : "${lookup_lr_user_groups.output.body.*.groupId}", - "userId" : "${lookup_lr_user_by_screenname.output.body.userId}", - "scriptExpression": "inputs = {}; tasks = []; for(var i=0;i<$.groups.length;i++){tasks.push({'name': 'pyrest','type' : 'SIMPLE','taskReferenceName' : 'del-' + i});inputs['del-'+i] = {'url' : '${init.input.liferay}/user/unset-group-users?userIds=' + $.userId + '&groupId=' + $.groups[i],'method' : 'POST','headers' : {'Authorization' : 'Basic ' + '${init.input.liferay_auth}', 'Accept' : 'application/json'}}}; return { 'tasks' : Java.to(tasks, 'java.util.Map[]'), 'inputs' : inputs};" - } - }, - { - "name" : "fork_dynamic", - "type" : "FORK_JOIN_DYNAMIC", - "taskReferenceName" : "parallel_delete_group", - "inputParameters" : { - "tasks" : "${build_delete_group_tasks.output.result.tasks}", - "inputs" : "${build_delete_group_tasks.output.result.inputs}" - }, - "dynamicForkTasksParam": "tasks", - "dynamicForkTasksInputParamName": "inputs" - }, - { - "name" : "join", - "type" : "JOIN", - "taskReferenceName" : "join_parallel_group_deletion" - }, - { - "name" : "pyrest", - "taskReferenceName" : "delete_lr_user", - "type" : "SIMPLE", - "inputParameters" : { - "url" : "${init.input.liferay}/user/delete-user", - "method" : "POST", - "params" : { - "userId" : "${lookup_lr_user_by_screenname.output.body.userId}" - }, - "headers" : { - "Authorization" : "Basic ${init.input.liferay_auth}", - "Accept" : "application/json" - } - } - }, - { - "name": "LAMBDA_TASK", - "taskReferenceName": "lr_final_task", - "type": "LAMBDA", - "inputParameters" : { - "scriptExpression" : "1 == 1" - } - } - ] - ] - }, - { - "name" : "join", - "type" : "JOIN", - "taskReferenceName" : "global_delete_user_join", - "joinOn": [ "lr_final_task"] - }, - { - "name" : "pyrest", - "taskReferenceName" : "delete_keycloak_user", - "type" : "SIMPLE", - "inputParameters" : { - "url" : "${init.input.keycloak_admin}/users/${init.input.keycloak_userid}", - "method" : "DELETE", - "headers" : { - "Authorization" : "Bearer ${authorize.output.body.access_token}", - "Accept" : "application/json" - } + { + "name" : "pyrest", + "taskReferenceName" : "authorize", + "type" : "SIMPLE", + "inputParameters" : { + "url" : "${init.input.keycloak}/protocol/openid-connect/token", + "method" : "POST", + "headers" : { + "Accept" : "application/json" + }, + "body" : { + "client_id" : "orchestrator", + "client_secret" : "{{ keycloak_auth }}", + "grant_type" : "client_credentials" } } + }, + { + "name" : "pyrest", + "taskReferenceName" : "lookup_user", + "type" : "SIMPLE", + "inputParameters" : { + "url" : "${init.input.keycloak_admin}/users/${init.input.keycloak_userid}", + "method" : "GET", + "headers" : { + "Authorization" : "Bearer ${authorize.output.body.access_token}", + "Accept" : "application/json" + } + } + }, + { + "name" : "fork_join", + "taskReferenceName" : "global_delete_user", + "type" : "FORK_JOIN", + "forkTasks" : [ + [ + { + "name" : "pyrest", + "taskReferenceName" : "lookup_lr_company", + "type" : "SIMPLE", + "inputParameters" : { + "url" : "${init.input.liferay}/company/get-company-by-web-id", + "method" : "GET", + "params" : { "webId" : "liferay.com"}, + "headers" : { + "Authorization" : "Basic ${init.input.liferay_auth}", + "Accept" : "application/json" + } + } + }, + { + "name" : "pyrest", + "taskReferenceName" : "lookup_lr_user_by_screenname", + "type" : "SIMPLE", + "inputParameters" : { + "url" : "${init.input.liferay}/user/get-user-by-screen-name", + "method" : "GET", + "params" : { + "companyId" : "${lookup_lr_company.output.body.companyId}", + "screenName" : "${lookup_user.output.body.username}" + }, + "headers" : { + "Authorization" : "Basic ${init.input.liferay_auth}", + "Accept" : "application/json" + } + } + }, + { + "name" : "pyrest", + "taskReferenceName" : "lookup_lr_user_groups", + "type" : "SIMPLE", + "inputParameters" : { + "url" : "${init.input.liferay}/group/get-user-sites-groups", + "method" : "GET", + "params" : { + "classNames" : "[\"com.liferay.portal.model.Group\"]", + "userId" : "${lookup_lr_user_by_screenname.output.body.userId}", + "max" : "-1" + }, + "headers" : { + "Authorization" : "Basic ${init.input.liferay_auth}", + "Accept" : "application/json" + } + } + }, + { + "name": "LAMBDA_TASK", + "taskReferenceName": "build_delete_group_tasks", + "type": "LAMBDA", + "inputParameters": { + "groups" : "${lookup_lr_user_groups.output.body.*.groupId}", + "userId" : "${lookup_lr_user_by_screenname.output.body.userId}", + "scriptExpression": "inputs = {}; tasks = []; for(var i=0;i<$.groups.length;i++){tasks.push({'name': 'pyrest','type' : 'SIMPLE','taskReferenceName' : 'del-' + i});inputs['del-'+i] = {'url' : '${init.input.liferay}/user/unset-group-users?userIds=' + $.userId + '&groupId=' + $.groups[i],'method' : 'POST','headers' : {'Authorization' : 'Basic ' + '${init.input.liferay_auth}', 'Accept' : 'application/json'}}}; return { 'tasks' : Java.to(tasks, 'java.util.Map[]'), 'inputs' : inputs};" + } + }, + { + "name" : "fork_dynamic", + "type" : "FORK_JOIN_DYNAMIC", + "taskReferenceName" : "parallel_delete_group", + "inputParameters" : { + "tasks" : "${build_delete_group_tasks.output.result.tasks}", + "inputs" : "${build_delete_group_tasks.output.result.inputs}" + }, + "dynamicForkTasksParam": "tasks", + "dynamicForkTasksInputParamName": "inputs" + }, + { + "name" : "join", + "type" : "JOIN", + "taskReferenceName" : "join_parallel_group_deletion" + }, + { + "name" : "pyrest", + "taskReferenceName" : "delete_lr_user", + "type" : "SIMPLE", + "inputParameters" : { + "url" : "${init.input.liferay}/user/delete-user", + "method" : "POST", + "params" : { + "userId" : "${lookup_lr_user_by_screenname.output.body.userId}" + }, + "headers" : { + "Authorization" : "Basic ${init.input.liferay_auth}", + "Accept" : "application/json" + } + } + }, + { + "name": "LAMBDA_TASK", + "taskReferenceName": "lr_final_task", + "type": "LAMBDA", + "inputParameters" : { + "scriptExpression" : "1 == 1" + } + } + ] + ], + [ + { + "name" : "pyrest", + "taskReferenceName" : "get_rootvo", + "type" : "SIMPLE", + "inputParameters" : { + "url" : "${init.input.keycloak_admin}/clients?clientId=${workflow.input.root_vo}", + "method" : "GET", + "headers" : { + "Authorization" : "Bearer ${authorize.output.body.access_token}", + "Accept" : "application/json" + } + } + }, + { + "name" : "pyrest", + "taskReferenceName" : "get_rootvo_roles", + "type" : "SIMPLE", + "inputParameters" : { + "url" : "${init.input.keycloak_admin}/clients/${get_rootvo.output.body[0].id}/roles", + "method" : "GET", + "headers" : { + "Authorization" : "Bearer ${authorize.output.body.access_token}", + "Accept" : "application/json" + } + } + }, + { + "name" : "pyrest", + "taskReferenceName" : "get_rootvo_infra_managers", + "type" : "SIMPLE", + "inputParameters" : { + "url" : "${init.input.keycloak_admin}/clients/${get_rootvo.output.body[0].id}/roles/Infrastructure-Manager/users", + "method" : "GET", + "headers" : { + "Authorization" : "Bearer ${authorize.output.body.access_token}", + "Accept" : "application/json" + } + } + } + ] + }, + { + "name" : "join", + "type" : "JOIN", + "taskReferenceName" : "global_delete_user_join", + "joinOn": [ "lr_final_task", "get_rootvo_inframanagers"] + }, + { + "name" : "pyrest", + "taskReferenceName" : "delete_keycloak_user", + "type" : "SIMPLE", + "inputParameters" : { + "url" : "${init.input.keycloak_admin}/users/${init.input.keycloak_userid}", + "method" : "DELETE", + "headers" : { + "Authorization" : "Bearer ${authorize.output.body.access_token}", + "Accept" : "application/json" + } + } + }, + { + "name" : "pymail", + "taskReferenceName" : "notify_infra_managers", + "type" : "SIMPLE", + "inputParameters" : { + "subject" : "User account REMOVAL notification", + "from" : "noreply@d4science.org", + "to" : "${get_rootvo_infra_managers.output.body.*.email}", + "html" : "

Dear ${workflow.input.root_vo} Infrastructure Manager,

${${lookup_user.output.body.firstName} ${lookup_user.output.body.lastName} (${lookup_user.output.body.username}) removed his/her account from the portal with the following email: ${lookup_user.output.body.email}

You received this email because you are an Infrastructure Manager.

WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, you are strictly prohibited from disclosing, distributing, copying, or in any way using this message. If you have received this communication in error, please notify the sender and destroy and delete any copies you may have received.

" + } + }, ] }