You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2023/05/26 10:30:50 UTC

[james-project] 05/07: JAMES-3909 VacationDeleteUserTaskStep

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 9e20aeef2691031a883e91dd8fd7a5f399704c8f
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri May 19 16:42:50 2023 +0700

    JAMES-3909 VacationDeleteUserTaskStep
---
 .../vacation/api/VacationDeleteUserTaskStep.java   | 59 ++++++++++++++++++
 .../memory/VacationDeleteUserTaskStepTest.java     | 70 ++++++++++++++++++++++
 2 files changed, 129 insertions(+)

diff --git a/server/data/data-api/src/main/java/org/apache/james/vacation/api/VacationDeleteUserTaskStep.java b/server/data/data-api/src/main/java/org/apache/james/vacation/api/VacationDeleteUserTaskStep.java
new file mode 100644
index 0000000000..70725fbd8c
--- /dev/null
+++ b/server/data/data-api/src/main/java/org/apache/james/vacation/api/VacationDeleteUserTaskStep.java
@@ -0,0 +1,59 @@
+/******************************************************************
+ * 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.vacation.api;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.Username;
+import org.apache.james.user.api.DeleteUserDataTaskStep;
+import org.apache.james.util.ValuePatch;
+import org.reactivestreams.Publisher;
+
+public class VacationDeleteUserTaskStep implements DeleteUserDataTaskStep {
+    private final VacationRepository vacationRepository;
+
+    @Inject
+    public VacationDeleteUserTaskStep(VacationRepository vacationRepository) {
+        this.vacationRepository = vacationRepository;
+    }
+
+    @Override
+    public StepName name() {
+        return new StepName("VacationDeleteUserTaskStep");
+    }
+
+    @Override
+    public int priority() {
+        return 4;
+    }
+
+    @Override
+    public Publisher<Void> deleteUserData(Username username) {
+        return vacationRepository.modifyVacation(AccountId.fromUsername(username),
+            VacationPatch.builder()
+                .isEnabled(false)
+                .subject(ValuePatch.remove())
+                .fromDate(ValuePatch.remove())
+                .htmlBody(ValuePatch.remove())
+                .textBody(ValuePatch.remove())
+                .toDate(ValuePatch.remove())
+                .build());
+    }
+}
diff --git a/server/data/data-memory/src/test/java/org/apache/james/vacation/memory/VacationDeleteUserTaskStepTest.java b/server/data/data-memory/src/test/java/org/apache/james/vacation/memory/VacationDeleteUserTaskStepTest.java
new file mode 100644
index 0000000000..57bf370717
--- /dev/null
+++ b/server/data/data-memory/src/test/java/org/apache/james/vacation/memory/VacationDeleteUserTaskStepTest.java
@@ -0,0 +1,70 @@
+/******************************************************************
+ * 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.vacation.memory;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import org.apache.james.core.Username;
+import org.apache.james.vacation.api.AccountId;
+import org.apache.james.vacation.api.Vacation;
+import org.apache.james.vacation.api.VacationDeleteUserTaskStep;
+import org.apache.james.vacation.api.VacationPatch;
+import org.apache.james.vacation.api.VacationRepository;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import reactor.core.publisher.Mono;
+
+class VacationDeleteUserTaskStepTest {
+    public static final Username BOB = Username.of("bob");
+    private VacationDeleteUserTaskStep testee;
+    private VacationRepository vacationRepository;
+
+    @BeforeEach
+    void beforeEach() {
+        vacationRepository = new MemoryVacationRepository();
+        testee = new VacationDeleteUserTaskStep(vacationRepository);
+    }
+
+    @Test
+    void shouldOverridePersonalData() {
+        VacationPatch vacationPatch = VacationPatch.builder()
+            .isEnabled(true)
+            .build();
+        vacationRepository.modifyVacation(AccountId.fromUsername(BOB), vacationPatch).block();
+
+        Mono.from(testee.deleteUserData(BOB)).block();
+
+        assertThat(Mono.from(vacationRepository.retrieveVacation(AccountId.fromUsername(BOB))).block())
+            .isEqualTo(Vacation.builder()
+                .enabled(false)
+                .build());
+    }
+
+    @Test
+    void shouldNotCreateVacationWhenNone() {
+        Mono.from(testee.deleteUserData(BOB)).block();
+
+
+        assertThat(Mono.from(vacationRepository.retrieveVacation(AccountId.fromUsername(BOB))).block())
+            .isEqualTo(Vacation.builder()
+                .enabled(false)
+                .build());
+    }
+}


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