james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [05/21] james-project git commit: JAMES-2455 Avoid recursive resolution when getting group members
Date Fri, 06 Jul 2018 09:27:31 GMT
JAMES-2455 Avoid recursive resolution when getting group members

For instance if a group member has forwards, he was not displayed in the group.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/161019dd
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/161019dd
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/161019dd

Branch: refs/heads/master
Commit: 161019ddfa4eb1863fc72e61fbee061b4a4da91e
Parents: ca12082
Author: benwa <btellier@linagora.com>
Authored: Thu Jul 5 12:47:58 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Jul 5 12:55:22 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/rrt/lib/MappingSource.java |  4 +++
 server/protocols/webadmin/webadmin-data/pom.xml |  4 +++
 .../james/webadmin/routes/GroupsRoutes.java     |  6 +++--
 .../james/webadmin/routes/GroupsRoutesTest.java | 28 +++++++++++++++++---
 4 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/161019dd/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingSource.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingSource.java
b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingSource.java
index 5539089..7bd6298 100644
--- a/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingSource.java
+++ b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingSource.java
@@ -48,6 +48,10 @@ public class MappingSource implements Serializable {
         return new MappingSource(Optional.of(domain), Optional.empty(), Optional.empty());
     }
 
+    public static MappingSource fromMailAddress(MailAddress address) {
+        return fromUser(User.fromMailAddress(address));
+    }
+
     public static MappingSource fromUser(String localPart, String domain) {
         return fromUser(localPart, Domain.of(domain));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/161019dd/server/protocols/webadmin/webadmin-data/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/pom.xml b/server/protocols/webadmin/webadmin-data/pom.xml
index c007063..12757d0 100644
--- a/server/protocols/webadmin/webadmin-data/pom.xml
+++ b/server/protocols/webadmin/webadmin-data/pom.xml
@@ -47,6 +47,10 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-data-library</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>james-server-data-memory</artifactId>
             <scope>test</scope>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/161019dd/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
index 7f7a6ed..24ac5ec 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
@@ -49,6 +49,7 @@ import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.lib.Mapping;
 import org.apache.james.rrt.lib.MappingSource;
 import org.apache.james.rrt.lib.Mappings;
+import org.apache.james.rrt.lib.MappingsImpl;
 import org.apache.james.user.api.UsersRepository;
 import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.util.OptionalUtils;
@@ -234,9 +235,10 @@ public class GroupsRoutes implements Routes {
         @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
             message = "Internal server error - Something went bad on the server side.")
     })
-    public ImmutableSortedSet<String> listGroupMembers(Request request, Response response)
throws RecipientRewriteTable.ErrorMappingException, RecipientRewriteTableException {
+    public ImmutableSortedSet<String> listGroupMembers(Request request, Response response)
throws RecipientRewriteTableException {
         MailAddress groupAddress = parseMailAddress(request.params(GROUP_ADDRESS));
-        Mappings mappings = recipientRewriteTable.getMappings(groupAddress.getLocalPart(),
groupAddress.getDomain())
+        Mappings mappings = Optional.ofNullable(recipientRewriteTable.getUserDomainMappings(MappingSource.fromMailAddress(groupAddress)))
+            .orElse(MappingsImpl.empty())
             .select(Mapping.Type.Group);
 
         ensureNonEmptyMappings(mappings);

http://git-wip-us.apache.org/repos/asf/james-project/blob/161019dd/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
index 805aa43..09ae779 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
@@ -35,6 +35,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.james.core.Domain;
+import org.apache.james.core.User;
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.domainlist.api.DomainList;
 import org.apache.james.domainlist.memory.MemoryDomainList;
@@ -121,6 +122,27 @@ class GroupsRoutesTest {
                 .body(is("[]"));
         }
 
+
+        @Test
+        void getShouldNotResolveRecurseGroups() throws Exception {
+            when().put(GROUP1 + SEPARATOR + USER_A);
+
+            memoryRecipientRewriteTable.addForwardMapping(MappingSource.fromUser(User.fromUsername(USER_A)),
+                "b@" + DOMAIN.name());
+
+            List<String> addresses =
+                when()
+                    .get(GROUP1)
+                .then()
+                    .contentType(ContentType.JSON)
+                    .statusCode(HttpStatus.OK_200)
+                    .extract()
+                    .body()
+                    .jsonPath()
+                    .getList(".");
+            assertThat(addresses).containsExactly(USER_A);
+        }
+
         @Test
         void getGroupsShouldListExistingGroupsInAlphabeticOrder() {
             given()
@@ -686,7 +708,7 @@ class GroupsRoutesTest {
         void getShouldReturnErrorWhenRecipientRewriteTableExceptionIsThrown() throws Exception
{
             doThrow(RecipientRewriteTableException.class)
                 .when(memoryRecipientRewriteTable)
-                .getMappings(anyString(), any());
+                .getUserDomainMappings(any());
 
             when()
                 .get(GROUP1)
@@ -698,7 +720,7 @@ class GroupsRoutesTest {
         void getShouldReturnErrorWhenErrorMappingExceptionIsThrown() throws Exception {
             doThrow(RecipientRewriteTable.ErrorMappingException.class)
                 .when(memoryRecipientRewriteTable)
-                .getMappings(anyString(), any());
+                .getUserDomainMappings(any());
 
             when()
                 .get(GROUP1)
@@ -710,7 +732,7 @@ class GroupsRoutesTest {
         void getShouldReturnErrorWhenRuntimeExceptionIsThrown() throws Exception {
             doThrow(RuntimeException.class)
                 .when(memoryRecipientRewriteTable)
-                .getMappings(anyString(), any());
+                .getUserDomainMappings(any());
 
             when()
                 .get(GROUP1)


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message