From d716abd938dffa771e486f74702f6aa782bee043 Mon Sep 17 00:00:00 2001 From: Jayaprakash8887 Date: Wed, 6 Dec 2023 17:40:30 +0530 Subject: [PATCH 1/5] Issue #LR-676 feat: Delete User API --- .../kafka/InstructionEventGenerator.java | 2 +- .../main/java/org/sunbird/keys/JsonKey.java | 2 +- .../user/UserDeletionBackgroundJobActor.java | 81 +++++++++++-------- 3 files changed, 49 insertions(+), 36 deletions(-) diff --git a/core/platform-common/src/main/java/org/sunbird/kafka/InstructionEventGenerator.java b/core/platform-common/src/main/java/org/sunbird/kafka/InstructionEventGenerator.java index de28930485..1cab8a175d 100644 --- a/core/platform-common/src/main/java/org/sunbird/kafka/InstructionEventGenerator.java +++ b/core/platform-common/src/main/java/org/sunbird/kafka/InstructionEventGenerator.java @@ -19,7 +19,7 @@ public class InstructionEventGenerator { private static String beJobRequesteventId = "BE_JOB_REQUEST"; private static int iteration = 1; - private static String actorId = "Sunbird LMS Samza Job"; + private static String actorId = "Sunbird LMS Flink Job"; private static String actorType = "System"; private static String pdataId = "org.sunbird.platform"; private static String pdataVersion = "1.0"; diff --git a/core/platform-common/src/main/java/org/sunbird/keys/JsonKey.java b/core/platform-common/src/main/java/org/sunbird/keys/JsonKey.java index 0d9b137b3e..7a07ea0205 100644 --- a/core/platform-common/src/main/java/org/sunbird/keys/JsonKey.java +++ b/core/platform-common/src/main/java/org/sunbird/keys/JsonKey.java @@ -671,7 +671,7 @@ public final class JsonKey { public static final String SUGGESTED_USERS = "suggested_users"; public static final String DELETE_USER_ACTON = "delete-user"; public static final String OBJECT = "object"; - public static final String EDATA = "eData"; + public static final String EDATA = "edata"; public static final String MANAGED_USERS = "managed_users"; public static final String USER_DELETION_TOPIC = "user-deletion-broadcast-topic"; public static final String USER_DELETION_ROLES = "user-deletion-roles"; diff --git a/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java b/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java index 0173b941e1..e1034ce68f 100644 --- a/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java +++ b/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java @@ -1,9 +1,6 @@ package org.sunbird.actor.user; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import org.sunbird.actor.core.BaseActor; import org.sunbird.common.ElasticSearchHelper; import org.sunbird.dto.SearchDTO; @@ -27,50 +24,31 @@ public void onReceive(Request request) throws Throwable { private void inputKafkaTopic(Request request) throws Exception { Map userDetails = request.getRequest(); String userId = (String) userDetails.get(JsonKey.USER_ID); - ArrayList roles = (ArrayList) userDetails.get(JsonKey.USER_ROLES); + ArrayList roles = (ArrayList) userDetails.get(JsonKey.USER_ROLES); logger.info("UserDeletionBackgroundJobActor::inputKafkaTopic:: userId:: " + userId); logger.info("UserDeletionBackgroundJobActor::inputKafkaTopic:: roles size:: " + roles.size()); User user = userService.getUserById(userId, request.getRequestContext()); String rootOrgId = user.getRootOrgId(); List> suggestedUsersList = new ArrayList<>(); - Map searchQueryMap = new HashMap<>(); - Map searchFilter = new HashMap<>(); - searchFilter.put(JsonKey.ROOT_ORG_ID, rootOrgId); if (!roles.isEmpty()) { - // for each role in the organisation, fetch list of other users to pass it as part of event - List queryFields = new ArrayList<>(); - queryFields.add(JsonKey.USER_ID); - searchQueryMap.put(JsonKey.FIELDS, queryFields); - logger.info("UserDeletionBackgroundJobActor::inputKafkaTopic:: roles size:: " + roles.size()); - roles.forEach( - role -> { - searchFilter.put(JsonKey.ROLES + "." + JsonKey.ROLE, role); - searchQueryMap.put(JsonKey.FILTERS, searchFilter); - SearchDTO searchDto = ElasticSearchHelper.createSearchDTO(searchQueryMap); - Map result = - userService.searchUser(searchDto, request.getRequestContext()); - List> userMapList = - (List>) result.get(JsonKey.CONTENT); - - if (!userMapList.isEmpty()) { - Map roleUsersMap = new HashMap<>(); - roleUsersMap.put(JsonKey.ROLE, role); - List roleUsersList = new ArrayList<>(); - for (Map userMap : userMapList) { - roleUsersList.add((String) userMap.get(JsonKey.USER_ID)); - } - roleUsersMap.put(JsonKey.USERS, roleUsersList); - suggestedUsersList.add(roleUsersMap); - } - }); + suggestedUsersList = fetchUsersByRoles(roles, rootOrgId, request); } + + if (!roles.contains(JsonKey.ORG_ADMIN)) { + // Add logic to fetch and add orgAdmins to suggestedUsersList + List> orgAdminUsersList = + fetchUsersByRoles((ArrayList) Arrays.asList("JsonKey.ORG_ADMIN"), rootOrgId, request); + if (!orgAdminUsersList.isEmpty()) suggestedUsersList.addAll(orgAdminUsersList); + } + logger.info( "UserDeletionBackgroundJobActor::inputKafkaTopic:: suggestedUsersList size:: " + suggestedUsersList.size()); /* Fetch Managed Users - START */ + Map searchQueryMap = new HashMap<>(); List managedUsersList = new ArrayList<>(); Map managedUsersSearchFilter = new HashMap<>(); managedUsersSearchFilter.put(JsonKey.ROOT_ORG_ID, rootOrgId); @@ -119,4 +97,39 @@ private void inputKafkaTopic(Request request) throws Exception { "UserDeletionBackgroundJobActor::inputKafkaTopic:: InstructionEventGenerator.pushInstructionEvent:: "); InstructionEventGenerator.pushInstructionEvent(userDeletionTopic, data); } + + private List fetchUsersByRoles(ArrayList roles, String rootOrgId, Request request) { + List> suggestedUsersList = new ArrayList<>(); + Map searchQueryMap = new HashMap<>(); + Map searchFilter = new HashMap<>(); + searchFilter.put(JsonKey.ROOT_ORG_ID, rootOrgId); + + // for each role in the organisation, fetch list of other users to pass it as part of event + List queryFields = new ArrayList<>(); + queryFields.add(JsonKey.USER_ID); + searchQueryMap.put(JsonKey.FIELDS, queryFields); + logger.info("UserDeletionBackgroundJobActor::inputKafkaTopic:: roles size:: " + roles.size()); + roles.forEach( + role -> { + searchFilter.put(JsonKey.ROLES + "." + JsonKey.ROLE, role); + searchQueryMap.put(JsonKey.FILTERS, searchFilter); + SearchDTO searchDto = ElasticSearchHelper.createSearchDTO(searchQueryMap); + Map result = + userService.searchUser(searchDto, request.getRequestContext()); + List> userMapList = + (List>) result.get(JsonKey.CONTENT); + + if (!userMapList.isEmpty()) { + Map roleUsersMap = new HashMap<>(); + roleUsersMap.put(JsonKey.ROLE, role); + List roleUsersList = new ArrayList<>(); + for (Map userMap : userMapList) { + roleUsersList.add((String) userMap.get(JsonKey.USER_ID)); + } + roleUsersMap.put(JsonKey.USERS, roleUsersList); + suggestedUsersList.add(roleUsersMap); + } + }); + return suggestedUsersList; + } } From 750047c64917ae733c52c9d58f62b9cd1108994e Mon Sep 17 00:00:00 2001 From: Jayaprakash8887 Date: Wed, 6 Dec 2023 17:56:42 +0530 Subject: [PATCH 2/5] Issue #LR-676 feat: Delete User API --- .../user/UserDeletionBackgroundJobActor.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java b/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java index e1034ce68f..f5ce373798 100644 --- a/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java +++ b/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java @@ -30,7 +30,7 @@ private void inputKafkaTopic(Request request) throws Exception { User user = userService.getUserById(userId, request.getRequestContext()); String rootOrgId = user.getRootOrgId(); - List> suggestedUsersList = new ArrayList<>(); + ArrayList> suggestedUsersList = new ArrayList<>(); if (!roles.isEmpty()) { suggestedUsersList = fetchUsersByRoles(roles, rootOrgId, request); @@ -38,8 +38,8 @@ private void inputKafkaTopic(Request request) throws Exception { if (!roles.contains(JsonKey.ORG_ADMIN)) { // Add logic to fetch and add orgAdmins to suggestedUsersList - List> orgAdminUsersList = - fetchUsersByRoles((ArrayList) Arrays.asList("JsonKey.ORG_ADMIN"), rootOrgId, request); + ArrayList> orgAdminUsersList = + fetchUsersByRoles((ArrayList) Arrays.asList(JsonKey.ORG_ADMIN), rootOrgId, request); if (!orgAdminUsersList.isEmpty()) suggestedUsersList.addAll(orgAdminUsersList); } @@ -98,14 +98,14 @@ private void inputKafkaTopic(Request request) throws Exception { InstructionEventGenerator.pushInstructionEvent(userDeletionTopic, data); } - private List fetchUsersByRoles(ArrayList roles, String rootOrgId, Request request) { - List> suggestedUsersList = new ArrayList<>(); + private ArrayList fetchUsersByRoles(ArrayList roles, String rootOrgId, Request request) { + ArrayList> suggestedUsersList = new ArrayList<>(); Map searchQueryMap = new HashMap<>(); Map searchFilter = new HashMap<>(); searchFilter.put(JsonKey.ROOT_ORG_ID, rootOrgId); // for each role in the organisation, fetch list of other users to pass it as part of event - List queryFields = new ArrayList<>(); + ArrayList queryFields = new ArrayList<>(); queryFields.add(JsonKey.USER_ID); searchQueryMap.put(JsonKey.FIELDS, queryFields); logger.info("UserDeletionBackgroundJobActor::inputKafkaTopic:: roles size:: " + roles.size()); @@ -116,13 +116,13 @@ private List fetchUsersByRoles(ArrayList roles, String rootOrgId, Request reques SearchDTO searchDto = ElasticSearchHelper.createSearchDTO(searchQueryMap); Map result = userService.searchUser(searchDto, request.getRequestContext()); - List> userMapList = - (List>) result.get(JsonKey.CONTENT); + ArrayList> userMapList = + (ArrayList>) result.get(JsonKey.CONTENT); if (!userMapList.isEmpty()) { Map roleUsersMap = new HashMap<>(); roleUsersMap.put(JsonKey.ROLE, role); - List roleUsersList = new ArrayList<>(); + ArrayList roleUsersList = new ArrayList<>(); for (Map userMap : userMapList) { roleUsersList.add((String) userMap.get(JsonKey.USER_ID)); } From 6c73fa188362536e1083642c0d5814cc2b7c306c Mon Sep 17 00:00:00 2001 From: Jayaprakash8887 Date: Wed, 6 Dec 2023 18:00:22 +0530 Subject: [PATCH 3/5] Issue #LR-676 feat: Delete User API --- .../user/UserDeletionBackgroundJobActor.java | 84 ++++++++----------- 1 file changed, 36 insertions(+), 48 deletions(-) diff --git a/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java b/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java index f5ce373798..b277f08700 100644 --- a/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java +++ b/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java @@ -1,6 +1,9 @@ package org.sunbird.actor.user; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.sunbird.actor.core.BaseActor; import org.sunbird.common.ElasticSearchHelper; import org.sunbird.dto.SearchDTO; @@ -24,31 +27,51 @@ public void onReceive(Request request) throws Throwable { private void inputKafkaTopic(Request request) throws Exception { Map userDetails = request.getRequest(); String userId = (String) userDetails.get(JsonKey.USER_ID); - ArrayList roles = (ArrayList) userDetails.get(JsonKey.USER_ROLES); + ArrayList roles = (ArrayList) userDetails.get(JsonKey.USER_ROLES); logger.info("UserDeletionBackgroundJobActor::inputKafkaTopic:: userId:: " + userId); logger.info("UserDeletionBackgroundJobActor::inputKafkaTopic:: roles size:: " + roles.size()); User user = userService.getUserById(userId, request.getRequestContext()); String rootOrgId = user.getRootOrgId(); - ArrayList> suggestedUsersList = new ArrayList<>(); + List> suggestedUsersList = new ArrayList<>(); + Map searchQueryMap = new HashMap<>(); + Map searchFilter = new HashMap<>(); + searchFilter.put(JsonKey.ROOT_ORG_ID, rootOrgId); - if (!roles.isEmpty()) { - suggestedUsersList = fetchUsersByRoles(roles, rootOrgId, request); - } + if (!roles.contains(JsonKey.ORG_ADMIN)) roles.add(JsonKey.ORG_ADMIN); - if (!roles.contains(JsonKey.ORG_ADMIN)) { - // Add logic to fetch and add orgAdmins to suggestedUsersList - ArrayList> orgAdminUsersList = - fetchUsersByRoles((ArrayList) Arrays.asList(JsonKey.ORG_ADMIN), rootOrgId, request); - if (!orgAdminUsersList.isEmpty()) suggestedUsersList.addAll(orgAdminUsersList); - } + // for each role in the organisation, fetch list of other users to pass it as part of event + List queryFields = new ArrayList<>(); + queryFields.add(JsonKey.USER_ID); + searchQueryMap.put(JsonKey.FIELDS, queryFields); + logger.info("UserDeletionBackgroundJobActor::inputKafkaTopic:: roles size:: " + roles.size()); + roles.forEach( + role -> { + searchFilter.put(JsonKey.ROLES + "." + JsonKey.ROLE, role); + searchQueryMap.put(JsonKey.FILTERS, searchFilter); + SearchDTO searchDto = ElasticSearchHelper.createSearchDTO(searchQueryMap); + Map result = + userService.searchUser(searchDto, request.getRequestContext()); + List> userMapList = + (List>) result.get(JsonKey.CONTENT); + + if (!userMapList.isEmpty()) { + Map roleUsersMap = new HashMap<>(); + roleUsersMap.put(JsonKey.ROLE, role); + List roleUsersList = new ArrayList<>(); + for (Map userMap : userMapList) { + roleUsersList.add((String) userMap.get(JsonKey.USER_ID)); + } + roleUsersMap.put(JsonKey.USERS, roleUsersList); + suggestedUsersList.add(roleUsersMap); + } + }); logger.info( "UserDeletionBackgroundJobActor::inputKafkaTopic:: suggestedUsersList size:: " + suggestedUsersList.size()); /* Fetch Managed Users - START */ - Map searchQueryMap = new HashMap<>(); List managedUsersList = new ArrayList<>(); Map managedUsersSearchFilter = new HashMap<>(); managedUsersSearchFilter.put(JsonKey.ROOT_ORG_ID, rootOrgId); @@ -97,39 +120,4 @@ private void inputKafkaTopic(Request request) throws Exception { "UserDeletionBackgroundJobActor::inputKafkaTopic:: InstructionEventGenerator.pushInstructionEvent:: "); InstructionEventGenerator.pushInstructionEvent(userDeletionTopic, data); } - - private ArrayList fetchUsersByRoles(ArrayList roles, String rootOrgId, Request request) { - ArrayList> suggestedUsersList = new ArrayList<>(); - Map searchQueryMap = new HashMap<>(); - Map searchFilter = new HashMap<>(); - searchFilter.put(JsonKey.ROOT_ORG_ID, rootOrgId); - - // for each role in the organisation, fetch list of other users to pass it as part of event - ArrayList queryFields = new ArrayList<>(); - queryFields.add(JsonKey.USER_ID); - searchQueryMap.put(JsonKey.FIELDS, queryFields); - logger.info("UserDeletionBackgroundJobActor::inputKafkaTopic:: roles size:: " + roles.size()); - roles.forEach( - role -> { - searchFilter.put(JsonKey.ROLES + "." + JsonKey.ROLE, role); - searchQueryMap.put(JsonKey.FILTERS, searchFilter); - SearchDTO searchDto = ElasticSearchHelper.createSearchDTO(searchQueryMap); - Map result = - userService.searchUser(searchDto, request.getRequestContext()); - ArrayList> userMapList = - (ArrayList>) result.get(JsonKey.CONTENT); - - if (!userMapList.isEmpty()) { - Map roleUsersMap = new HashMap<>(); - roleUsersMap.put(JsonKey.ROLE, role); - ArrayList roleUsersList = new ArrayList<>(); - for (Map userMap : userMapList) { - roleUsersList.add((String) userMap.get(JsonKey.USER_ID)); - } - roleUsersMap.put(JsonKey.USERS, roleUsersList); - suggestedUsersList.add(roleUsersMap); - } - }); - return suggestedUsersList; - } } From 05e520646ea69907768be0b0fec2d30c517010d7 Mon Sep 17 00:00:00 2001 From: Jayaprakash8887 Date: Tue, 12 Dec 2023 16:32:44 +0530 Subject: [PATCH 4/5] Issue #LR-676 feat: Delete User API --- .../org/sunbird/actor/user/UserDeletionBackgroundJobActor.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java b/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java index b277f08700..55717ffd4f 100644 --- a/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java +++ b/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java @@ -32,6 +32,7 @@ private void inputKafkaTopic(Request request) throws Exception { logger.info("UserDeletionBackgroundJobActor::inputKafkaTopic:: roles size:: " + roles.size()); User user = userService.getUserById(userId, request.getRequestContext()); String rootOrgId = user.getRootOrgId(); + String userName = user.getUserName(); List> suggestedUsersList = new ArrayList<>(); Map searchQueryMap = new HashMap<>(); @@ -110,6 +111,7 @@ private void inputKafkaTopic(Request request) throws Exception { Map eData = new HashMap<>(); eData.put(JsonKey.ORGANISATION_ID, rootOrgId); eData.put(JsonKey.USER_ID, userId); + eData.put(JsonKey.USERNAME, userName); eData.put(JsonKey.SUGGESTED_USERS, suggestedUsersList); eData.put(JsonKey.MANAGED_USERS, managedUsersList); eData.put(JsonKey.ACTION, JsonKey.DELETE_USER_ACTON); From d0090a0554397edc44ad8ef165a5587fe484a8e1 Mon Sep 17 00:00:00 2001 From: Jayaprakash8887 Date: Mon, 18 Dec 2023 15:34:21 +0530 Subject: [PATCH 5/5] Issue #LR-676 feat: Delete User API --- .../org/sunbird/actor/user/UserDeletionBackgroundJobActor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java b/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java index 55717ffd4f..326b401969 100644 --- a/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java +++ b/service/src/main/java/org/sunbird/actor/user/UserDeletionBackgroundJobActor.java @@ -14,6 +14,7 @@ import org.sunbird.service.user.UserService; import org.sunbird.service.user.impl.UserServiceImpl; import org.sunbird.util.PropertiesCache; +import org.sunbird.util.user.UserUtil; public class UserDeletionBackgroundJobActor extends BaseActor { @@ -32,7 +33,7 @@ private void inputKafkaTopic(Request request) throws Exception { logger.info("UserDeletionBackgroundJobActor::inputKafkaTopic:: roles size:: " + roles.size()); User user = userService.getUserById(userId, request.getRequestContext()); String rootOrgId = user.getRootOrgId(); - String userName = user.getUserName(); + String userName = UserUtil.getDecryptedData(user.getUserName(), request.getRequestContext()); List> suggestedUsersList = new ArrayList<>(); Map searchQueryMap = new HashMap<>();