This is an automated email from the ASF dual-hosted git repository. ofuks pushed a commit to branch DLAB-1571 in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/DLAB-1571 by this push: new 71919dc [DLAB-1700] Fixed issue with admin per project 71919dc is described below commit 71919dc55de8e7ff146bacd02237acb8dea88a2e Author: Oleh Fuks <olegfuk...@gmail.com> AuthorDate: Tue Apr 14 10:59:50 2020 +0300 [DLAB-1700] Fixed issue with admin per project --- .../java/com/epam/dlab/backendapi/dao/UserRoleDao.java | 2 +- .../java/com/epam/dlab/backendapi/dao/UserRoleDaoImpl.java | 14 ++++---------- .../dlab/backendapi/service/impl/UserGroupServiceImpl.java | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/UserRoleDao.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/UserRoleDao.java index c9b5585..48abb54 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/UserRoleDao.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/UserRoleDao.java @@ -47,5 +47,5 @@ public interface UserRoleDao { boolean removeGroup(String groupId); - List<UserGroupDto> aggregateRolesByGroup(boolean isAdmin); + List<UserGroupDto> aggregateRolesByGroup(); } diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/UserRoleDaoImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/UserRoleDaoImpl.java index 174e71f..81b7135 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/UserRoleDaoImpl.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/UserRoleDaoImpl.java @@ -25,9 +25,7 @@ import com.epam.dlab.exceptions.DlabException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.inject.Singleton; -import com.mongodb.client.model.Aggregates; import com.mongodb.client.model.BsonField; -import com.mongodb.client.model.Filters; import com.mongodb.client.result.UpdateResult; import org.bson.Document; import org.bson.conversions.Bson; @@ -108,7 +106,7 @@ public class UserRoleDaoImpl extends BaseDAO implements UserRoleDao { .noneMatch(id -> id.equals(u.getId()))) .forEach(this::insert); - addGroupToRole(aggregateRolesByGroup(false) + addGroupToRole(aggregateRolesByGroup() .stream() .map(UserGroupDto::getGroup) .collect(Collectors.toSet()), @@ -155,19 +153,15 @@ public class UserRoleDaoImpl extends BaseDAO implements UserRoleDao { } @Override - public List<UserGroupDto> aggregateRolesByGroup(boolean isAdmin) { + public List<UserGroupDto> aggregateRolesByGroup() { final Document role = roleDocument(); final Bson groupBy = group(GROUPS, new BsonField(ROLES, new Document(ADD_TO_SET, role))); final Bson lookup = lookup(USER_GROUPS, ID, ID, GROUP_INFO); - final List<Bson> pipeline = new ArrayList<>(); - if (!isAdmin) { - pipeline.add(Aggregates.match(Filters.not(eq(ID, ADMIN)))); - } - pipeline.addAll(Arrays.asList(unwind(GROUPS), groupBy, lookup, + final List<Bson> pipeline = Arrays.asList(unwind(GROUPS), groupBy, lookup, project(new Document(GROUP, "$" + ID).append(GROUP_INFO, elementAt(GROUP_INFO, 0)) .append(ROLES, "$" + ROLES)), project(new Document(GROUP, "$" + ID).append(USERS_FIELD, "$" + GROUP_INFO + "." + USERS_FIELD) - .append(ROLES, "$" + ROLES)))); + .append(ROLES, "$" + ROLES))); return stream(aggregate(MongoCollections.ROLES, pipeline)) .map(d -> convertFromDocument(d, UserGroupDto.class)) diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/UserGroupServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/UserGroupServiceImpl.java index 1758a8b..0b05f84 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/UserGroupServiceImpl.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/UserGroupServiceImpl.java @@ -97,14 +97,14 @@ public class UserGroupServiceImpl implements UserGroupService { @Override public List<UserGroupDto> getAggregatedRolesByGroup(UserInfo user) { if (UserRoles.isAdmin(user)) { - return userRoleDao.aggregateRolesByGroup(true); + return userRoleDao.aggregateRolesByGroup(); } else if (UserRoles.isProjectAdmin(user)) { Set<String> groups = projectService.getProjects(user) .stream() .map(ProjectDTO::getGroups) .flatMap(Collection::stream) .collect(Collectors.toSet()); - return userRoleDao.aggregateRolesByGroup(false) + return userRoleDao.aggregateRolesByGroup() .stream() .filter(userGroup -> groups.contains(userGroup.getGroup())) .collect(Collectors.toList()); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@dlab.apache.org For additional commands, e-mail: commits-h...@dlab.apache.org