You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "Arsnael (via GitHub)" <gi...@apache.org> on 2023/02/22 08:04:31 UTC

[GitHub] [james-project] Arsnael commented on a diff in pull request #1450: JAMES-3885 Migrates mailboxes, acls, subscriptions upon username changes

Arsnael commented on code in PR #1450:
URL: https://github.com/apache/james-project/pull/1450#discussion_r1113944424


##########
server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryUsernameChangeIntegrationTest.java:
##########
@@ -78,14 +72,36 @@ void setUp(GuiceJamesServer jmapServer) throws Exception {
         dataProbe.addUser(ALICE.asString(), ALICE_PASSWORD);
         dataProbe.addUser(CEDRIC.asString(), CEDRIC_PASSWORD);
 
-        jmapPort = jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort();
+        Port jmapPort = jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort();
         RestAssured.requestSpecification = jmapRequestSpecBuilder
             .setPort(jmapPort.getValue())
             .build();
 
         webAdminApi = WebAdminUtils.spec(jmapServer.getProbe(WebAdminGuiceProbe.class).getWebAdminPort());
     }
 
+    @Test
+    void shouldMigrateMailboxes() {
+        webAdminApi.put("/users/" + ALICE.asString() + "/mailboxes/test").prettyPeek();

Review Comment:
   debug spotted



##########
server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryUsernameChangeIntegrationTest.java:
##########
@@ -78,14 +72,36 @@ void setUp(GuiceJamesServer jmapServer) throws Exception {
         dataProbe.addUser(ALICE.asString(), ALICE_PASSWORD);
         dataProbe.addUser(CEDRIC.asString(), CEDRIC_PASSWORD);
 
-        jmapPort = jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort();
+        Port jmapPort = jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort();
         RestAssured.requestSpecification = jmapRequestSpecBuilder
             .setPort(jmapPort.getValue())
             .build();
 
         webAdminApi = WebAdminUtils.spec(jmapServer.getProbe(WebAdminGuiceProbe.class).getWebAdminPort());
     }
 
+    @Test
+    void shouldMigrateMailboxes() {
+        webAdminApi.put("/users/" + ALICE.asString() + "/mailboxes/test").prettyPeek();
+
+        String taskId = webAdminApi
+            .queryParam("action", "rename")
+            .post("/users/" + ALICE.asString() + "/rename/" + BOB.asString()).prettyPeek()

Review Comment:
   debug spotted



##########
server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryUsernameChangeIntegrationTest.java:
##########
@@ -78,14 +72,36 @@ void setUp(GuiceJamesServer jmapServer) throws Exception {
         dataProbe.addUser(ALICE.asString(), ALICE_PASSWORD);
         dataProbe.addUser(CEDRIC.asString(), CEDRIC_PASSWORD);
 
-        jmapPort = jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort();
+        Port jmapPort = jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort();
         RestAssured.requestSpecification = jmapRequestSpecBuilder
             .setPort(jmapPort.getValue())
             .build();
 
         webAdminApi = WebAdminUtils.spec(jmapServer.getProbe(WebAdminGuiceProbe.class).getWebAdminPort());
     }
 
+    @Test
+    void shouldMigrateMailboxes() {
+        webAdminApi.put("/users/" + ALICE.asString() + "/mailboxes/test").prettyPeek();
+
+        String taskId = webAdminApi
+            .queryParam("action", "rename")
+            .post("/users/" + ALICE.asString() + "/rename/" + BOB.asString()).prettyPeek()
+            .jsonPath()
+            .get("taskId");
+
+        webAdminApi.get("/tasks/" + taskId + "/await");
+
+        webAdminApi.get("/users/" + ALICE.asString() + "/mailboxes").prettyPeek()

Review Comment:
   debug spotted



##########
server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/ACLUsernameChangeTaskStep.java:
##########
@@ -0,0 +1,95 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.adapter.mailbox;
+
+import java.util.Optional;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.Username;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.SubscriptionManager;
+import org.apache.james.mailbox.exception.SubscriptionException;
+import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxMetaData;
+import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.user.api.UsernameChangeTaskStep;
+import org.apache.james.util.ReactorUtils;
+import org.reactivestreams.Publisher;
+
+import com.github.fge.lambdas.Throwing;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class ACLUsernameChangeTaskStep implements UsernameChangeTaskStep {
+    private final MailboxManager mailboxManager;
+    private final SubscriptionManager subscriptionManager;
+
+    @Inject
+    public ACLUsernameChangeTaskStep(MailboxManager mailboxManager, SubscriptionManager subscriptionManager) {
+        this.mailboxManager = mailboxManager;
+        this.subscriptionManager = subscriptionManager;
+    }
+
+    @Override
+    public StepName name() {
+        return new StepName("ACLUsernameChangeTaskStep");
+    }
+
+    @Override
+    public int priority() {
+        return 3;
+    }
+
+    @Override
+    public Publisher<Void> changeUsername(Username oldUsername, Username newUsername) {
+        MailboxSession oldSession = mailboxManager.createSystemSession(oldUsername);
+        MailboxSession newSession = mailboxManager.createSystemSession(newUsername);
+        return mailboxManager.search(MailboxQuery.builder().matchesAllMailboxNames().build(), oldSession)
+            .filter(mailbox -> !mailbox.getPath().getUser().equals(oldUsername))
+            .concatMap(mailbox -> migrateACLs(oldUsername, newUsername, mailbox))
+            .then(updateSubscriptionsOnDeletedMailboxes(oldUsername, oldSession, newSession));
+    }
+
+    private Mono<Void> updateSubscriptionsOnDeletedMailboxes(Username oldUsername, MailboxSession oldSession, MailboxSession newSession) {
+        try {
+            return Flux.from(subscriptionManager.subscriptionsReactive(oldSession))
+                .filter(subscription -> !subscription.getUser().equals(oldUsername))
+                .concatMap(subscription -> Mono.from(subscriptionManager.subscribeReactive(subscription, newSession))

Review Comment:
   I'm likely a bit confused but aren't we migrating subscriptions already in previous commit?
   In StoreMailboxManager -> renameMailboxReactive -> renameSubscriptionsIfNeeded ?



##########
server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryUsernameChangeIntegrationTest.java:
##########
@@ -78,14 +72,36 @@ void setUp(GuiceJamesServer jmapServer) throws Exception {
         dataProbe.addUser(ALICE.asString(), ALICE_PASSWORD);
         dataProbe.addUser(CEDRIC.asString(), CEDRIC_PASSWORD);
 
-        jmapPort = jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort();
+        Port jmapPort = jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort();
         RestAssured.requestSpecification = jmapRequestSpecBuilder
             .setPort(jmapPort.getValue())
             .build();
 
         webAdminApi = WebAdminUtils.spec(jmapServer.getProbe(WebAdminGuiceProbe.class).getWebAdminPort());
     }
 
+    @Test
+    void shouldMigrateMailboxes() {
+        webAdminApi.put("/users/" + ALICE.asString() + "/mailboxes/test").prettyPeek();
+
+        String taskId = webAdminApi
+            .queryParam("action", "rename")
+            .post("/users/" + ALICE.asString() + "/rename/" + BOB.asString()).prettyPeek()
+            .jsonPath()
+            .get("taskId");
+
+        webAdminApi.get("/tasks/" + taskId + "/await");
+
+        webAdminApi.get("/users/" + ALICE.asString() + "/mailboxes").prettyPeek()
+            .then()
+            .body(".", hasSize(0));
+
+        webAdminApi.get("/users/" + BOB.asString() + "/mailboxes").prettyPeek()

Review Comment:
   debug spotted



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org