Commit 6a02999e authored by Rostislav Vatolin [SLB]'s avatar Rostislav Vatolin [SLB]
Browse files

Merge branch 'add_get_member_for_rem' into 'master'

Error removing member from group

See merge request !82
parents c5b25ea7 1d9d556e
Pipeline #46786 passed with stages
in 15 minutes and 31 seconds
...@@ -42,7 +42,7 @@ public class RemoveMemberService { ...@@ -42,7 +42,7 @@ public class RemoveMemberService {
!removeMemberServiceDto.getRequesterId().equalsIgnoreCase(serviceAccountId)) { !removeMemberServiceDto.getRequesterId().equalsIgnoreCase(serviceAccountId)) {
throw new AppException(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase(), "Not authorized to manage members"); throw new AppException(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase(), "Not authorized to manage members");
} }
EntityNode memberNode = getEntityNode(memberEmail, partitionId); EntityNode memberNode = retrieveGroupRepo.getMemberNodeForRemovalFromGroup(memberEmail, partitionId);
removeMemberServiceDto.setChildrenReference(memberNode.getDirectChildReference(retrieveGroupRepo, existingGroupEntityNode).orElseThrow( removeMemberServiceDto.setChildrenReference(memberNode.getDirectChildReference(retrieveGroupRepo, existingGroupEntityNode).orElseThrow(
() -> new AppException(HttpStatus.NOT_FOUND.value(), HttpStatus.NOT_FOUND.getReasonPhrase(), String.format("Group %s does not have %s as a child/member", groupEmail, memberEmail)) () -> new AppException(HttpStatus.NOT_FOUND.value(), HttpStatus.NOT_FOUND.getReasonPhrase(), String.format("Group %s does not have %s as a child/member", groupEmail, memberEmail))
)); ));
...@@ -67,12 +67,4 @@ public class RemoveMemberService { ...@@ -67,12 +67,4 @@ public class RemoveMemberService {
groupCacheService.refreshListGroupCache(impactedUsers, removeMemberServiceDto.getPartitionId()); groupCacheService.refreshListGroupCache(impactedUsers, removeMemberServiceDto.getPartitionId());
return impactedUsers; return impactedUsers;
} }
private EntityNode getEntityNode(String id, String partitionId) {
return retrieveGroupRepo.getEntityNode(id, partitionId)
.orElseThrow(() -> new AppException(
HttpStatus.NOT_FOUND.value(),
HttpStatus.NOT_FOUND.getReasonPhrase(),
String.format("Not found entity node by email: %s and partitionId: %s", id, partitionId)));
}
} }
...@@ -16,6 +16,8 @@ public interface RetrieveGroupRepo { ...@@ -16,6 +16,8 @@ public interface RetrieveGroupRepo {
Optional<EntityNode> getEntityNode(String entityEmail, String partitionId); Optional<EntityNode> getEntityNode(String entityEmail, String partitionId);
EntityNode getMemberNodeForRemovalFromGroup(String memberId, String partitionId);
Set<EntityNode> getEntityNodes(String partitionId, List<String> nodeIds); Set<EntityNode> getEntityNodes(String partitionId, List<String> nodeIds);
Map<String, Set<String>> getUserPartitionAssociations(Set<String> userIds); Map<String, Set<String>> getUserPartitionAssociations(Set<String> userIds);
......
...@@ -77,7 +77,7 @@ public class RemoveMemberServiceTests { ...@@ -77,7 +77,7 @@ public class RemoveMemberServiceTests {
.name("member") .name("member")
.dataPartitionId("common") .dataPartitionId("common")
.build(); .build();
when(retrieveGroupRepo.getEntityNode("member@xxx.com", "common")).thenReturn(Optional.of(memberNode)); when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup("member@xxx.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder() EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP) .type(NodeType.GROUP)
.nodeId("data.x@common.contoso.com") .nodeId("data.x@common.contoso.com")
...@@ -128,7 +128,7 @@ public class RemoveMemberServiceTests { ...@@ -128,7 +128,7 @@ public class RemoveMemberServiceTests {
.name("member") .name("member")
.dataPartitionId("common") .dataPartitionId("common")
.build(); .build();
when(retrieveGroupRepo.getEntityNode("member@xxx.com", "common")).thenReturn(Optional.of(memberNode)); when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup("member@xxx.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder() EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP) .type(NodeType.GROUP)
.nodeId("data.x@common.contoso.com") .nodeId("data.x@common.contoso.com")
...@@ -170,7 +170,7 @@ public class RemoveMemberServiceTests { ...@@ -170,7 +170,7 @@ public class RemoveMemberServiceTests {
.name("member") .name("member")
.dataPartitionId("common") .dataPartitionId("common")
.build(); .build();
when(retrieveGroupRepo.getEntityNode("member@xxx.com", "common")).thenReturn(Optional.of(memberNode)); when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup("member@xxx.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder() EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP) .type(NodeType.GROUP)
.nodeId("data.x@common.contoso.com") .nodeId("data.x@common.contoso.com")
...@@ -219,7 +219,7 @@ public class RemoveMemberServiceTests { ...@@ -219,7 +219,7 @@ public class RemoveMemberServiceTests {
.name("member") .name("member")
.dataPartitionId("common") .dataPartitionId("common")
.build(); .build();
when(retrieveGroupRepo.getEntityNode("member@xxx.com", "common")).thenReturn(Optional.of(memberNode)); when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup("member@xxx.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder() EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP) .type(NodeType.GROUP)
.nodeId("data.x@common.contoso.com") .nodeId("data.x@common.contoso.com")
...@@ -271,7 +271,7 @@ public class RemoveMemberServiceTests { ...@@ -271,7 +271,7 @@ public class RemoveMemberServiceTests {
.name("users") .name("users")
.dataPartitionId("common") .dataPartitionId("common")
.build(); .build();
when(retrieveGroupRepo.getEntityNode("users@common.contoso.com", "common")).thenReturn(Optional.of(memberNode)); when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup("users@common.contoso.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder() EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP) .type(NodeType.GROUP)
.nodeId("data.default.owners@common.contoso.com") .nodeId("data.default.owners@common.contoso.com")
...@@ -328,7 +328,7 @@ public class RemoveMemberServiceTests { ...@@ -328,7 +328,7 @@ public class RemoveMemberServiceTests {
.name("member") .name("member")
.dataPartitionId("common") .dataPartitionId("common")
.build(); .build();
when(retrieveGroupRepo.getEntityNode("member@xxx.com", "common")).thenReturn(Optional.of(memberNode)); when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup("member@xxx.com", "common")).thenReturn(memberNode);
EntityNode entityNode = EntityNode.builder() EntityNode entityNode = EntityNode.builder()
.type(NodeType.USER) .type(NodeType.USER)
.nodeId("member@xxx.com") .nodeId("member@xxx.com")
...@@ -378,8 +378,8 @@ public class RemoveMemberServiceTests { ...@@ -378,8 +378,8 @@ public class RemoveMemberServiceTests {
.name("datafier") .name("datafier")
.dataPartitionId("common") .dataPartitionId("common")
.build(); .build();
when(retrieveGroupRepo.getEntityNode( when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup(
"datafier@evd-ddl-us-common.iam.gserviceaccount.com", "common")).thenReturn(Optional.of(memberNode)); "datafier@evd-ddl-us-common.iam.gserviceaccount.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder() EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP) .type(NodeType.GROUP)
.nodeId("users.data.root@common.contoso.com") .nodeId("users.data.root@common.contoso.com")
...@@ -437,8 +437,8 @@ public class RemoveMemberServiceTests { ...@@ -437,8 +437,8 @@ public class RemoveMemberServiceTests {
.name("users.data.root") .name("users.data.root")
.dataPartitionId("common") .dataPartitionId("common")
.build(); .build();
when(retrieveGroupRepo.getEntityNode( when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup(
"users.data.root@common.contoso.com", "common")).thenReturn(Optional.of(memberNode)); "users.data.root@common.contoso.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder() EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP) .type(NodeType.GROUP)
.nodeId("users.test@common.contoso.com") .nodeId("users.test@common.contoso.com")
......
...@@ -90,6 +90,14 @@ public class AwsRetrieveGroupRepo implements RetrieveGroupRepo { ...@@ -90,6 +90,14 @@ public class AwsRetrieveGroupRepo implements RetrieveGroupRepo {
} }
} }
@Override
public EntityNode getMemberNodeForRemovalFromGroup(String memberId, String partitionId) {
if (!memberId.endsWith(String.format("@%s.%s", partitionId, config.getDomain()))) {
return EntityNode.createMemberNodeForNewUser(memberId, partitionId);
}
return EntityNode.createNodeFromGroupEmail(memberId);
}
@Override @Override
public Set<EntityNode> getEntityNodes(String partitionId, List<String> nodeIds) { public Set<EntityNode> getEntityNodes(String partitionId, List<String> nodeIds) {
if (nodeIds.isEmpty()) { if (nodeIds.isEmpty()) {
......
...@@ -54,6 +54,15 @@ public class RetrieveGroupRepoGremlin implements RetrieveGroupRepo { ...@@ -54,6 +54,15 @@ public class RetrieveGroupRepoGremlin implements RetrieveGroupRepo {
return gremlinConnector.getVertex(traversal).map(vertexUtilService::createMemberNode); return gremlinConnector.getVertex(traversal).map(vertexUtilService::createMemberNode);
} }
@Override
public EntityNode getMemberNodeForRemovalFromGroup(String memberId, String partitionId) {
return getEntityNode(memberId, partitionId)
.orElseThrow(() -> new AppException(
HttpStatus.NOT_FOUND.value(),
HttpStatus.NOT_FOUND.getReasonPhrase(),
String.format("Not found entity node by email: %s and partitionId: %s", memberId, partitionId)));
}
@Override @Override
public Set<EntityNode> getEntityNodes(String partitionId, List<String> nodeIds) { public Set<EntityNode> getEntityNodes(String partitionId, List<String> nodeIds) {
return new HashSet<>(); return new HashSet<>();
......
...@@ -87,6 +87,14 @@ public class RetrieveGroupRepoRedis implements RetrieveGroupRepo { ...@@ -87,6 +87,14 @@ public class RetrieveGroupRepoRedis implements RetrieveGroupRepo {
} }
} }
@Override
public EntityNode getMemberNodeForRemovalFromGroup(String memberId, String partitionId) {
if (!memberId.endsWith(String.format("@%s.%s", partitionId, config.getDomain()))) {
return EntityNode.createMemberNodeForNewUser(memberId, partitionId);
}
return EntityNode.createNodeFromGroupEmail(memberId);
}
@Override @Override
public Set<EntityNode> getEntityNodes(String partitionId, List<String> nodeIds) { public Set<EntityNode> getEntityNodes(String partitionId, List<String> nodeIds) {
if (nodeIds.isEmpty()) { if (nodeIds.isEmpty()) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment