james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject [26/27] james-project git commit: JAMES-2169 User can retrieve shared mailbox from JMAP and its integration test
Date Thu, 05 Oct 2017 18:02:38 GMT
JAMES-2169 User can retrieve shared mailbox from JMAP and its integration test


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

Branch: refs/heads/master
Commit: f52eaa62a793ecfe5d276531ebb3fc1351564bc6
Parents: 93aac90
Author: quynhn <qnguyen@linagora.com>
Authored: Wed Oct 4 16:07:16 2017 +0700
Committer: Matthieu Baechler <matthieu@apache.org>
Committed: Thu Oct 5 20:00:39 2017 +0200

----------------------------------------------------------------------
 .../integration/GetMailboxesMethodTest.java     | 102 +++++++++++++++++++
 .../james/jmap/methods/GetMailboxesMethod.java  |  10 +-
 2 files changed, 107 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f52eaa62/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
index 547c644..5e21f00 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
@@ -554,4 +554,106 @@ public abstract class GetMailboxesMethodTest {
 
         assertThat(sharedWith).containsOnlyKeys(alice, cedric);
     }
+
+    @Test
+    public void getMailboxesShouldReturnAllAccessibleMailboxesWhenEmptyIds() throws Exception
{
+        String sharedMailboxName = "BobShared";
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, bob, DefaultMailboxes.INBOX);
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, bob, sharedMailboxName);
+
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice, DefaultMailboxes.INBOX);
+        MailboxPath bobMailboxPath = MailboxPath.forUser(bob, sharedMailboxName);
+        aclProbe.replaceRights(bobMailboxPath, alice, new Rfc4314Rights(Right.Read));
+
+        List<String> expectedMailboxes = ImmutableList.<String> builder()
+            .addAll(DefaultMailboxes.DEFAULT_MAILBOXES)
+            .add(sharedMailboxName)
+            .build();
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMailboxes\", {}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("mailboxes"))
+            .body(ARGUMENTS + ".list", hasSize(6))
+            .body(ARGUMENTS + ".list.name", hasItems(expectedMailboxes.toArray()));
+    }
+
+    @Test
+    public void getMailboxesShouldFilterMailboxesWithReadRightWhenEmptyIds() throws Exception
{
+        String sharedReadMailboxName = "BobShared";
+        String sharedAdministerMailboxName = "BobShared1";
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, bob, DefaultMailboxes.INBOX);
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, bob, sharedReadMailboxName);
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, bob, sharedAdministerMailboxName);
+
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice, DefaultMailboxes.INBOX);
+        MailboxPath bobSharedReadMailboxPath = MailboxPath.forUser(bob, sharedReadMailboxName);
+        MailboxPath bobSharedAdministerMailboxPath = MailboxPath.forUser(bob, sharedAdministerMailboxName);
+
+        aclProbe.replaceRights(bobSharedReadMailboxPath, alice, new Rfc4314Rights(Right.Read));
+        aclProbe.replaceRights(bobSharedAdministerMailboxPath, alice, new Rfc4314Rights(Right.Administer));
+
+        List<String> expectedMailboxes = ImmutableList.<String> builder()
+            .addAll(DefaultMailboxes.DEFAULT_MAILBOXES)
+            .add(sharedReadMailboxName)
+            .build();
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMailboxes\", {}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("mailboxes"))
+            .body(ARGUMENTS + ".list", hasSize(6))
+            .body(ARGUMENTS + ".list.name", hasItems(expectedMailboxes.toArray()));
+    }
+
+    @Test
+    public void getMailboxesShouldReturnExactUserInbox() throws Exception {
+        String mailboxName = "BobShared";
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, bob, mailboxName);
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, bob, DefaultMailboxes.INBOX);
+        MailboxId aliceInboxMailbox = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE,
alice, DefaultMailboxes.INBOX);
+        MailboxPath bobMailboxPath = MailboxPath.forUser(bob, mailboxName);
+        aclProbe.replaceRights(bobMailboxPath, alice, new Rfc4314Rights(Right.Read));
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMailboxes\", {\"ids\": [\"" + aliceInboxMailbox.serialize() + "\"]},
\"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("mailboxes"))
+            .body(ARGUMENTS + ".list.name", hasItems(MailboxConstants.INBOX))
+            .body(ARGUMENTS + ".list.id", hasItems(aliceInboxMailbox.serialize()));
+    }
+
+    @Test
+    public void getMailboxesShouldReturnSharedMailboxesWithRead() throws Exception {
+        String sharedMailboxName = "BobShared";
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, bob, DefaultMailboxes.INBOX);
+        MailboxId mailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE,
bob, sharedMailboxName);
+
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice, DefaultMailboxes.INBOX);
+        MailboxPath bobMailboxPath = MailboxPath.forUser(bob, sharedMailboxName);
+        aclProbe.replaceRights(bobMailboxPath, alice, new Rfc4314Rights(Right.Read));
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMailboxes\", {\"ids\": [\"" + mailboxId.serialize() + "\"]}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("mailboxes"))
+            .body(ARGUMENTS + ".list", hasSize(1))
+            .body(ARGUMENTS + ".list.id", hasItems(mailboxId.serialize()));
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f52eaa62/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
index eae7e13..b4cad15 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
@@ -139,7 +139,7 @@ public class GetMailboxesMethod implements Method {
 
     private Stream<Mailbox> retrieveAllMailboxes(MailboxSession mailboxSession) throws
MailboxException {
         List<MailboxMetaData> userMailboxes = mailboxManager.search(
-            MailboxQuery.privateMailboxesBuilder(mailboxSession)
+            MailboxQuery.builder()
                 .matchesAllMailboxNames()
                 .build(),
             mailboxSession);
@@ -147,10 +147,10 @@ public class GetMailboxesMethod implements Method {
             .stream()
             .map(MailboxMetaData::getId)
             .map(mailboxId -> mailboxFactory.builder()
-                    .id(mailboxId)
-                    .session(mailboxSession)
-                    .usingPreloadedMailboxesMetadata(userMailboxes)
-                    .build())
+                .id(mailboxId)
+                .session(mailboxSession)
+                .usingPreloadedMailboxesMetadata(userMailboxes)
+                .build())
             .flatMap(OptionalUtils::toStream);
     }
 


---------------------------------------------------------------------
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