You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datalab.apache.org by dy...@apache.org on 2022/09/26 09:22:16 UTC

[incubator-datalab] branch DATALAB-3051 created (now 36d106e7f)

This is an automated email from the ASF dual-hosted git repository.

dyankiv pushed a change to branch DATALAB-3051
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git


      at 36d106e7f show users who are added to groups in autocomplete dropdown

This branch includes the following new commits:

     new 36d106e7f show users who are added to groups in autocomplete dropdown

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datalab.apache.org
For additional commands, e-mail: commits-help@datalab.apache.org


[incubator-datalab] 01/01: show users who are added to groups in autocomplete dropdown

Posted by dy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dyankiv pushed a commit to branch DATALAB-3051
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git

commit 36d106e7f46fbcf4c4c5c717a54e73da09e4b07f
Author: Denys Yankiv <de...@gmail.com>
AuthorDate: Mon Sep 26 12:21:39 2022 +0300

    show users who are added to groups in autocomplete dropdown
---
 .../com/epam/datalab/backendapi/dao/SecurityDAO.java    | 11 +++++++----
 .../service/impl/ImageExploratoryServiceImpl.java       | 17 ++++++++++++++++-
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/dao/SecurityDAO.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/dao/SecurityDAO.java
index 85e836e83..2522036c1 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/dao/SecurityDAO.java
+++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/dao/SecurityDAO.java
@@ -39,10 +39,7 @@ import java.util.Set;
 import java.util.stream.Collectors;
 
 import static com.epam.datalab.backendapi.dao.MongoCollections.ROLES;
-import static com.mongodb.client.model.Filters.and;
-import static com.mongodb.client.model.Filters.eq;
-import static com.mongodb.client.model.Filters.gte;
-import static com.mongodb.client.model.Filters.ne;
+import static com.mongodb.client.model.Filters.*;
 import static com.mongodb.client.model.Projections.exclude;
 import static com.mongodb.client.model.Projections.fields;
 import static com.mongodb.client.model.Projections.include;
@@ -109,6 +106,12 @@ public class SecurityDAO extends BaseDAO {
                 .map(d -> convertFromDocument((Document) d.get(TOKEN_RESPONSE), AccessTokenResponse.class));
     }
 
+    public Set<String> getUserNames(String name){
+        return stream(find(SECURITY_COLLECTION, regex(ID, name,"i")))
+                .map(document -> document.getString(ID))
+                .collect(Collectors.toSet());
+    }
+
     @SuppressWarnings("unchecked")
     private Set<String> toUsers(Document d) {
         final Object users = d.get("users");
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/ImageExploratoryServiceImpl.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/ImageExploratoryServiceImpl.java
index b0b5bc7dc..5d45e3cff 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/ImageExploratoryServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/ImageExploratoryServiceImpl.java
@@ -101,6 +101,9 @@ public class ImageExploratoryServiceImpl implements ImageExploratoryService {
     @Inject
     private UserSettingsDAO userSettingsDAO;
 
+    @Inject
+    private SecurityDAO securityDAO;
+
     @Audit(action = CREATE, type = IMAGE)
     @Override
     public String createImage(@User UserInfo user, @Project String project, @ResourceName String exploratoryName, String imageName, String imageDescription, @Info String info) {
@@ -316,10 +319,22 @@ public class ImageExploratoryServiceImpl implements ImageExploratoryService {
     @Override
     public Set<SharedWithDTO> getUsersAndGroupsForSharing(String userName, String imageName, String project, String endpoint, String value) {
         Set<SharedWithDTO> sharedWith = getImageSharingInfo(userName, imageName, project, endpoint);
-        Set<SharedWithDTO> canBeSharedWith = userSettingsDAO.getUserNames(value).stream()
+
+        // Find users in groups
+        Map<String, Set<String>> groupsAndUsers = securityDAO.getGroups();
+        final Set<String> usersInGroups = new HashSet<>();
+        groupsAndUsers.entrySet().stream().forEach(entry -> usersInGroups.addAll(entry.getValue()));
+        Set<String> usersFiltered = usersInGroups.stream()
+                .filter(name -> name.toLowerCase().contains(value.toLowerCase())).collect(Collectors.toSet());
+        // Find users who logged in
+        usersFiltered.addAll(securityDAO.getUserNames(value));
+
+        Set<SharedWithDTO> canBeSharedWith = usersFiltered.stream()
                 .map(s -> new SharedWithDTO(SharedWithDTO.Type.USER, s)).collect(Collectors.toSet());
+
         canBeSharedWith.addAll(userGroupDAO.getGroupNames(value).stream()
                 .map(s -> new SharedWithDTO(SharedWithDTO.Type.GROUP, s)).collect(Collectors.toSet()));
+
         canBeSharedWith.removeAll(sharedWith);
         return new TreeSet<>(canBeSharedWith);
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datalab.apache.org
For additional commands, e-mail: commits-help@datalab.apache.org