james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject [25/27] james-project git commit: MAILBOX-310 Correct WebAdmin mailbox handling
Date Thu, 05 Oct 2017 18:02:37 GMT
MAILBOX-310 Correct WebAdmin mailbox handling


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

Branch: refs/heads/master
Commit: 636e5a40f9f4753a4d8358ed590f286c0501d223
Parents: b44b9bb
Author: benwa <btellier@linagora.com>
Authored: Thu Oct 5 09:13:29 2017 +0700
Committer: Matthieu Baechler <matthieu@apache.org>
Committed: Thu Oct 5 20:00:39 2017 +0200

----------------------------------------------------------------------
 server/protocols/webadmin/webadmin-mailbox/pom.xml      |  6 ++++++
 .../james/webadmin/service/UserMailboxesService.java    | 12 +++++-------
 .../james/webadmin/routes/UserMailboxesRoutesTest.java  |  4 ++--
 3 files changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/636e5a40/server/protocols/webadmin/webadmin-mailbox/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/pom.xml b/server/protocols/webadmin/webadmin-mailbox/pom.xml
index 471f8dd..96d5eee 100644
--- a/server/protocols/webadmin/webadmin-mailbox/pom.xml
+++ b/server/protocols/webadmin/webadmin-mailbox/pom.xml
@@ -39,6 +39,12 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>apache-james-mailbox-api</artifactId>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>apache-james-mailbox-memory</artifactId>
             <scope>test</scope>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/636e5a40/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
index 225d0bf..af0b658 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
@@ -47,9 +47,7 @@ import com.google.common.base.Strings;
 
 
 public class UserMailboxesService {
-
     private static final Logger LOGGER = LoggerFactory.getLogger(UserMailboxesService.class);
-    private static final String USER_NAME = "webAdmin";
 
     private final MailboxManager mailboxManager;
     private final UsersRepository usersRepository;
@@ -62,7 +60,7 @@ public class UserMailboxesService {
 
     public void createMailbox(String username, MailboxName mailboxName) throws MailboxException,
UsersRepositoryException {
         usernamePreconditions(username);
-        MailboxSession mailboxSession = mailboxManager.createSystemSession(USER_NAME);
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
         try {
             mailboxManager.createMailbox(
                 convertToMailboxPath(username, mailboxName.asString(), mailboxSession),
@@ -74,7 +72,7 @@ public class UserMailboxesService {
 
     public void deleteMailboxes(String username) throws MailboxException, UsersRepositoryException
{
         usernamePreconditions(username);
-        MailboxSession mailboxSession = mailboxManager.createSystemSession(USER_NAME);
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
         listUserMailboxes(mailboxSession)
             .map(MailboxMetaData::getPath)
             .forEach(Throwing.consumer(mailboxPath -> deleteMailbox(mailboxSession, mailboxPath)));
@@ -82,7 +80,7 @@ public class UserMailboxesService {
 
     public List<MailboxResponse> listMailboxes(String username) throws MailboxException,
UsersRepositoryException {
         usernamePreconditions(username);
-        MailboxSession mailboxSession = mailboxManager.createSystemSession(USER_NAME);
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
         return listUserMailboxes(mailboxSession)
             .map(mailboxMetaData -> new MailboxResponse(mailboxMetaData.getPath().getName()))
             .collect(Guavate.toImmutableList());
@@ -90,7 +88,7 @@ public class UserMailboxesService {
 
     public boolean testMailboxExists(String username, MailboxName mailboxName) throws MailboxException,
UsersRepositoryException {
         usernamePreconditions(username);
-        MailboxSession mailboxSession = mailboxManager.createSystemSession(USER_NAME);
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
         return mailboxManager.mailboxExists(
             convertToMailboxPath(username, mailboxName.asString(), mailboxSession),
             mailboxSession);
@@ -98,7 +96,7 @@ public class UserMailboxesService {
 
     public void deleteMailbox(String username, MailboxName mailboxName) throws MailboxException,
UsersRepositoryException, MailboxHaveChildrenException {
         usernamePreconditions(username);
-        MailboxSession mailboxSession = mailboxManager.createSystemSession(USER_NAME);
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
         MailboxPath mailboxPath = convertToMailboxPath(username, mailboxName.asString(),
mailboxSession);
         listChildren(mailboxPath, mailboxSession)
             .forEach(Throwing.consumer(path -> deleteMailbox(mailboxSession, path)));

http://git-wip-us.apache.org/repos/asf/james-project/blob/636e5a40/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
index 01b6212..943a159 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
@@ -37,7 +37,6 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -46,6 +45,7 @@ import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
 import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
+import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
@@ -566,7 +566,7 @@ public class UserMailboxesRoutesTest {
         @Before
         public void setUp() throws Exception {
             mailboxManager = mock(MailboxManager.class);
-            when(mailboxManager.createSystemSession(any())).thenReturn(mock(MailboxSession.class));
+            when(mailboxManager.createSystemSession(any())).thenReturn(new MockMailboxSession(USERNAME));
 
             createServer(mailboxManager);
         }


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