james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [1/9] james-project git commit: MAILBOX-318 Use SetMailboxes method to update rights instead of the ACLProbe
Date Wed, 08 Nov 2017 07:29:48 GMT
Repository: james-project
Updated Branches:
  refs/heads/master ae155b8d3 -> 0e99fb117


MAILBOX-318 Use SetMailboxes method to update rights instead of the ACLProbe


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

Branch: refs/heads/master
Commit: 562eeaab0279728d0e31a888e9947f16de5bc827
Parents: 30483cf
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Fri Nov 3 11:26:15 2017 +0100
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Tue Nov 7 15:33:42 2017 +0100

----------------------------------------------------------------------
 .../cucumber/SetMailboxesMethodStepdefs.java    | 47 +++++++++++++++-----
 1 file changed, 37 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/562eeaab/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
index 449a407..d26df19 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
@@ -24,17 +24,18 @@ import static org.assertj.core.api.Assertions.assertThat;
 import java.io.ByteArrayInputStream;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
 import javax.inject.Inject;
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.modules.ACLProbeImpl;
 
 import com.github.fge.lambdas.Throwing;
 import com.jayway.awaitility.Awaitility;
@@ -87,18 +88,44 @@ public class SetMailboxesMethodStepdefs {
     }
 
     @Given("^\"([^\"]*)\" shares its mailbox \"([^\"]*)\" with rights \"([^\"]*)\" with \"([^\"]*)\"$")
-    public void shareMailboxWithRight(String owner, String mailbox, String rights, String
shareTo) throws Throwable {
-        MailboxPath mailboxPath = MailboxPath.forUser(owner, mailbox);
-
-        mainStepdefs.aclProbe.replaceRights(mailboxPath, shareTo, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights(rights));
+    public void shareMailboxWithRight(String owner, String mailboxName, String rights, String
shareTo) throws Throwable {
+        userStepdefs.connectUser(owner);
+        Mailbox mailbox = mainStepdefs.mailboxProbe.getMailbox("#private", owner, mailboxName);
+        String mailboxId = mailbox.getMailboxId().serialize();
+        String requestBody =
+                "[" +
+                    "  [ \"setMailboxes\"," +
+                    "    {" +
+                    "      \"update\": {" +
+                    "        \"" + mailboxId + "\" : {" +
+                    "          \"sharedWith\" : { \"" + shareTo + "\" : " + rightsAsString(rights)
+ " }" +
+                    "        }" +
+                    "      }" +
+                    "    }," +
+                    "    \"#0\"" +
+                    "  ]" +
+                    "]";
+        httpClient.post(requestBody);
+    }
+    
+    private String rightsAsString(String rights) throws UnsupportedRightException {
+        return MailboxACL.Rfc4314Rights
+            .fromSerializedRfc4314Rights(rights)
+            .list()
+            .stream()
+            .map(MailboxACL.Right::asCharacter)
+            .map(String::valueOf)
+            .map(this::surroundWithDoubleQuotes)
+            .collect(Collectors.joining(", ", "[ ", " ]"));
+    }
+    
+    private String surroundWithDoubleQuotes(String input) {
+        return "\"" + input + "\"";
     }
     
     @Given("^\"([^\"]*)\" shares (?:his|her) mailbox \"([^\"]*)\" with \"([^\"]*)\" with
\"([^\"]*)\" rights$")
-    public void shareMailbox(String owner, String mailbox, String shareTo, String rights)
throws Throwable {
-        mainStepdefs.jmapServer.getProbe(ACLProbeImpl.class)
-            .replaceRights(MailboxPath.forUser(owner, mailbox),
-                shareTo,
-                MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights(rights));
+    public void shareMailbox(String owner, String mailboxName, String shareTo, String rights)
throws Throwable {
+        shareMailboxWithRight(owner, mailboxName, rights, shareTo);
     }
 
     @When("^renaming mailbox \"([^\"]*)\" to \"([^\"]*)\"")


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