MAILBOX-355 PropagateLookupRightListener should retrieve MailboxPath rather than read it from the event
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/16e4d9f9 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/16e4d9f9 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/16e4d9f9 Branch: refs/heads/master Commit: 16e4d9f93d411cebbf4f39d8420f379e357b692c Parents: a788cf3 Author: Benoit Tellier <btell...@linagora.com> Authored: Tue Dec 4 14:32:48 2018 +0700 Committer: Benoit Tellier <btell...@linagora.com> Committed: Wed Dec 5 16:34:25 2018 +0700 ---------------------------------------------------------------------- .../event/PropagateLookupRightListener.java | 51 +++++++++++--------- .../event/PropagateLookupRightListenerTest.java | 2 +- 2 files changed, 28 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/16e4d9f9/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java index 7767a94..88b4b48 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java @@ -25,6 +25,7 @@ import javax.inject.Inject; import org.apache.james.mailbox.Event; import org.apache.james.mailbox.MailboxListener; +import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.RightManager; import org.apache.james.mailbox.acl.ACLDiff; @@ -40,10 +41,12 @@ public class PropagateLookupRightListener implements MailboxListener { private static final Logger LOGGER = LoggerFactory.getLogger(PropagateLookupRightListener.class); private final RightManager rightManager; + private final MailboxManager mailboxManager; @Inject - public PropagateLookupRightListener(RightManager rightManager) { + PropagateLookupRightListener(RightManager rightManager, MailboxManager mailboxManager) { this.rightManager = rightManager; + this.mailboxManager = mailboxManager; } @Override @@ -53,36 +56,36 @@ public class PropagateLookupRightListener implements MailboxListener { @Override public void event(Event event) { - MailboxSession mailboxSession = event.getSession(); - - if (event instanceof MailboxACLUpdated) { - MailboxACLUpdated aclUpdateEvent = (MailboxACLUpdated) event; + try { + MailboxSession mailboxSession = event.getSession(); - updateLookupRightOnParent(mailboxSession, aclUpdateEvent.getMailboxPath(), aclUpdateEvent.getAclDiff()); - } else if (event instanceof MailboxRenamed) { - MailboxRenamed renamedEvent = (MailboxRenamed) event; - updateLookupRightOnParent(mailboxSession, renamedEvent.getNewPath()); - } - } + if (event instanceof MailboxACLUpdated) { + MailboxACLUpdated aclUpdateEvent = (MailboxACLUpdated) event; + MailboxPath mailboxPath = mailboxManager.getMailbox(aclUpdateEvent.getMailboxId(), mailboxSession).getMailboxPath(); - private void updateLookupRightOnParent(MailboxSession session, MailboxPath path) { - try { - MailboxACL acl = rightManager.listRights(path, session); - listAncestors(session, path) - .forEach(parentMailboxPath -> - updateLookupRight( - session, - parentMailboxPath, - acl.getEntries() - .entrySet() - .stream() - .map(entry -> new Entry(entry.getKey(), entry.getValue())) - )); + updateLookupRightOnParent(mailboxSession, mailboxPath, aclUpdateEvent.getAclDiff()); + } else if (event instanceof MailboxRenamed) { + MailboxRenamed renamedEvent = (MailboxRenamed) event; + updateLookupRightOnParent(mailboxSession, renamedEvent.getNewPath()); + } } catch (MailboxException e) { throw new RuntimeException(e); } } + private void updateLookupRightOnParent(MailboxSession session, MailboxPath path) throws MailboxException { + MailboxACL acl = rightManager.listRights(path, session); + listAncestors(session, path) + .forEach(parentMailboxPath -> + updateLookupRight( + session, + parentMailboxPath, + acl.getEntries() + .entrySet() + .stream() + .map(entry -> new Entry(entry.getKey(), entry.getValue())))); + } + private void updateLookupRightOnParent(MailboxSession mailboxSession, MailboxPath mailboxPath, ACLDiff aclDiff) { listAncestors(mailboxSession, mailboxPath) .forEach(path -> http://git-wip-us.apache.org/repos/asf/james-project/blob/16e4d9f9/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java index d89f1bc..2bfdcde 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java @@ -80,7 +80,7 @@ public class PropagateLookupRightListenerTest { storeRightManager = resources.getStoreRightManager(); mailboxMapper = storeMailboxManager.getMapperFactory(); - testee = new PropagateLookupRightListener(storeRightManager); + testee = new PropagateLookupRightListener(storeRightManager, storeMailboxManager); storeMailboxManager.addGlobalListener(testee, mailboxSession); parentMailboxId = storeMailboxManager.createMailbox(PARENT_MAILBOX, mailboxSession).get(); --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org