JAMES-2162 JMAP implementation for reading GetMailboxes::sharedWith

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

Branch: refs/heads/master
Commit: 0ac2d416aceaeaf8c3b0e2c0384bccbf52bedf3d
Parents: 672f24f
Author: benwa <[email protected]>
Authored: Wed Sep 27 17:42:30 2017 +0700
Committer: benwa <[email protected]>
Committed: Tue Oct 3 07:52:12 2017 +0700

----------------------------------------------------------------------
 .../james/mailbox/store/probe/ACLProbe.java     |  28 ++++
 .../james/cli/probe/impl/JmxMailboxProbe.java   |  11 +-
 .../org/apache/james/modules/ACLProbeImpl.java  |  51 +++++++
 .../org/apache/james/modules/MailboxModule.java |   1 +
 .../apache/james/modules/MailboxProbeImpl.java  |   1 -
 .../integration/GetMailboxesMethodTest.java     | 147 ++++++++++++++-----
 .../apache/james/jmap/model/MailboxFactory.java |   5 +
 .../james/jmap/model/mailbox/Mailbox.java       |  25 +++-
 .../james/jmap/model/mailbox/MailboxTest.java   |   2 +-
 9 files changed, 222 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0ac2d416/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/ACLProbe.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/ACLProbe.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/ACLProbe.java
