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:51 UTC
[james-project] 06/07: JAMES-3909 FiltersDeleteUserDataTaskStep
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 728b0ec6f0a94b0fdcdd71cd980306e5f04854e8
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri May 19 16:55:06 2023 +0700
JAMES-3909 FiltersDeleteUserDataTaskStep
---
.../filtering/FiltersDeleteUserDataTaskStep.java | 52 +++++++++++++++++++
.../impl/FiltersDeleteUserDataTaskStepTest.java | 58 ++++++++++++++++++++++
2 files changed, 110 insertions(+)
diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/FiltersDeleteUserDataTaskStep.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/FiltersDeleteUserDataTaskStep.java
new file mode 100644
index 0000000000..28f0280e38
--- /dev/null
+++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/FiltersDeleteUserDataTaskStep.java
@@ -0,0 +1,52 @@
+/******************************************************************
+ * 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.jmap.api.filtering;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.Username;
+import org.apache.james.user.api.DeleteUserDataTaskStep;
+import org.reactivestreams.Publisher;
+
+import reactor.core.publisher.Mono;
+
+public class FiltersDeleteUserDataTaskStep implements DeleteUserDataTaskStep {
+ private final FilteringManagement filteringManagement;
+
+ @Inject
+ public FiltersDeleteUserDataTaskStep(FilteringManagement filteringManagement) {
+ this.filteringManagement = filteringManagement;
+ }
+
+ @Override
+ public StepName name() {
+ return new StepName("FiltersDeleteUserDataTaskStep ");
+ }
+
+ @Override
+ public int priority() {
+ return 5;
+ }
+
+ @Override
+ public Publisher<Void> deleteUserData(Username username) {
+ return Mono.from(filteringManagement.clearRulesForUser(username)).then();
+ }
+}
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/impl/FiltersDeleteUserDataTaskStepTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/impl/FiltersDeleteUserDataTaskStepTest.java
new file mode 100644
index 0000000000..06a9fc080b
--- /dev/null
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/impl/FiltersDeleteUserDataTaskStepTest.java
@@ -0,0 +1,58 @@
+/******************************************************************
+ * 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.jmap.api.filtering.impl;
+
+import static org.apache.james.jmap.api.filtering.RuleFixture.RULE_1;
+import static org.apache.james.jmap.api.filtering.RuleFixture.RULE_2;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import org.apache.james.core.Username;
+import org.apache.james.eventsourcing.eventstore.memory.InMemoryEventStore;
+import org.apache.james.jmap.api.filtering.FilteringManagement;
+import org.apache.james.jmap.api.filtering.FiltersDeleteUserDataTaskStep;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import reactor.core.publisher.Mono;
+
+class FiltersDeleteUserDataTaskStepTest {
+ private static final Username BOB = Username.of("bob");
+
+ private FilteringManagement filteringManagement;
+ private FiltersDeleteUserDataTaskStep testee;
+
+ @BeforeEach
+ void beforeEach() {
+ filteringManagement = new EventSourcingFilteringManagement(new InMemoryEventStore());
+ testee = new FiltersDeleteUserDataTaskStep(filteringManagement);
+ }
+
+ @Test
+ void shouldClearRules() {
+ Mono.from(filteringManagement.defineRulesForUser(BOB, Optional.empty(), RULE_1, RULE_2)).block();
+
+ Mono.from(testee.deleteUserData(BOB)).block();
+
+ assertThat(Mono.from(filteringManagement.listRulesForUser(BOB)).block().getRules())
+ .isEmpty();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org