james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject [01/27] james-project git commit: MAILBOX-310 MailboxACL should present only users ACL
Date Thu, 05 Oct 2017 18:02:13 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 10da4351c -> f52eaa62a


MAILBOX-310 MailboxACL should present only users ACL


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

Branch: refs/heads/master
Commit: 929f31dcb9f24e132c0eba6ec6358e4a3a8ab8ab
Parents: 434e040
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Fri Sep 29 15:26:38 2017 +0200
Committer: benwa <btellier@linagora.com>
Committed: Wed Oct 4 16:29:09 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/model/MailboxACL.java  |  6 +++
 .../james/mailbox/model/MailboxACLTest.java     | 41 ++++++++++++++++++++
 2 files changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/929f31dc/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
index e414ebc..a38e601 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
@@ -878,4 +878,10 @@ public class MailboxACL {
         return union(new MailboxACL(new Entry(key, mailboxACLRights)));
     }
 
+    public Map<EntryKey, Rfc4314Rights> ofPositiveNameType(NameType nameType) {
+        return this.entries.entrySet().stream()
+            .filter(entry -> !entry.getKey().isNegative())
+            .filter(entry -> entry.getKey().getNameType().equals(nameType))
+            .collect(Guavate.entriesToMap());
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/929f31dc/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java
index 7bbb4eb..fccabd0 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java
@@ -30,10 +30,14 @@ import java.util.Properties;
 import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.MailboxACL.Entry;
 import org.apache.james.mailbox.model.MailboxACL.EntryKey;
+import org.apache.james.mailbox.model.MailboxACL.NameType;
 import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights;
+import org.assertj.core.data.MapEntry;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableMap;
+
 /**
  * @author Peter Palaga
  */
@@ -41,6 +45,7 @@ public class MailboxACLTest {
 
     private static final String USER_1 = "user1";
     private static final String USER_2 = "user2";
+    private static final boolean NEGATIVE = true;
 
     private static final String ae = "ae";
     private static final String ik = "ik";
@@ -224,4 +229,40 @@ public class MailboxACLTest {
             .isEqualTo(MailboxACL.EMPTY);
     }
 
+    @Test
+    public void usersACLShouldReturnEmptyMapWhenEmpty() {
+        assertThat(MailboxACL.EMPTY.ofPositiveNameType(NameType.user))
+            .isEmpty();
+    }
+
+    @Test
+    public void usersACLShouldReturnEmptyMapWhenNoUserEntry() {
+        MailboxACL mailboxACL = new MailboxACL(
+                ImmutableMap.of(EntryKey.createGroupEntryKey("group"), MailboxACL.FULL_RIGHTS,
+                    EntryKey.createGroupEntryKey("group2"), MailboxACL.NO_RIGHTS));
+        assertThat(mailboxACL.ofPositiveNameType(NameType.user))
+            .isEmpty();
+    }
+
+    @Test
+    public void usersACLShouldReturnOnlyUsersMapWhenSomeUserEntries() throws Exception {
+        MailboxACL.Rfc4314Rights rights = MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("aei");
+        MailboxACL mailboxACL = new MailboxACL(
+            ImmutableMap.of(EntryKey.createUserEntryKey("user1"), MailboxACL.FULL_RIGHTS,
+                EntryKey.createGroupEntryKey("group"), MailboxACL.FULL_RIGHTS,
+                EntryKey.createUserEntryKey("user2"), rights,
+                EntryKey.createGroupEntryKey("group2"), MailboxACL.NO_RIGHTS));
+        assertThat(mailboxACL.ofPositiveNameType(NameType.user))
+            .containsOnly(
+                MapEntry.entry(EntryKey.createUserEntryKey("user1"), MailboxACL.FULL_RIGHTS),
+                MapEntry.entry(EntryKey.createUserEntryKey("user2"), rights));
+    }
+
+    @Test
+    public void ofPositiveNameTypeShouldFilterOutNegativeEntries() throws Exception {
+        MailboxACL mailboxACL = new MailboxACL(
+            ImmutableMap.of(EntryKey.createUserEntryKey("user1", NEGATIVE), MailboxACL.FULL_RIGHTS));
+        assertThat(mailboxACL.ofPositiveNameType(NameType.user))
+            .isEmpty();
+    }
 }


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