new file mode 100644
index 0000000..986186e
--- /dev/null
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/ACLProbe.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.probe;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights;
+import org.apache.james.mailbox.model.MailboxPath;
+
+public interface ACLProbe {
+    void replaceRights(MailboxPath mailboxPath, String targetUser, 
Rfc4314Rights rights) throws MailboxException;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ac2d416/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java
----------------------------------------------------------------------
diff --git 
a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java
 
b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java
index ab9005a..ebc1f0e 100644
--- 
a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java
+++ 
b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java
@@ -23,9 +23,11 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
 import java.util.Date;
+
 import javax.mail.Flags;
 import javax.management.MalformedObjectNameException;
 
+import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.adapter.mailbox.MailboxCopierManagementMBean;
 import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean;
 import org.apache.james.adapter.mailbox.ReIndexerManagementMBean;
@@ -97,23 +99,20 @@ public class JmxMailboxProbe implements MailboxProbe, 
JmxProbe {
         reIndexerManagement.reIndex();
     }
 
-
     @Override
     public Mailbox getMailbox(String namespace, String user, String name) {
-        return null;
+        throw new NotImplementedException();
     }
 
-
     @Override
     public ComposedMessageId appendMessage(String username, MailboxPath 
mailboxPath, InputStream message,
             Date internalDate, boolean isRecent, Flags flags) throws 
MailboxException {
-        return null;
+        throw new NotImplementedException();
     }
 
 
     @Override
     public Collection<String> listSubscriptions(String user) throws Exception {
-        return null;
+        throw new NotImplementedException();
     }
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ac2d416/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java
 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java
new file mode 100644
index 0000000..a25c4d9
--- /dev/null
+++ 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java
@@ -0,0 +1,51 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.modules;
+
+import javax.inject.Inject;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxACL.ACLCommand;
+import org.apache.james.mailbox.model.MailboxACL.EditMode;
+import org.apache.james.mailbox.model.MailboxACL.EntryKey;
+import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.probe.ACLProbe;
+import org.apache.james.utils.GuiceProbe;
+
+public class ACLProbeImpl implements GuiceProbe, ACLProbe {
+    private final MailboxManager mailboxManager;
+
+    @Inject
+    private ACLProbeImpl(MailboxManager mailboxManager) {
+        this.mailboxManager = mailboxManager;
+    }
+
+    @Override
+    public void replaceRights(MailboxPath mailboxPath, String targetUser, 
Rfc4314Rights rights) throws MailboxException {
+        MailboxSession mailboxSession = 
mailboxManager.createSystemSession(mailboxPath.getUser());
+
+        EntryKey key = EntryKey.createUser(targetUser);
+        ACLCommand mailboxACLCommand = new ACLCommand(key, EditMode.REPLACE, 
rights);
+        mailboxManager.applyRightsCommand(mailboxPath, mailboxACLCommand, 
mailboxSession);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ac2d416/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
index 48a9077..a91ada3 100644
--- 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
+++ 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
@@ -30,6 +30,7 @@ public class MailboxModule extends AbstractModule {
         Multibinder<GuiceProbe> probeMultiBinder = 
Multibinder.newSetBinder(binder(), GuiceProbe.class);
         probeMultiBinder.addBinding().to(MailboxProbeImpl.class);
         probeMultiBinder.addBinding().to(QuotaProbesImpl.class);
+        probeMultiBinder.addBinding().to(ACLProbeImpl.class);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ac2d416/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
index 6a9588f..b2462ee 100644
--- 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
+++ 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
@@ -49,7 +49,6 @@ import org.apache.james.utils.GuiceProbe;
 import com.google.common.base.Throwables;
 
 public class MailboxProbeImpl implements GuiceProbe, MailboxProbe {
-
     private final MailboxManager mailboxManager;
     private final MailboxMapperFactory mailboxMapperFactory;
     private final SubscriptionManager subscriptionManager;

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ac2d416/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 60806e7..c9136f3 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
@@ -24,9 +24,11 @@ import static 
com.jayway.restassured.config.EncoderConfig.encoderConfig;
 import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.hamcrest.Matchers.empty;
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasEntry;
 import static org.hamcrest.Matchers.hasItem;
 import static org.hamcrest.Matchers.hasItems;
 import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.isEmptyOrNullString;
 import static org.hamcrest.Matchers.not;
 import static org.hamcrest.Matchers.nullValue;
@@ -43,21 +45,26 @@ import org.apache.james.GuiceJamesServer;
 import org.apache.james.jmap.DefaultMailboxes;
 import org.apache.james.jmap.HttpJmapAuthentication;
 import org.apache.james.jmap.api.access.AccessToken;
+import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights;
+import org.apache.james.mailbox.model.MailboxACL.Right;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.probe.ACLProbe;
 import org.apache.james.mailbox.store.probe.MailboxProbe;
+import org.apache.james.modules.ACLProbeImpl;
 import org.apache.james.modules.MailboxProbeImpl;
 import org.apache.james.probe.DataProbe;
-import org.apache.james.utils.JmapGuiceProbe;
 import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.JmapGuiceProbe;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
 import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import com.jayway.restassured.RestAssured;
 import com.jayway.restassured.builder.RequestSpecBuilder;
 import com.jayway.restassured.http.ContentType;
@@ -65,6 +72,11 @@ import com.jayway.restassured.http.ContentType;
 public abstract class GetMailboxesMethodTest {
     private static final String NAME = "[0][0]";
     private static final String ARGUMENTS = "[0][1]";
+    private static final String FIRST_MAILBOX = ARGUMENTS + ".list[0]";
+
+    public static final String READ = String.valueOf(Right.Read.asCharacter());
+    public static final String LOOKUP = 
String.valueOf(Right.Lookup.asCharacter());
+    public static final String ADMINISTER = 
String.valueOf(Right.Administer.asCharacter());
 
     protected abstract GuiceJamesServer createJmapServer();
 
@@ -72,13 +84,15 @@ public abstract class GetMailboxesMethodTest {
     private String username;
     private GuiceJamesServer jmapServer;
     private MailboxProbe mailboxProbe;
+    private ACLProbe aclProbe;
     
     @Before
     public void setup() throws Throwable {
         jmapServer = createJmapServer();
         jmapServer.start();
         mailboxProbe = jmapServer.getProbe(MailboxProbeImpl.class);
-        
+        aclProbe = jmapServer.getProbe(ACLProbeImpl.class);
+
         RestAssured.requestSpecification = new RequestSpecBuilder()
                 .setContentType(ContentType.JSON)
                 .setAccept(ContentType.JSON)
@@ -195,7 +209,7 @@ public abstract class GetMailboxesMethodTest {
             .statusCode(200)
             .body(NAME, equalTo("mailboxes"))
             .body(ARGUMENTS + ".list", hasSize(1))
-            .body(ARGUMENTS + ".list[0].id", equalTo(mailboxId));
+            .body(FIRST_MAILBOX + ".id", equalTo(mailboxId));
     }
 
     @Test
@@ -235,6 +249,67 @@ public abstract class GetMailboxesMethodTest {
             .body(ARGUMENTS + ".list", hasSize(7))
             .body(ARGUMENTS + ".list.name", 
hasItems(expectedMailboxes.toArray()));
     }
+
+    @Test
+    public void getMailboxesShouldReturnSharedWithProperty() throws Exception {
+        String mailboxName = "myMailbox";
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, 
mailboxName);
+        String targetUser1 = "[email protected]";
+        String targetUser2 = "[email protected]";
+        Mailbox myMailbox = 
mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, mailboxName);
+        aclProbe.replaceRights(myMailbox.generateAssociatedPath(), 
targetUser1, new Rfc4314Rights(Right.Read, Right.Administer));
+        aclProbe.replaceRights(myMailbox.generateAssociatedPath(), 
targetUser2, new Rfc4314Rights(Right.Read, Right.Lookup));
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMailboxes\", {\"ids\": [\"" + 
myMailbox.getMailboxId().serialize() + "\"]}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("mailboxes"))
+            .body(FIRST_MAILBOX + ".name", equalTo(mailboxName))
+            .body(FIRST_MAILBOX + ".sharedWith", hasEntry(targetUser1, 
ImmutableList.of(ADMINISTER, READ)))
+            .body(FIRST_MAILBOX + ".sharedWith", hasEntry(targetUser2, 
ImmutableList.of(LOOKUP, READ)));
+    }
+
+    @Test
+    public void getMailboxShouldReturnEmptySharedWithWhenNoDelegation() throws 
Exception {
+        String mailboxName = "myMailbox";
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, 
mailboxName);
+        Mailbox myMailbox = 
mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, mailboxName);
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMailboxes\", {\"ids\": [\"" + 
myMailbox.getMailboxId().serialize() + "\"]}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("mailboxes"))
+            .body(FIRST_MAILBOX + ".name", equalTo(mailboxName))
+            .body(FIRST_MAILBOX + ".sharedWith", is(ImmutableMap.of()));
+    }
+
+    @Test
+    public void nonHandledRightsShouldBeFilteredOut() throws Exception {
+        String mailboxName = "myMailbox";
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, 
mailboxName);
+        String targetUser1 = "[email protected]";
+        Mailbox myMailbox = 
mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, mailboxName);
+        aclProbe.replaceRights(myMailbox.generateAssociatedPath(), 
targetUser1, new Rfc4314Rights(Right.Read, Right.Post));
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMailboxes\", {\"ids\": [\"" + 
myMailbox.getMailboxId().serialize() + "\"]}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("mailboxes"))
+            .body(FIRST_MAILBOX + ".name", equalTo(mailboxName))
+            .body(FIRST_MAILBOX + ".sharedWith", hasEntry(targetUser1, 
ImmutableList.of(READ)));
+    }
     
     @Test
     public void getMailboxesShouldErrorInvalidArgumentsWhenRequestIsInvalid() 
throws Exception {
@@ -325,19 +400,19 @@ public abstract class GetMailboxesMethodTest {
             .statusCode(200)
             .body(NAME, equalTo("mailboxes"))
             .body(ARGUMENTS + ".list.name", hasItem("name"))
-            .body(ARGUMENTS + ".list[0].parentId", nullValue())
-            .body(ARGUMENTS + ".list[0].role", nullValue())
-            .body(ARGUMENTS + ".list[0].sortOrder", equalTo(1000))
-            .body(ARGUMENTS + ".list[0].mustBeOnlyMailbox", equalTo(false))
-            .body(ARGUMENTS + ".list[0].mayReadItems", equalTo(false))
-            .body(ARGUMENTS + ".list[0].mayAddItems", equalTo(false))
-            .body(ARGUMENTS + ".list[0].mayRemoveItems", equalTo(false))
-            .body(ARGUMENTS + ".list[0].mayCreateChild", equalTo(false))
-            .body(ARGUMENTS + ".list[0].mayRename", equalTo(false))
-            .body(ARGUMENTS + ".list[0].mayDelete", equalTo(false))
-            .body(ARGUMENTS + ".list[0].totalMessages", equalTo(1))
-            .body(ARGUMENTS + ".list[0].unreadMessages", equalTo(1))
-            .body(ARGUMENTS + ".list[0].unreadThreads", equalTo(0));
+            .body(FIRST_MAILBOX + ".parentId", nullValue())
+            .body(FIRST_MAILBOX + ".role", nullValue())
+            .body(FIRST_MAILBOX + ".sortOrder", equalTo(1000))
+            .body(FIRST_MAILBOX + ".mustBeOnlyMailbox", equalTo(false))
+            .body(FIRST_MAILBOX + ".mayReadItems", equalTo(false))
+            .body(FIRST_MAILBOX + ".mayAddItems", equalTo(false))
+            .body(FIRST_MAILBOX + ".mayRemoveItems", equalTo(false))
+            .body(FIRST_MAILBOX + ".mayCreateChild", equalTo(false))
+            .body(FIRST_MAILBOX + ".mayRename", equalTo(false))
+            .body(FIRST_MAILBOX + ".mayDelete", equalTo(false))
+            .body(FIRST_MAILBOX + ".totalMessages", equalTo(1))
+            .body(FIRST_MAILBOX + ".unreadMessages", equalTo(1))
+            .body(FIRST_MAILBOX + ".unreadThreads", equalTo(0));
     }
 
     @Test
@@ -353,21 +428,21 @@ public abstract class GetMailboxesMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("mailboxes"))
-            .body(ARGUMENTS + ".list[0].id", not(isEmptyOrNullString()))
-            .body(ARGUMENTS + ".list[0].name", nullValue())
-            .body(ARGUMENTS + ".list[0].parentId", nullValue())
-            .body(ARGUMENTS + ".list[0].role", nullValue())
-            .body(ARGUMENTS + ".list[0].sortOrder", equalTo(1000))
-            .body(ARGUMENTS + ".list[0].mustBeOnlyMailbox", nullValue())
-            .body(ARGUMENTS + ".list[0].mayReadItems", nullValue())
-            .body(ARGUMENTS + ".list[0].mayAddItems", nullValue())
-            .body(ARGUMENTS + ".list[0].mayRemoveItems", nullValue())
-            .body(ARGUMENTS + ".list[0].mayCreateChild", nullValue())
-            .body(ARGUMENTS + ".list[0].mayRename", nullValue())
-            .body(ARGUMENTS + ".list[0].mayDelete", nullValue())
-            .body(ARGUMENTS + ".list[0].totalMessages", nullValue())
-            .body(ARGUMENTS + ".list[0].unreadMessages", equalTo(0))
-            .body(ARGUMENTS + ".list[0].unreadThreads", nullValue());
+            .body(FIRST_MAILBOX + ".id", not(isEmptyOrNullString()))
+            .body(FIRST_MAILBOX + ".name", nullValue())
+            .body(FIRST_MAILBOX + ".parentId", nullValue())
+            .body(FIRST_MAILBOX + ".role", nullValue())
+            .body(FIRST_MAILBOX + ".sortOrder", equalTo(1000))
+            .body(FIRST_MAILBOX + ".mustBeOnlyMailbox", nullValue())
+            .body(FIRST_MAILBOX + ".mayReadItems", nullValue())
+            .body(FIRST_MAILBOX + ".mayAddItems", nullValue())
+            .body(FIRST_MAILBOX + ".mayRemoveItems", nullValue())
+            .body(FIRST_MAILBOX + ".mayCreateChild", nullValue())
+            .body(FIRST_MAILBOX + ".mayRename", nullValue())
+            .body(FIRST_MAILBOX + ".mayDelete", nullValue())
+            .body(FIRST_MAILBOX + ".totalMessages", nullValue())
+            .body(FIRST_MAILBOX + ".unreadMessages", equalTo(0))
+            .body(FIRST_MAILBOX + ".unreadThreads", nullValue());
     }
 
     @Test
@@ -382,8 +457,8 @@ public abstract class GetMailboxesMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("mailboxes"))
-            .body(ARGUMENTS + ".list[0].id", not(isEmptyOrNullString()))
-            .body(ARGUMENTS + ".list[0].name", nullValue());
+            .body(FIRST_MAILBOX + ".id", not(isEmptyOrNullString()))
+            .body(FIRST_MAILBOX + ".name", nullValue());
     }
 
     @Test
