james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [4/7] james-project git commit: JAMES-2179 Allow ignoring some JMAP Rights entry
Date Wed, 11 Oct 2017 03:09:32 GMT
JAMES-2179 Allow ignoring some JMAP Rights entry


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

Branch: refs/heads/master
Commit: 543aebcf36726a40c659ca6fe6b07ee7a7ca2747
Parents: 617512b
Author: benwa <btellier@linagora.com>
Authored: Tue Oct 10 17:16:24 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Oct 11 10:08:49 2017 +0700

----------------------------------------------------------------------
 .../methods/SetMailboxesUpdateProcessor.java    |  6 +++-
 .../apache/james/jmap/model/mailbox/Rights.java | 13 ++++++++
 .../james/jmap/model/mailbox/RightsTest.java    | 31 ++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/543aebcf/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
index 0e2ad14..673741a 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
@@ -210,7 +210,11 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor
{
         MailboxPath originMailboxPath = mailboxManager.getMailbox(mailbox.getId(), mailboxSession).getMailboxPath();
         MailboxPath destinationMailboxPath = computeNewMailboxPath(mailbox, originMailboxPath,
updateRequest, mailboxSession);
         if (updateRequest.getSharedWith().isPresent()) {
-            mailboxManager.setRights(originMailboxPath, updateRequest.getSharedWith().get().toMailboxAcl(),
mailboxSession);
+            mailboxManager.setRights(originMailboxPath,
+                updateRequest.getSharedWith()
+                    .get()
+                    .toMailboxAcl(),
+                mailboxSession);
         }
         if (!originMailboxPath.equals(destinationMailboxPath)) {
             mailboxManager.renameMailbox(originMailboxPath, destinationMailboxPath, mailboxSession);

http://git-wip-us.apache.org/repos/asf/james-project/blob/543aebcf/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Rights.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Rights.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Rights.java
index 38ce0b3..2b15585 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Rights.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Rights.java
@@ -27,6 +27,7 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.function.BinaryOperator;
 
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.EntryKey;
 import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights;
@@ -200,6 +201,18 @@ public class Rights {
         return rights.asMap();
     }
 
+    public Rights removeEntriesFor(Username username) {
+        return new Rights(
+            rights.asMap()
+                .entrySet()
+                .stream()
+                .filter(entry -> entry.getKey().equals(username))
+                .flatMap(entry -> entry.getValue()
+                    .stream()
+                    .map(v -> Pair.of(entry.getKey(), v)))
+                .collect(Guavate.toImmutableListMultimap(Pair::getKey, Pair::getValue)));
+    }
+
     public MailboxACL toMailboxAcl() {
         BinaryOperator<MailboxACL> union = Throwing.binaryOperator(MailboxACL::union);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/543aebcf/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RightsTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RightsTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RightsTest.java
index a427144..5618995 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RightsTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RightsTest.java
@@ -35,6 +35,8 @@ import nl.jqno.equalsverifier.EqualsVerifier;
 public class RightsTest {
 
     public static final boolean NEGATIVE = true;
+    public static final Rights.Username USERNAME = new Rights.Username("username");
+    public static final Rights.Username OTHER_USERNAME = new Rights.Username("otherUsername");
 
     @Test
     public void rightsShouldMatchBeanContract() {
@@ -161,4 +163,33 @@ public class RightsTest {
                 new Entry(user2, MailboxACL.Right.PerformExpunge, MailboxACL.Right.Lookup)));
     }
 
+    @Test
+    public void removeEntriesForShouldNotModifyEmptyRights() {
+        assertThat(Rights.EMPTY.removeEntriesFor(USERNAME))
+            .isEqualTo(Rights.EMPTY);
+    }
+
+    @Test
+    public void removeEntriesForShouldRemoveUsernameEntryWhenPresent() {
+        Rights rights = Rights.builder()
+            .delegateTo(USERNAME, Rights.Right.Lookup)
+            .build();
+        assertThat(rights.removeEntriesFor(USERNAME))
+            .isEqualTo(Rights.EMPTY);
+    }
+
+    @Test
+    public void removeEntriesForShouldOnlyRemoveSpecifiedUsername() {
+        Rights rights = Rights.builder()
+            .delegateTo(USERNAME, Rights.Right.Lookup)
+            .delegateTo(OTHER_USERNAME, Rights.Right.Lookup)
+            .build();
+
+        Rights expected = Rights.builder()
+            .delegateTo(OTHER_USERNAME, Rights.Right.Lookup)
+            .build();
+
+        assertThat(rights.removeEntriesFor(USERNAME))
+            .isEqualTo(expected);
+    }
 }
\ No newline at end of file


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