@@ -398,8 +473,8 @@ public abstract class GetMailboxesMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("mailboxes"))
-            .body(ARGUMENTS + ".list[0].id", not(isEmptyOrNullString()))
-            .body(ARGUMENTS + ".list[0].name", nullValue());
+            .body(FIRST_MAILBOX + ".id", not(isEmptyOrNullString()))
+            .body(FIRST_MAILBOX + ".name", nullValue());
     }
 
     @Test
@@ -438,7 +513,7 @@ public abstract class GetMailboxesMethodTest {
             .statusCode(200)
             .body(NAME, equalTo("mailboxes"))
             .body(ARGUMENTS + ".list", hasSize(1))
-            .body(ARGUMENTS + ".list[0].role", 
equalTo(DefaultMailboxes.OUTBOX.toLowerCase(Locale.US)));
+            .body(FIRST_MAILBOX + ".role", 
equalTo(DefaultMailboxes.OUTBOX.toLowerCase(Locale.US)));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ac2d416/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
index 23d327c..9890c85 100644
--- 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
@@ -24,6 +24,7 @@ import java.util.Optional;
 import javax.inject.Inject;
 
 import org.apache.james.jmap.model.mailbox.Mailbox;
+import org.apache.james.jmap.model.mailbox.Rights;
 import org.apache.james.jmap.model.mailbox.Role;
 import org.apache.james.jmap.model.mailbox.SortOrder;
 import org.apache.james.mailbox.MailboxManager;
@@ -42,6 +43,7 @@ import com.google.common.base.Splitter;
 import com.google.common.base.Throwables;
 
 public class MailboxFactory {
+    public static final boolean NO_RESET_RECENT = false;
     private final MailboxManager mailboxManager;
 
     public static class MailboxBuilder {
@@ -98,6 +100,8 @@ public class MailboxFactory {
         MailboxPath mailboxPath = messageManager.getMailboxPath();
         Optional<Role> role = Role.from(mailboxPath.getName());
         MailboxCounters mailboxCounters = 
messageManager.getMailboxCounters(mailboxSession);
+        MessageManager.MetaData metaData = 
messageManager.getMetaData(NO_RESET_RECENT, mailboxSession, 
MessageManager.MetaData.FetchGroup.NO_COUNT);
+
         return Mailbox.builder()
             .id(messageManager.getId())
             .name(getName(mailboxPath, mailboxSession))
@@ -106,6 +110,7 @@ public class MailboxFactory {
             .unreadMessages(mailboxCounters.getUnseen())
             .totalMessages(mailboxCounters.getCount())
             .sortOrder(SortOrder.getSortOrder(role))
+            .sharedWith(Rights.fromACL(metaData.getACL()))
             .build();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ac2d416/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
index cddb101..d0b8144 100644
--- 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
@@ -60,9 +60,11 @@ public class Mailbox {
         private long unreadMessages;
         private long totalThreads;
         private long unreadThreads;
+        private Optional<Rights> sharedWith;
 
         private Builder() {
             parentId = Optional.empty();
+            sharedWith = Optional.empty();
         }
 
         public Builder id(MailboxId id) {
@@ -147,12 +149,17 @@ public class Mailbox {
             return this;
         }
 
+        public Builder sharedWith(Rights sharedWith) {
+            this.sharedWith = Optional.of(sharedWith);
+            return this;
+        }
+
         public Mailbox build() {
             Preconditions.checkState(!Strings.isNullOrEmpty(name), "'name' is 
mandatory");
             Preconditions.checkState(id != null, "'id' is mandatory");
 
             return new Mailbox(id, name, parentId, role, sortOrder, 
mustBeOnlyMailbox, mayReadItems, mayAddItems, mayRemoveItems, mayCreateChild, 
mayRename, mayDelete,
-                    totalMessages, unreadMessages, totalThreads, 
unreadThreads);
+                    totalMessages, unreadMessages, totalThreads, 
unreadThreads, sharedWith.orElse(Rights.EMPTY));
         }
     }
 
@@ -172,10 +179,11 @@ public class Mailbox {
     private final long unreadMessages;
     private final long totalThreads;
     private final long unreadThreads;
+    private final Rights sharedWith;
 
     @VisibleForTesting Mailbox(MailboxId id, String name, Optional<MailboxId> 
parentId, Optional<Role> role, SortOrder sortOrder, boolean mustBeOnlyMailbox,
-            boolean mayReadItems, boolean mayAddItems, boolean mayRemoveItems, 
boolean mayCreateChild, boolean mayRename, boolean mayDelete,
-            long totalMessages, long unreadMessages, long totalThreads, long 
unreadThreads) {
+                               boolean mayReadItems, boolean mayAddItems, 
boolean mayRemoveItems, boolean mayCreateChild, boolean mayRename, boolean 
mayDelete,
+                               long totalMessages, long unreadMessages, long 
totalThreads, long unreadThreads, Rights sharedWith) {
 
         this.id = id;
         this.name = name;
@@ -193,6 +201,7 @@ public class Mailbox {
         this.unreadMessages = unreadMessages;
         this.totalThreads = totalThreads;
         this.unreadThreads = unreadThreads;
+        this.sharedWith = sharedWith;
     }
 
     public MailboxId getId() {
@@ -259,6 +268,10 @@ public class Mailbox {
         return unreadThreads;
     }
 
+    public Rights getSharedWith() {
+        return sharedWith;
+    }
+
     @Override
     public final boolean equals(Object obj) {
         if (obj instanceof Mailbox) {
@@ -278,7 +291,8 @@ public class Mailbox {
                 && Objects.equals(this.totalMessages, other.totalMessages)
                 && Objects.equals(this.unreadMessages, other.unreadMessages)
                 && Objects.equals(this.totalThreads, other.totalThreads)
-                && Objects.equals(this.unreadThreads, other.unreadThreads);
+                && Objects.equals(this.unreadThreads, other.unreadThreads)
+                && Objects.equals(this.sharedWith, other.sharedWith);
         }
         return false;
     }
@@ -286,7 +300,8 @@ public class Mailbox {
     @Override
     public final int hashCode() {
         return Objects.hash(id, name, parentId, role, sortOrder, 
mustBeOnlyMailbox, mayReadItems, mayAddItems, 
-                mayRemoveItems, mayCreateChild, mayRename, mayDelete, 
totalMessages, unreadMessages, totalThreads, unreadThreads);
+            mayRemoveItems, mayCreateChild, mayRename, mayDelete, 
totalMessages, unreadMessages, totalThreads,
+            unreadThreads, sharedWith);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ac2d416/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxTest.java
index 1ac869f..91275df 100644
--- 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxTest.java
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxTest.java
@@ -63,7 +63,7 @@ public class MailboxTest {
     @Test
     public void buildShouldWork() {
         Mailbox expectedMailbox = new Mailbox(InMemoryId.of(1), "name", 
Optional.of(InMemoryId.of(0)), Optional.of(Role.DRAFTS), SortOrder.of(123),
-                true, true, true, true, true, true, true, 456, 789, 741, 852);
+                true, true, true, true, true, true, true, 456, 789, 741, 852, 
Rights.EMPTY);
 
         Mailbox mailbox = Mailbox.builder()
             .id(InMemoryId.of(1))


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to