[james-project] branch master updated: JAMES-3925 Define an API to store current values of JMAP uploads (#1699)

2023-08-25 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
 new cd94e5434e JAMES-3925 Define an API to store current values of JMAP 
uploads (#1699)
cd94e5434e is described below

commit cd94e5434e528fc076ebc3635ee4ab06cb2c0528
Author: hungphan227 <45198168+hungphan...@users.noreply.github.com>
AuthorDate: Sat Aug 26 12:53:29 2023 +0700

JAMES-3925 Define an API to store current values of JMAP uploads (#1699)
---
 .../james/modules/data/CassandraJmapModule.java|  3 +
 .../james/modules/mailbox/MemoryQuotaModule.java   |  3 +
 .../upload/CassandraUploadUsageRepository.java | 67 +++
 .../upload/CassandraUploadUsageRepositoryTest.java | 48 ++
 .../jmap/api/upload/UploadUsageRepository.java | 34 ++
 .../upload/InMemoryUploadUsageRepository.java  | 75 ++
 .../api/upload/UploadUsageRepositoryContract.scala | 50 +++
 .../upload/InMemoryUploadUsageRepositoryTest.java  | 41 
 8 files changed, 321 insertions(+)

diff --git 
a/server/container/guice/cassandra/src/main/java/org/apache/james/modules/data/CassandraJmapModule.java
 
b/server/container/guice/cassandra/src/main/java/org/apache/james/modules/data/CassandraJmapModule.java
index e1b9584628..a6c0884c27 100644
--- 
a/server/container/guice/cassandra/src/main/java/org/apache/james/modules/data/CassandraJmapModule.java
+++ 
b/server/container/guice/cassandra/src/main/java/org/apache/james/modules/data/CassandraJmapModule.java
@@ -41,6 +41,7 @@ import 
org.apache.james.jmap.api.projections.MessageFastViewProjectionHealthChec
 import org.apache.james.jmap.api.pushsubscription.PushDeleteUserDataTaskStep;
 import org.apache.james.jmap.api.pushsubscription.PushSubscriptionRepository;
 import org.apache.james.jmap.api.upload.UploadRepository;
+import org.apache.james.jmap.api.upload.UploadUsageRepository;
 import org.apache.james.jmap.cassandra.access.CassandraAccessModule;
 import org.apache.james.jmap.cassandra.access.CassandraAccessTokenRepository;
 import org.apache.james.jmap.cassandra.change.CassandraEmailChangeModule;
@@ -57,6 +58,7 @@ import 
org.apache.james.jmap.cassandra.projections.CassandraMessageFastViewProje
 import 
org.apache.james.jmap.cassandra.pushsubscription.CassandraPushSubscriptionModule;
 import 
org.apache.james.jmap.cassandra.pushsubscription.CassandraPushSubscriptionRepository;
 import org.apache.james.jmap.cassandra.upload.CassandraUploadRepository;
+import org.apache.james.jmap.cassandra.upload.CassandraUploadUsageRepository;
 import org.apache.james.jmap.cassandra.upload.UploadConfiguration;
 import org.apache.james.jmap.cassandra.upload.UploadDAO;
 import org.apache.james.jmap.cassandra.upload.UploadModule;
@@ -80,6 +82,7 @@ public class CassandraJmapModule extends AbstractModule {
 bind(CassandraUploadRepository.class).in(Scopes.SINGLETON);
 bind(UploadDAO.class).in(Scopes.SINGLETON);
 bind(UploadRepository.class).to(CassandraUploadRepository.class);
+
bind(UploadUsageRepository.class).to(CassandraUploadUsageRepository.class);
 
bind(UploadConfiguration.class).toInstance(UploadConfiguration.SINGLETON);
 
 bind(CassandraCustomIdentityDAO.class).in(Scopes.SINGLETON);
diff --git 
a/server/container/guice/memory/src/main/java/org/apache/james/modules/mailbox/MemoryQuotaModule.java
 
b/server/container/guice/memory/src/main/java/org/apache/james/modules/mailbox/MemoryQuotaModule.java
index 1fd76c36f7..dc389d74d6 100644
--- 
a/server/container/guice/memory/src/main/java/org/apache/james/modules/mailbox/MemoryQuotaModule.java
+++ 
b/server/container/guice/memory/src/main/java/org/apache/james/modules/mailbox/MemoryQuotaModule.java
@@ -20,6 +20,8 @@
 package org.apache.james.modules.mailbox;
 
 import org.apache.james.events.EventListener;
+import org.apache.james.jmap.api.upload.UploadUsageRepository;
+import org.apache.james.jmap.memory.upload.InMemoryUploadUsageRepository;
 import org.apache.james.mailbox.inmemory.quota.InMemoryCurrentQuotaManager;
 import org.apache.james.mailbox.inmemory.quota.InMemoryPerUserMaxQuotaManager;
 import org.apache.james.mailbox.quota.CurrentQuotaManager;
@@ -52,6 +54,7 @@ public class MemoryQuotaModule extends AbstractModule {
 bind(MaxQuotaManager.class).to(InMemoryPerUserMaxQuotaManager.class);
 bind(QuotaManager.class).to(StoreQuotaManager.class);
 bind(CurrentQuotaManager.class).to(InMemoryCurrentQuotaManager.class);
+
bind(UploadUsageRepository.class).to(InMemoryUploadUsageRepository.class);
 
 bind(ListeningCurrentQuotaUpdater.class).in(Scopes.SINGLETON);
 bind(QuotaUpdater.class).to(ListeningCurrentQuotaUpdater.class);
diff --git 

[GitHub] [james-project] chibenwa merged pull request #1699: JAMES-3925 Define an API to store current values of JMAP uploads

2023-08-25 Thread via GitHub


chibenwa merged PR #1699:
URL: https://github.com/apache/james-project/pull/1699


-- 
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-unsubscr...@james.apache.org

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


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



[james-project] branch master updated (4d7aae72b4 -> 7280c36399)

2023-08-25 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

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


from 4d7aae72b4 JAMES-3925 Rework JMAP upload APIs
 new 9fcb888081 JAMES-3936 Forward + Alias + Group + Address Mapping Routes 
should not decode URL path two times
 new 7df0dd0168 JAMES-3936 MailRepositoriesRoutes should not decode request 
param 2 times
 new cbc2313e26 JAMES-3936 DomainsRoutes should not decode request param 2 
times
 new 0f9adc382f JAMES-3936 RegexMappingRoutes should not decode request 
param 2 times
 new f5ac5279c4 JAMES-3936 UserQuotaRoutes should not decode URL path two 
times
 new ed3fb56ce2 JAMES-3936 Better notating ticket number in tests
 new 7280c36399 JAMES-3936 Fix some failing tests

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../mailets/ToRepositoryIntegrationTest.java   |  1 +
 ...rTaskSerializationIntegrationImmutableTest.java |  1 +
 ...dminServerTaskSerializationIntegrationTest.java |  1 +
 .../org/apache/james/webadmin/WebAdminUtils.java   |  3 ++-
 .../james/webadmin/routes/DomainsRoutes.java   | 21 ++--
 .../james/webadmin/routes/MailAddressParser.java   | 15 +--
 .../james/webadmin/routes/RegexMappingRoutes.java  |  7 ++
 .../webadmin/routes/AddressMappingRoutesTest.java  | 18 +++---
 .../james/webadmin/routes/AliasRoutesTest.java |  1 +
 .../james/webadmin/routes/DomainsRoutesTest.java   | 21 ++--
 .../james/webadmin/routes/ForwardRoutesTest.java   | 14 +++
 .../james/webadmin/routes/GroupsRoutesTest.java|  1 +
 .../webadmin/routes/RegexMappingRoutesTest.java| 26 ---
 .../webadmin/routes/SieveScriptRoutesTest.java |  5 ++--
 .../james/webadmin/routes/UserRoutesTest.java  | 29 +++---
 .../james/webadmin/routes/UserQuotaRoutes.java | 10 ++--
 .../webadmin/routes/UserMailboxesRoutesTest.java   | 16 ++--
 .../james/webadmin/routes/UserQuotaRoutesTest.java |  3 ++-
 .../webadmin/routes/MailRepositoriesRoutes.java| 27 ++--
 19 files changed, 109 insertions(+), 111 deletions(-)


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



[james-project] 04/07: JAMES-3936 RegexMappingRoutes should not decode request param 2 times

2023-08-25 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

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

commit 0f9adc382f8f21a4fb488d2bcc8b801028efa2cd
Author: Quan Tran 
AuthorDate: Wed Aug 23 17:03:53 2023 +0700

JAMES-3936 RegexMappingRoutes should not decode request param 2 times

Once has been handled by Spark.
---
 .../james/webadmin/routes/RegexMappingRoutes.java  |  7 ++
 .../webadmin/routes/RegexMappingRoutesTest.java| 26 ++
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git 
a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/RegexMappingRoutes.java
 
b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/RegexMappingRoutes.java
index 1df59788ad..aac6f6d308 100644
--- 
a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/RegexMappingRoutes.java
+++ 
b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/RegexMappingRoutes.java
@@ -22,9 +22,6 @@ package org.apache.james.webadmin.routes;
 import static org.apache.james.webadmin.Constants.SEPARATOR;
 import static spark.Spark.halt;
 
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
-
 import javax.inject.Inject;
 
 import org.apache.james.core.Username;
@@ -75,7 +72,7 @@ public class RegexMappingRoutes implements Routes {
 private HaltException addRegexMapping(Request request, Response response) 
throws Exception {
 try {
 MappingSource mappingSource = extractMappingSource(request);
-String regex = URLDecoder.decode(request.params(REGEX_PARAM), 
StandardCharsets.UTF_8.toString());
+String regex = request.params(REGEX_PARAM);
 recipientRewriteTable.addRegexMapping(mappingSource, regex);
 } catch (InvalidRegexException e) {
 throw ErrorResponder.builder()
@@ -90,7 +87,7 @@ public class RegexMappingRoutes implements Routes {
 private HaltException removeRegexMapping(Request request, Response 
response) throws Exception {
 try {
 MappingSource mappingSource = 
MappingSource.parse(request.params(MAPPING_SOURCE_PARAM));
-String regex = URLDecoder.decode(request.params(REGEX_PARAM), 
StandardCharsets.UTF_8.toString());
+String regex = request.params(REGEX_PARAM);
 recipientRewriteTable.removeRegexMapping(mappingSource, regex);
 } catch (RecipientRewriteTableException e) {
 throw ErrorResponder.builder()
diff --git 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/RegexMappingRoutesTest.java
 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/RegexMappingRoutesTest.java
index b1abf71dc4..dd4c8d8293 100644
--- 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/RegexMappingRoutesTest.java
+++ 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/RegexMappingRoutesTest.java
@@ -24,10 +24,11 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.hamcrest.core.Is.is;
 import static org.mockito.Mockito.mock;
 
+import java.net.URLEncoder;
+
 import org.apache.james.core.Domain;
 import org.apache.james.core.Username;
 import org.apache.james.dnsservice.api.DNSService;
-import org.apache.james.domainlist.api.DomainList;
 import org.apache.james.domainlist.lib.DomainListConfiguration;
 import org.apache.james.domainlist.memory.MemoryDomainList;
 import org.apache.james.rrt.lib.Mapping;
@@ -41,7 +42,6 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import io.restassured.RestAssured;
-import io.restassured.filter.log.LogDetail;
 import io.restassured.http.ContentType;
 
 class RegexMappingRoutesTest {
@@ -63,6 +63,7 @@ class RegexMappingRoutesTest {
 
 RestAssured.requestSpecification = 
WebAdminUtils.buildRequestSpecification(webAdminServer)
 .setBasePath(RegexMappingRoutes.BASE_PATH)
+.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client
 .build();
 }
 
@@ -136,7 +137,7 @@ class RegexMappingRoutesTest {
 @Test
 void addRegexMappingShouldReturnBadRequestWhenRegexIsInvalid() {
 with()
-.post("ja...@domain.tld/targets/O.*[]")
+.post("ja...@domain.tld/targets/"+ URLEncoder.encode("O.*[]"))
 .then()
 .statusCode(HttpStatus.BAD_REQUEST_400)
 .contentType(ContentType.JSON)
@@ -148,7 +149,7 @@ class RegexMappingRoutesTest {
 @Test
 void addRegexMappingShouldReturnNoContentWhenRegexContainsQuestionMark() {
 with()
-.post("ja...@domain.tld/targets/^[aei%3Fou].*ja...@domain.tld")
+.post("ja...@domain.tld/targets/" + 

[james-project] 07/07: JAMES-3936 Fix some failing tests

2023-08-25 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

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

commit 7280c3639900d0e0ce5eb395ee7c1e7f29fa97d0
Author: Quan Tran 
AuthorDate: Thu Aug 24 11:25:38 2023 +0700

JAMES-3936 Fix some failing tests

Rest assured client no longer encodes now, we need to encode ourselves some 
special characters.
---
 .../mailets/ToRepositoryIntegrationTest.java   |  1 +
 ...rTaskSerializationIntegrationImmutableTest.java |  1 +
 ...dminServerTaskSerializationIntegrationTest.java |  1 +
 .../org/apache/james/webadmin/WebAdminUtils.java   |  3 ++-
 .../webadmin/routes/SieveScriptRoutesTest.java |  5 ++--
 .../james/webadmin/routes/UserRoutesTest.java  | 29 +++---
 .../webadmin/routes/UserMailboxesRoutesTest.java   | 16 ++--
 7 files changed, 32 insertions(+), 24 deletions(-)

diff --git 
a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryIntegrationTest.java
 
b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryIntegrationTest.java
index a7653f1286..2411ef085b 100644
--- 
a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryIntegrationTest.java
+++ 
b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryIntegrationTest.java
@@ -88,6 +88,7 @@ class ToRepositoryIntegrationTest {
 webAdminAPI = WebAdminUtils.buildRequestSpecification(
 jamesServer.getProbe(WebAdminGuiceProbe.class)
 .getWebAdminPort())
+.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client. rf: 
https://issues.apache.org/jira/projects/JAMES/issues/JAMES-3936
 .build();
 }
 
diff --git 
a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerTaskSerializationIntegrationImmutableTest.java
 
b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerTaskSerializationIntegrationImmutableTest.java
index dbcdaa1f64..ad1e468e52 100644
--- 
a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerTaskSerializationIntegrationImmutableTest.java
+++ 
b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerTaskSerializationIntegrationImmutableTest.java
@@ -95,6 +95,7 @@ class 
RabbitMQWebAdminServerTaskSerializationIntegrationImmutableTest {
 WebAdminGuiceProbe webAdminGuiceProbe = 
guiceJamesServer.getProbe(WebAdminGuiceProbe.class);
 
 RestAssured.requestSpecification = 
WebAdminUtils.buildRequestSpecification(webAdminGuiceProbe.getWebAdminPort())
+.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client. rf: 
https://issues.apache.org/jira/projects/JAMES/issues/JAMES-3936
 .build();
 RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
 }
diff --git 
a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerTaskSerializationIntegrationTest.java
 
b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerTaskSerializationIntegrationTest.java
index e54a15d3da..5bc4b26532 100644
--- 
a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerTaskSerializationIntegrationTest.java
+++ 
b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerTaskSerializationIntegrationTest.java
@@ -130,6 +130,7 @@ class 
RabbitMQWebAdminServerTaskSerializationIntegrationTest {
 mailboxProbe = guiceJamesServer.getProbe(MailboxProbeImpl.class);
 
 RestAssured.requestSpecification = 
WebAdminUtils.buildRequestSpecification(webAdminGuiceProbe.getWebAdminPort())
+.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client. rf: 
https://issues.apache.org/jira/projects/JAMES/issues/JAMES-3936
 .build();
 RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
 }
diff --git 
a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/WebAdminUtils.java
 

[james-project] 05/07: JAMES-3936 UserQuotaRoutes should not decode URL path two times

2023-08-25 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

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

commit f5ac5279c4fa91a229ad2374e540abc6b082f26e
Author: Quan Tran 
AuthorDate: Wed Aug 23 17:17:47 2023 +0700

JAMES-3936 UserQuotaRoutes should not decode URL path two times
---
 .../java/org/apache/james/webadmin/routes/UserQuotaRoutes.java | 10 ++
 .../org/apache/james/webadmin/routes/UserQuotaRoutesTest.java  |  3 ++-
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git 
a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserQuotaRoutes.java
 
b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserQuotaRoutes.java
index be0511e1f3..b3c6a9578b 100644
--- 
a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserQuotaRoutes.java
+++ 
b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserQuotaRoutes.java
@@ -21,9 +21,6 @@ package org.apache.james.webadmin.routes;
 
 import static org.apache.james.webadmin.routes.MailboxesRoutes.TASK_PARAMETER;
 
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
 import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
@@ -280,11 +277,8 @@ public class UserQuotaRoutes implements Routes {
 }, jsonTransformer);
 }
 
-private Username checkUserExist(Request request) throws 
UsersRepositoryException, UnsupportedEncodingException {
-String user = URLDecoder.decode(request.params(USER),
-StandardCharsets.UTF_8.displayName());
-
-Username username = Username.of(user);
+private Username checkUserExist(Request request) throws 
UsersRepositoryException {
+Username username = Username.of(request.params(USER));
 
 if (!usersRepository.contains(username)) {
 throw ErrorResponder.builder()
diff --git 
a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java
 
b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java
index 85f31398a5..f7311b3e2c 100644
--- 
a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java
+++ 
b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java
@@ -102,7 +102,8 @@ class UserQuotaRoutesTest {
 usersRepository.addUser(JACK, PASSWORD);
 usersRepository.addUser(GUY_WITH_STRANGE_DOMAIN, PASSWORD);
 
-RestAssured.requestSpecification = 
testSystem.getRequestSpecification();
+RestAssured.requestSpecification = testSystem.getRequestSpecification()
+.urlEncodingEnabled(false); // no further automatically encoding 
by Rest Assured client. rf: 
https://issues.apache.org/jira/projects/JAMES/issues/JAMES-3936
 RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
 }
 


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



[james-project] 01/07: JAMES-3936 Forward + Alias + Group + Address Mapping Routes should not decode URL path two times

2023-08-25 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

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

commit 9fcb8880812098f09e8e37131b06fb892a213000
Author: Quan Tran 
AuthorDate: Wed Aug 23 15:33:05 2023 +0700

JAMES-3936 Forward + Alias + Group + Address Mapping Routes should not 
decode URL path two times

We already have Spark handle URL decoding once, no need one more time 
within MailAddressParser.
---
 .../james/webadmin/routes/MailAddressParser.java   | 15 +--
 .../webadmin/routes/AddressMappingRoutesTest.java  | 18 +++---
 .../apache/james/webadmin/routes/AliasRoutesTest.java  |  1 +
 .../james/webadmin/routes/ForwardRoutesTest.java   | 14 ++
 .../apache/james/webadmin/routes/GroupsRoutesTest.java |  1 +
 5 files changed, 32 insertions(+), 17 deletions(-)

diff --git 
a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/MailAddressParser.java
 
b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/MailAddressParser.java
index 0f7b03b41d..666cd1ab9a 100644
--- 
a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/MailAddressParser.java
+++ 
b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/MailAddressParser.java
@@ -19,10 +19,6 @@
 
 package org.apache.james.webadmin.routes;
 
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
-
 import javax.mail.internet.AddressException;
 
 import org.apache.james.core.MailAddress;
@@ -37,8 +33,7 @@ class MailAddressParser {
 
 static MailAddress parseMailAddress(String address, String addressType) {
 try {
-String decodedAddress = URLDecoder.decode(address, 
StandardCharsets.UTF_8.displayName());
-return new MailAddress(decodedAddress);
+return new MailAddress(address);
 } catch (AddressException e) {
 LOGGER.error("The {} {} is not an email address", addressType, 
address);
 throw ErrorResponder.builder()
@@ -47,14 +42,6 @@ class MailAddressParser {
 .message("The %s is not an email address", addressType)
 .cause(e)
 .haltError();
-} catch (UnsupportedEncodingException e) {
-LOGGER.error("UTF-8 should be a valid encoding");
-throw ErrorResponder.builder()
-.statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
-.type(ErrorResponder.ErrorType.SERVER_ERROR)
-.message("Internal server error - Something went bad on the 
server side.")
-.cause(e)
-.haltError();
 }
 }
 
diff --git 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AddressMappingRoutesTest.java
 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AddressMappingRoutesTest.java
index aac29ea4b3..f57d76a75c 100644
--- 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AddressMappingRoutesTest.java
+++ 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AddressMappingRoutesTest.java
@@ -46,9 +46,11 @@ import io.restassured.RestAssured;
 import io.restassured.http.ContentType;
 
 class AddressMappingRoutesTest {
-private static String MAPPING_SOURCE = "sou...@domain.tld";
-private static String ALICE_ADDRESS = "al...@domain.tld";
-private static String BOB_ADDRESS = "b...@domain.tld";
+private static final String MAPPING_SOURCE = "sou...@domain.tld";
+private static final String ALICE_ADDRESS = "al...@domain.tld";
+private static final String ALICE_WITH_SLASH = "alice/@domain.tld";
+private static final String ALICE_WITH_ENCODED_SLASH = 
"alice...@domain.tld";
+private static final String BOB_ADDRESS = "b...@domain.tld";
 
 private WebAdminServer webAdminServer;
 private MemoryRecipientRewriteTable recipientRewriteTable;
@@ -70,6 +72,7 @@ class AddressMappingRoutesTest {
 
 RestAssured.requestSpecification = 
WebAdminUtils.buildRequestSpecification(webAdminServer)
 .setBasePath(AddressMappingRoutes.BASE_PATH)
+.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client
 .build();
 }
 
@@ -87,6 +90,15 @@ class AddressMappingRoutesTest {
 .containsAnyOf(Mapping.of(ALICE_ADDRESS));
 }
 
+@Test
+void addAddressMappingShouldSupportOneTimeEncodedAddress() {
+when()
+.post(MAPPING_SOURCE + "/targets/" + ALICE_WITH_ENCODED_SLASH);
+
+
assertThat(recipientRewriteTable.getStoredMappings(MappingSource.parse(MAPPING_SOURCE)))
+.containsAnyOf(Mapping.of(ALICE_WITH_SLASH));
+}
+
 @Test
 

[james-project] 06/07: JAMES-3936 Better notating ticket number in tests

2023-08-25 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

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

commit ed3fb56ce2e9bc32c4424663d50c2e38e78464e1
Author: Quan Tran 
AuthorDate: Wed Aug 23 17:38:25 2023 +0700

JAMES-3936 Better notating ticket number in tests
---
 .../java/org/apache/james/webadmin/routes/AddressMappingRoutesTest.java | 2 +-
 .../src/test/java/org/apache/james/webadmin/routes/AliasRoutesTest.java | 2 +-
 .../test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java   | 2 +-
 .../test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java   | 2 +-
 .../test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java| 2 +-
 .../java/org/apache/james/webadmin/routes/RegexMappingRoutesTest.java   | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AddressMappingRoutesTest.java
 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AddressMappingRoutesTest.java
index f57d76a75c..215081d27d 100644
--- 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AddressMappingRoutesTest.java
+++ 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AddressMappingRoutesTest.java
@@ -72,7 +72,7 @@ class AddressMappingRoutesTest {
 
 RestAssured.requestSpecification = 
WebAdminUtils.buildRequestSpecification(webAdminServer)
 .setBasePath(AddressMappingRoutes.BASE_PATH)
-.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client
+.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client. rf: 
https://issues.apache.org/jira/projects/JAMES/issues/JAMES-3936
 .build();
 }
 
diff --git 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AliasRoutesTest.java
 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AliasRoutesTest.java
index a5b35824ca..9d0d9e32ae 100644
--- 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AliasRoutesTest.java
+++ 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AliasRoutesTest.java
@@ -90,7 +90,7 @@ class AliasRoutesTest {
 
 RestAssured.requestSpecification = 
WebAdminUtils.buildRequestSpecification(webAdminServer)
 .setBasePath("address/aliases")
-.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client
+.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client. rf: 
https://issues.apache.org/jira/projects/JAMES/issues/JAMES-3936
 .build();
 }
 
diff --git 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
index 7a61cc1a48..9804973478 100644
--- 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
+++ 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
@@ -117,7 +117,7 @@ class DomainsRoutesTest {
 
 RestAssured.requestSpecification = 
WebAdminUtils.buildRequestSpecification(webAdminServer)
 .setBasePath(DomainsRoutes.DOMAINS)
-.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client
+.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client. rf: 
https://issues.apache.org/jira/projects/JAMES/issues/JAMES-3936
 .build();
 }
 
diff --git 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
index 663964bda3..317997dfb0 100644
--- 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
+++ 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
@@ -88,7 +88,7 @@ class ForwardRoutesTest {
 
 RestAssured.requestSpecification = 
WebAdminUtils.buildRequestSpecification(webAdminServer)
 .setBasePath("address/forwards")
-.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client
+.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client. rf: 
https://issues.apache.org/jira/projects/JAMES/issues/JAMES-3936
 .build();
 }
 
diff --git 

[james-project] 02/07: JAMES-3936 MailRepositoriesRoutes should not decode request param 2 times

2023-08-25 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

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

commit 7df0dd016876c4807705076c90494b8473f09b6d
Author: Quan Tran 
AuthorDate: Wed Aug 23 16:11:30 2023 +0700

JAMES-3936 MailRepositoriesRoutes should not decode request param 2 times

Besides, MailRepositoryPath.fromEncoded is being used by some Task DTOs - 
good to keep there.
---
 .../webadmin/routes/MailRepositoriesRoutes.java| 27 +++---
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git 
a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
 
b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
index 2b1c6b2f8f..407408aaf8 100644
--- 
a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
+++ 
b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
@@ -21,7 +21,6 @@ package org.apache.james.webadmin.routes;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
 import java.time.Clock;
 import java.util.Optional;
 import java.util.Set;
@@ -119,7 +118,7 @@ public class MailRepositoriesRoutes implements Routes {
 
 public void definePutMailRepository() {
 service.put(MAIL_REPOSITORIES + "/:encodedPath", (request, response) 
-> {
-MailRepositoryPath path = decodedRepositoryPath(request);
+MailRepositoryPath path = getRepositoryPath(request);
 String protocol = request.queryParams("protocol");
 try {
 repositoryStoreService.createMailRepository(path, protocol);
@@ -146,7 +145,7 @@ public class MailRepositoriesRoutes implements Routes {
 service.get(MAIL_REPOSITORIES + "/:encodedPath/mails", (request, 
response) -> {
 Offset offset = ParametersExtractor.extractOffset(request);
 Limit limit = ParametersExtractor.extractLimit(request);
-MailRepositoryPath path = decodedRepositoryPath(request);
+MailRepositoryPath path = getRepositoryPath(request);
 try {
 return repositoryStoreService.listMails(path, offset, limit)
 .orElseThrow(() -> 
repositoryNotFound(request.params("encodedPath"), path));
@@ -171,13 +170,13 @@ public class MailRepositoriesRoutes implements Routes {
 public void defineGetMail() {
 service.get(MAIL_REPOSITORIES + "/:encodedPath/mails/:mailKey", 
Constants.JSON_CONTENT_TYPE,
 (request, response) ->
-getMailAsJson(decodedRepositoryPath(request), new 
MailKey(request.params("mailKey")), request),
+getMailAsJson(getRepositoryPath(request), new 
MailKey(request.params("mailKey")), request),
 jsonTransformer);
 
 service.get(MAIL_REPOSITORIES + "/:encodedPath/mails/:mailKey", 
Constants.RFC822_CONTENT_TYPE,
 (request, response) -> writeMimeMessage(
 getMailAsMimeMessage(
-decodedRepositoryPath(request),
+getRepositoryPath(request),
 new MailKey(request.params("mailKey"))),
 response.raw()));
 }
@@ -262,7 +261,7 @@ public class MailRepositoriesRoutes implements Routes {
 
 public void defineGetMailRepository() {
 service.get(MAIL_REPOSITORIES + "/:encodedPath", (request, response) 
-> {
-MailRepositoryPath path = decodedRepositoryPath(request);
+MailRepositoryPath path = getRepositoryPath(request);
 try {
 long size = repositoryStoreService.size(path)
 .orElseThrow(() -> 
repositoryNotFound(request.params("encodedPath"), path));
@@ -280,7 +279,7 @@ public class MailRepositoriesRoutes implements Routes {
 
 public void defineDeleteMail() {
 service.delete(MAIL_REPOSITORIES + "/:encodedPath/mails/:mailKey", 
(request, response) -> {
-MailRepositoryPath path = decodedRepositoryPath(request);
+MailRepositoryPath path = getRepositoryPath(request);
 MailKey mailKey = new MailKey(request.params("mailKey"));
 try {
 repositoryStoreService.deleteMail(path, mailKey);
@@ -298,7 +297,7 @@ public class MailRepositoriesRoutes implements Routes {
 
 public void defineDeleteAll() {
 TaskFromRequest taskFromRequest = request -> {
-MailRepositoryPath path = decodedRepositoryPath(request);
+MailRepositoryPath path = getRepositoryPath(request);
 try {
 return 
repositoryStoreService.createClearMailRepositoryTask(path);
 } catch 

[james-project] 03/07: JAMES-3936 DomainsRoutes should not decode request param 2 times

2023-08-25 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

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

commit cbc2313e26aa99cf73f2c6514f982ad4dc8df13a
Author: Quan Tran 
AuthorDate: Wed Aug 23 16:40:22 2023 +0700

JAMES-3936 DomainsRoutes should not decode request param 2 times
---
 .../apache/james/webadmin/routes/DomainsRoutes.java | 21 ++---
 .../james/webadmin/routes/DomainsRoutesTest.java| 21 ++---
 2 files changed, 4 insertions(+), 38 deletions(-)

diff --git 
a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java
 
b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java
index 34ef2f9ab9..cba41954db 100644
--- 
a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java
+++ 
b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainsRoutes.java
@@ -21,9 +21,6 @@ package org.apache.james.webadmin.routes;
 
 import static org.apache.james.webadmin.Constants.SEPARATOR;
 
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
 import java.util.stream.Collectors;
 
 import javax.inject.Inject;
@@ -203,27 +200,13 @@ public class DomainsRoutes implements Routes {
 }
 
 private Domain checkValidDomain(String domainName) {
-String urlDecodedDomainName = urlDecodeDomain(domainName);
 try {
-return Domain.of(urlDecodedDomainName);
+return Domain.of(domainName);
 } catch (IllegalArgumentException e) {
 throw ErrorResponder.builder()
 .statusCode(HttpStatus.BAD_REQUEST_400)
 .type(ErrorType.INVALID_ARGUMENT)
-.message("Invalid request for domain creation %s", 
urlDecodedDomainName)
-.cause(e)
-.haltError();
-}
-}
-
-private String urlDecodeDomain(String domainName) {
-try {
-return URLDecoder.decode(domainName, 
StandardCharsets.UTF_8.toString());
-} catch (IllegalArgumentException | UnsupportedEncodingException e) {
-throw ErrorResponder.builder()
-.statusCode(HttpStatus.BAD_REQUEST_400)
-.type(ErrorType.INVALID_ARGUMENT)
-.message("Invalid request for domain creation %s unable to url 
decode some characters", domainName)
+.message("Invalid request for domain creation %s", domainName)
 .cause(e)
 .haltError();
 }
diff --git 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
index 82b88af391..7a61cc1a48 100644
--- 
a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
+++ 
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
@@ -117,6 +117,7 @@ class DomainsRoutesTest {
 
 RestAssured.requestSpecification = 
WebAdminUtils.buildRequestSpecification(webAdminServer)
 .setBasePath(DomainsRoutes.DOMAINS)
+.setUrlEncodingEnabled(false) // no further automatically encoding 
by Rest Assured client
 .build();
 }
 
@@ -332,7 +333,7 @@ class DomainsRoutesTest {
 }
 
 @Test
-void putShouldReturnUserErrorWhenNameContainsUrlEncodedUrlOperator() {
+void putWithDomainNameContainsSlashEncodedShouldDecodeAndReturnError() 
{
 Map errors = when()
 .put(DOMAIN + "%2F" + DOMAIN)
 .then()
@@ -349,24 +350,6 @@ class DomainsRoutesTest {
 .containsEntry("message", "Invalid request for domain creation 
domain/domain");
 }
 
-@Test
-void 
putShouldReturnUserErrorWhenNameContainsInvalidUrlEncodedCharacters() {
-Map errors = when()
-.put(DOMAIN + "%GG" + DOMAIN)
-.then()
-.statusCode(HttpStatus.BAD_REQUEST_400)
-.contentType(ContentType.JSON)
-.extract()
-.body()
-.jsonPath()
-.getMap(".");
-
-assertThat(errors)
-.containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
-.containsEntry("type", "InvalidArgument")
-.containsEntry("message", "Invalid request for domain creation 
domain%GGdomain unable to url decode some characters");
-}
-
 @Test
 void putShouldReturnUserErrorWhenNameContainsUrlSeparator() {
 when()


-
To unsubscribe, e-mail: 

[GitHub] [james-project] chibenwa merged pull request #1697: JAMES-3936 Webadmin: Avoid double decoding request param

2023-08-25 Thread via GitHub


chibenwa merged PR #1697:
URL: https://github.com/apache/james-project/pull/1697


-- 
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-unsubscr...@james.apache.org

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


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



[GitHub] [james-project] chibenwa commented on pull request #1701: JAMES-3925 Rework JMAP quota cleaup

2023-08-25 Thread via GitHub


chibenwa commented on PR #1701:
URL: https://github.com/apache/james-project/pull/1701#issuecomment-1693899759

   [Test 
Result](https://ci-builds.apache.org/job/james/job/ApacheJames/job/PR-1701/1/testReport/)
 (1 failure )
   
   
[org.apache.james.jmap.cassandra.upload.CassandraUploadRepositoryTest.uploadShouldExpire](https://ci-builds.apache.org/job/james/job/ApacheJames/job/PR-1701/1/testReport/junit/org.apache.james.jmap.cassandra.upload/CassandraUploadRepositoryTest/uploadShouldExpire/)


-- 
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-unsubscr...@james.apache.org

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


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



[GitHub] [james-project] chibenwa commented on a diff in pull request #1701: JAMES-3925 Rework JMAP quota cleaup

2023-08-25 Thread via GitHub


chibenwa commented on code in PR #1701:
URL: https://github.com/apache/james-project/pull/1701#discussion_r1306115545


##
server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/upload/UploadDAO.java:
##
@@ -183,13 +172,18 @@ public UploadDAO(CqlSession session, BlobId.Factory 
blobIdFactory, UploadConfigu
 .whereColumn(USER).isEqualTo(bindMarker(USER))
 .whereColumn(ID).isEqualTo(bindMarker(ID))
 .build());
+
+this.listByUploadDateLessThan = session.prepare(selectFrom(TABLE_NAME)
+.all()
+.allowFiltering()
+.whereColumn(UPLOAD_DATE).isLessThan(bindMarker(UPLOAD_DATE))

Review Comment:
   Do not push the where clause to the DB and prefer doing app side filtering 
IMO



-- 
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-unsubscr...@james.apache.org

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


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



[GitHub] [james-project] chibenwa commented on a diff in pull request #1701: JAMES-3925 Rework JMAP quota cleaup

2023-08-25 Thread via GitHub


chibenwa commented on code in PR #1701:
URL: https://github.com/apache/james-project/pull/1701#discussion_r1306115111


##
server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/upload/UploadDAO.java:
##
@@ -183,13 +172,18 @@ public UploadDAO(CqlSession session, BlobId.Factory 
blobIdFactory, UploadConfigu
 .whereColumn(USER).isEqualTo(bindMarker(USER))
 .whereColumn(ID).isEqualTo(bindMarker(ID))
 .build());
+
+this.listByUploadDateLessThan = session.prepare(selectFrom(TABLE_NAME)
+.all()
+.allowFiltering()

Review Comment:
   Why?



##
server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/upload/UploadDAO.java:
##
@@ -183,13 +172,18 @@ public UploadDAO(CqlSession session, BlobId.Factory 
blobIdFactory, UploadConfigu
 .whereColumn(USER).isEqualTo(bindMarker(USER))
 .whereColumn(ID).isEqualTo(bindMarker(ID))
 .build());
+
+this.listByUploadDateLessThan = session.prepare(selectFrom(TABLE_NAME)
+.all()
+.allowFiltering()

Review Comment:
   Why?



-- 
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-unsubscr...@james.apache.org

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


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



[GitHub] [james-project] chibenwa commented on a diff in pull request #1701: JAMES-3925 Rework JMAP quota cleaup

2023-08-25 Thread via GitHub


chibenwa commented on code in PR #1701:
URL: https://github.com/apache/james-project/pull/1701#discussion_r1306114115


##
server/container/guice/cassandra/src/main/java/org/apache/james/modules/data/CassandraJmapModule.java:
##
@@ -80,7 +79,6 @@ protected void configure() {
 bind(CassandraUploadRepository.class).in(Scopes.SINGLETON);
 bind(UploadDAO.class).in(Scopes.SINGLETON);
 bind(UploadRepository.class).to(CassandraUploadRepository.class);
-
bind(UploadConfiguration.class).toInstance(UploadConfiguration.SINGLETON);

Review Comment:
   Modify documentation?



-- 
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-unsubscr...@james.apache.org

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


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



[GitHub] [james-project] chibenwa commented on a diff in pull request #1702: JAMES-3926 Adopt Cassandra quota helpers for Mailbox (current) quota

2023-08-25 Thread via GitHub


chibenwa commented on code in PR #1702:
URL: https://github.com/apache/james-project/pull/1702#discussion_r1306111557


##
mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/quota/migration/CassandraCurrentQuotaManagerMigrationTest.java:
##
@@ -0,0 +1,127 @@
+/
+ * 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.mailbox.cassandra.quota.migration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.commons.configuration2.BaseHierarchicalConfiguration;
+import org.apache.james.backends.cassandra.CassandraCluster;
+import org.apache.james.backends.cassandra.CassandraClusterExtension;
+import org.apache.james.backends.cassandra.components.CassandraModule;
+import 
org.apache.james.backends.cassandra.components.CassandraMutualizedQuotaModule;
+import 
org.apache.james.backends.cassandra.components.CassandraQuotaCurrentValueDao;
+import 
org.apache.james.backends.cassandra.versions.CassandraSchemaVersionModule;
+import org.apache.james.blob.cassandra.CassandraBlobModule;
+import org.apache.james.core.Domain;
+import org.apache.james.core.Username;
+import org.apache.james.core.quota.QuotaCountUsage;
+import org.apache.james.core.quota.QuotaSizeUsage;
+import org.apache.james.domainlist.api.DomainList;
+import org.apache.james.domainlist.api.mock.SimpleDomainList;
+import org.apache.james.domainlist.cassandra.CassandraDomainListModule;
+import org.apache.james.mailbox.SessionProvider;
+import org.apache.james.mailbox.cassandra.CassandraMailboxSessionMapperFactory;
+import org.apache.james.mailbox.cassandra.CassandraTestSystemFixture;
+import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraModSeqModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraQuotaModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraThreadModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraUidModule;
+import org.apache.james.mailbox.cassandra.quota.CassandraCurrentQuotaManagerV1;
+import org.apache.james.mailbox.cassandra.quota.CassandraCurrentQuotaManagerV2;
+import org.apache.james.mailbox.model.CurrentQuotas;
+import org.apache.james.mailbox.model.QuotaOperation;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.UserQuotaRootResolver;
+import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
+import org.apache.james.user.api.UsersRepository;
+import org.apache.james.user.cassandra.CassandraUsersDAO;
+import org.apache.james.user.cassandra.CassandraUsersRepositoryModule;
+import org.apache.james.user.lib.UsersRepositoryImpl;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+public class CassandraCurrentQuotaManagerMigrationTest {
+public static final Username BOB = Username.of("bob");
+
+@RegisterExtension
+static CassandraClusterExtension cassandraCluster = new 
CassandraClusterExtension(CassandraModule.aggregateModules(
+CassandraQuotaModule.MODULE,
+CassandraUsersRepositoryModule.MODULE,
+CassandraDomainListModule.MODULE,
+CassandraMutualizedQuotaModule.MODULE,
+CassandraUidModule.MODULE,
+CassandraBlobModule.MODULE,
+CassandraMailboxModule.MODULE,
+CassandraModSeqModule.MODULE,
+CassandraThreadModule.MODULE,
+CassandraSchemaVersionModule.MODULE));

Review Comment:
   maybe a mock might actually be simpler here? (for once?)



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

[GitHub] [james-project] chibenwa commented on a diff in pull request #1702: JAMES-3926 Adopt Cassandra quota helpers for Mailbox (current) quota

2023-08-25 Thread via GitHub


chibenwa commented on code in PR #1702:
URL: https://github.com/apache/james-project/pull/1702#discussion_r1306110759


##
mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraCurrentQuotaManagerV2.java:
##
@@ -0,0 +1,111 @@
+/
+ * 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.mailbox.cassandra.quota;
+
+import java.util.function.Predicate;
+
+import javax.inject.Inject;
+
+import 
org.apache.james.backends.cassandra.components.CassandraQuotaCurrentValueDao;
+import 
org.apache.james.backends.cassandra.components.CassandraQuotaCurrentValueDao.QuotaKey;
+import org.apache.james.core.quota.QuotaComponent;
+import org.apache.james.core.quota.QuotaCountUsage;
+import org.apache.james.core.quota.QuotaCurrentValue;
+import org.apache.james.core.quota.QuotaSizeUsage;
+import org.apache.james.core.quota.QuotaType;
+import org.apache.james.mailbox.model.CurrentQuotas;
+import org.apache.james.mailbox.model.QuotaOperation;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.CurrentQuotaManager;
+
+import reactor.core.publisher.Mono;
+
+public class CassandraCurrentQuotaManagerV2 implements CurrentQuotaManager {
+private final CassandraQuotaCurrentValueDao currentValueDao;
+
+@Inject
+public CassandraCurrentQuotaManagerV2(CassandraQuotaCurrentValueDao 
currentValueDao) {
+this.currentValueDao = currentValueDao;
+}
+
+@Override
+public Mono getCurrentMessageCount(QuotaRoot quotaRoot) {
+return currentValueDao.getQuotaCurrentValue(asQuotaKeyCount(quotaRoot))
+.map(QuotaCurrentValue::getCurrentValue)
+.map(QuotaCountUsage::count)
+.defaultIfEmpty(QuotaCountUsage.count(0L));
+}
+
+@Override
+public Mono getCurrentStorage(QuotaRoot quotaRoot) {
+return currentValueDao.getQuotaCurrentValue(asQuotaKeySize(quotaRoot))
+.map(QuotaCurrentValue::getCurrentValue)
+.map(QuotaSizeUsage::size)
+.defaultIfEmpty(QuotaSizeUsage.size(0L));
+}
+
+@Override
+public Mono getCurrentQuotas(QuotaRoot quotaRoot) {
+return Mono.zip(
+getCurrentMessageCount(quotaRoot),
+getCurrentStorage(quotaRoot))
+.map(tuple2 -> new CurrentQuotas(tuple2.getT1(), tuple2.getT2()));
+}
+
+@Override
+public Mono increase(QuotaOperation quotaOperation) {
+return 
currentValueDao.increase(asQuotaKeyCount(quotaOperation.quotaRoot()), 
quotaOperation.count().asLong())
+
.then(currentValueDao.increase(asQuotaKeySize(quotaOperation.quotaRoot()), 
quotaOperation.size().asLong()));
+}
+
+@Override
+public Mono decrease(QuotaOperation quotaOperation) {
+return decrease(quotaOperation.quotaRoot(), quotaOperation.count(), 
quotaOperation.size());
+}
+
+private Mono decrease(QuotaRoot quotaRoot, QuotaCountUsage count, 
QuotaSizeUsage size) {
+return currentValueDao.decrease(asQuotaKeyCount(quotaRoot), 
count.asLong())
+.then(currentValueDao.decrease(asQuotaKeySize(quotaRoot), 
size.asLong()));
+}
+
+@Override
+public Mono setCurrentQuotas(QuotaOperation quotaOperation) {
+return getCurrentQuotas(quotaOperation.quotaRoot())
+
.filter(Predicate.not(Predicate.isEqual(CurrentQuotas.from(quotaOperation
+.flatMap(storedQuotas -> decrease(quotaOperation.quotaRoot(), 
storedQuotas.count(), storedQuotas.size())
+.then(increase(quotaOperation)));
+
+}

Review Comment:
   extra line



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

[GitHub] [james-project] chibenwa commented on a diff in pull request #1702: JAMES-3926 Adopt Cassandra quota helpers for Mailbox (current) quota

2023-08-25 Thread via GitHub


chibenwa commented on code in PR #1702:
URL: https://github.com/apache/james-project/pull/1702#discussion_r1306110097


##
mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraCurrentQuotaManagerV2.java:
##
@@ -0,0 +1,111 @@
+/
+ * 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.mailbox.cassandra.quota;
+
+import java.util.function.Predicate;
+
+import javax.inject.Inject;
+
+import 
org.apache.james.backends.cassandra.components.CassandraQuotaCurrentValueDao;
+import 
org.apache.james.backends.cassandra.components.CassandraQuotaCurrentValueDao.QuotaKey;
+import org.apache.james.core.quota.QuotaComponent;
+import org.apache.james.core.quota.QuotaCountUsage;
+import org.apache.james.core.quota.QuotaCurrentValue;
+import org.apache.james.core.quota.QuotaSizeUsage;
+import org.apache.james.core.quota.QuotaType;
+import org.apache.james.mailbox.model.CurrentQuotas;
+import org.apache.james.mailbox.model.QuotaOperation;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.CurrentQuotaManager;
+
+import reactor.core.publisher.Mono;
+
+public class CassandraCurrentQuotaManagerV2 implements CurrentQuotaManager {
+private final CassandraQuotaCurrentValueDao currentValueDao;
+
+@Inject
+public CassandraCurrentQuotaManagerV2(CassandraQuotaCurrentValueDao 
currentValueDao) {
+this.currentValueDao = currentValueDao;
+}
+
+@Override
+public Mono getCurrentMessageCount(QuotaRoot quotaRoot) {
+return currentValueDao.getQuotaCurrentValue(asQuotaKeyCount(quotaRoot))
+.map(QuotaCurrentValue::getCurrentValue)
+.map(QuotaCountUsage::count)
+.defaultIfEmpty(QuotaCountUsage.count(0L));
+}
+
+@Override
+public Mono getCurrentStorage(QuotaRoot quotaRoot) {
+return currentValueDao.getQuotaCurrentValue(asQuotaKeySize(quotaRoot))
+.map(QuotaCurrentValue::getCurrentValue)
+.map(QuotaSizeUsage::size)
+.defaultIfEmpty(QuotaSizeUsage.size(0L));
+}
+
+@Override
+public Mono getCurrentQuotas(QuotaRoot quotaRoot) {
+return Mono.zip(
+getCurrentMessageCount(quotaRoot),
+getCurrentStorage(quotaRoot))

Review Comment:
   Only the QotaType differ. If I'm not wrong we should be able to manage this 
in one primary key read...



-- 
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-unsubscr...@james.apache.org

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


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



[GitHub] [james-project] chibenwa commented on a diff in pull request #1699: JAMES-3925 Define an API to store current values of JMAP uploads

2023-08-25 Thread via GitHub


chibenwa commented on code in PR #1699:
URL: https://github.com/apache/james-project/pull/1699#discussion_r1306109000


##
server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/upload/CassandraUploadUsageRepository.java:
##
@@ -0,0 +1,67 @@
+/
+ * 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.cassandra.upload;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.Username;
+import org.apache.james.core.quota.QuotaComponent;
+import org.apache.james.core.quota.QuotaSizeUsage;
+import org.apache.james.core.quota.QuotaType;
+import org.apache.james.jmap.api.upload.UploadUsageRepository;
+import org.apache.james.mailbox.cassandra.quota.CassandraQuotaCurrentValueDao;
+
+import reactor.core.publisher.Mono;
+
+public class CassandraUploadUsageRepository implements UploadUsageRepository {
+
+private static final QuotaSizeUsage DEFAULT_QUOTA_SIZE_USAGE = 
QuotaSizeUsage.size(0);
+
+private CassandraQuotaCurrentValueDao cassandraQuotaCurrentValueDao;
+
+@Inject
+public CassandraUploadUsageRepository(CassandraQuotaCurrentValueDao 
cassandraQuotaCurrentValueDao) {
+this.cassandraQuotaCurrentValueDao = cassandraQuotaCurrentValueDao;
+}
+
+@Override
+public Mono increaseSpace(Username username, QuotaSizeUsage usage) {
+return 
cassandraQuotaCurrentValueDao.increase(CassandraQuotaCurrentValueDao.QuotaKey.of(QuotaComponent.JMAP_UPLOADS,
 username.asString(), QuotaType.SIZE),
+usage.asLong());
+}
+
+@Override
+public Mono decreaseSpace(Username username, QuotaSizeUsage usage) {
+return 
cassandraQuotaCurrentValueDao.decrease(CassandraQuotaCurrentValueDao.QuotaKey.of(QuotaComponent.JMAP_UPLOADS,
 username.asString(), QuotaType.SIZE),
+usage.asLong());
+}
+
+@Override
+public Mono getSpaceUsage(Username username) {
+return 
cassandraQuotaCurrentValueDao.getQuotaCurrentValue(CassandraQuotaCurrentValueDao.QuotaKey.of(QuotaComponent.JMAP_UPLOADS,
 username.asString(), QuotaType.SIZE))
+.map(quotaCurrentValue -> 
QuotaSizeUsage.size(quotaCurrentValue.getCurrentValue())).defaultIfEmpty(DEFAULT_QUOTA_SIZE_USAGE);
+}

Review Comment:
   Yes that would be ok



-- 
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-unsubscr...@james.apache.org

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


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



[GitHub] [james-project] quantranhong1999 commented on pull request #1697: JAMES-3936 Webadmin: Avoid double decoding request param

2023-08-25 Thread via GitHub


quantranhong1999 commented on PR #1697:
URL: https://github.com/apache/james-project/pull/1697#issuecomment-1693516373

   green => rebasing.


-- 
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-unsubscr...@james.apache.org

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


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



[GitHub] [james-project] Arsnael commented on a diff in pull request #1702: JAMES-3926 Adopt Cassandra quota helpers for Mailbox (current) quota

2023-08-25 Thread via GitHub


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


##
mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/quota/migration/CassandraCurrentQuotaManagerMigrationTest.java:
##
@@ -0,0 +1,127 @@
+/
+ * 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.mailbox.cassandra.quota.migration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.commons.configuration2.BaseHierarchicalConfiguration;
+import org.apache.james.backends.cassandra.CassandraCluster;
+import org.apache.james.backends.cassandra.CassandraClusterExtension;
+import org.apache.james.backends.cassandra.components.CassandraModule;
+import 
org.apache.james.backends.cassandra.components.CassandraMutualizedQuotaModule;
+import 
org.apache.james.backends.cassandra.components.CassandraQuotaCurrentValueDao;
+import 
org.apache.james.backends.cassandra.versions.CassandraSchemaVersionModule;
+import org.apache.james.blob.cassandra.CassandraBlobModule;
+import org.apache.james.core.Domain;
+import org.apache.james.core.Username;
+import org.apache.james.core.quota.QuotaCountUsage;
+import org.apache.james.core.quota.QuotaSizeUsage;
+import org.apache.james.domainlist.api.DomainList;
+import org.apache.james.domainlist.api.mock.SimpleDomainList;
+import org.apache.james.domainlist.cassandra.CassandraDomainListModule;
+import org.apache.james.mailbox.SessionProvider;
+import org.apache.james.mailbox.cassandra.CassandraMailboxSessionMapperFactory;
+import org.apache.james.mailbox.cassandra.CassandraTestSystemFixture;
+import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraModSeqModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraQuotaModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraThreadModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraUidModule;
+import org.apache.james.mailbox.cassandra.quota.CassandraCurrentQuotaManagerV1;
+import org.apache.james.mailbox.cassandra.quota.CassandraCurrentQuotaManagerV2;
+import org.apache.james.mailbox.model.CurrentQuotas;
+import org.apache.james.mailbox.model.QuotaOperation;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.UserQuotaRootResolver;
+import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
+import org.apache.james.user.api.UsersRepository;
+import org.apache.james.user.cassandra.CassandraUsersDAO;
+import org.apache.james.user.cassandra.CassandraUsersRepositoryModule;
+import org.apache.james.user.lib.UsersRepositoryImpl;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+public class CassandraCurrentQuotaManagerMigrationTest {
+public static final Username BOB = Username.of("bob");
+
+@RegisterExtension
+static CassandraClusterExtension cassandraCluster = new 
CassandraClusterExtension(CassandraModule.aggregateModules(
+CassandraQuotaModule.MODULE,
+CassandraUsersRepositoryModule.MODULE,
+CassandraDomainListModule.MODULE,
+CassandraMutualizedQuotaModule.MODULE,
+CassandraUidModule.MODULE,
+CassandraBlobModule.MODULE,
+CassandraMailboxModule.MODULE,
+CassandraModSeqModule.MODULE,
+CassandraThreadModule.MODULE,
+CassandraSchemaVersionModule.MODULE));

Review Comment:
   Honestly I have an issue here... Because of the 
CassandraMailboxSessionMapperFactory that I need because of the 
UserQuotaRootResolver, I have to inject a lot of modules... I'm not finished 
but I will fix it monday. 
   
   Just posting 

[GitHub] [james-project] Arsnael opened a new pull request, #1702: JAMES-3926 Adopt Cassandra quota helpers for Mailbox (current) quota

2023-08-25 Thread via GitHub


Arsnael opened a new pull request, #1702:
URL: https://github.com/apache/james-project/pull/1702

   (no comment)


-- 
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-unsubscr...@james.apache.org

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


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



[GitHub] [james-project] vttranlina opened a new pull request, #1701: JAMES-3925 Rework JMAP quota cleaup

2023-08-25 Thread via GitHub


vttranlina opened a new pull request, #1701:
URL: https://github.com/apache/james-project/pull/1701

   jira https://issues.apache.org/jira/browse/JAMES-3925


-- 
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-unsubscr...@james.apache.org

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


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



[GitHub] [james-project] hungphan227 commented on a diff in pull request #1699: JAMES-3925 Define an API to store current values of JMAP uploads

2023-08-25 Thread via GitHub


hungphan227 commented on code in PR #1699:
URL: https://github.com/apache/james-project/pull/1699#discussion_r1305308234


##
server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/upload/CassandraUploadUsageRepository.java:
##
@@ -0,0 +1,67 @@
+/
+ * 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.cassandra.upload;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.Username;
+import org.apache.james.core.quota.QuotaComponent;
+import org.apache.james.core.quota.QuotaSizeUsage;
+import org.apache.james.core.quota.QuotaType;
+import org.apache.james.jmap.api.upload.UploadUsageRepository;
+import org.apache.james.mailbox.cassandra.quota.CassandraQuotaCurrentValueDao;
+
+import reactor.core.publisher.Mono;
+
+public class CassandraUploadUsageRepository implements UploadUsageRepository {
+
+private static final QuotaSizeUsage DEFAULT_QUOTA_SIZE_USAGE = 
QuotaSizeUsage.size(0);
+
+private CassandraQuotaCurrentValueDao cassandraQuotaCurrentValueDao;
+
+@Inject
+public CassandraUploadUsageRepository(CassandraQuotaCurrentValueDao 
cassandraQuotaCurrentValueDao) {
+this.cassandraQuotaCurrentValueDao = cassandraQuotaCurrentValueDao;
+}
+
+@Override
+public Mono increaseSpace(Username username, QuotaSizeUsage usage) {
+return 
cassandraQuotaCurrentValueDao.increase(CassandraQuotaCurrentValueDao.QuotaKey.of(QuotaComponent.JMAP_UPLOADS,
 username.asString(), QuotaType.SIZE),
+usage.asLong());
+}
+
+@Override
+public Mono decreaseSpace(Username username, QuotaSizeUsage usage) {
+return 
cassandraQuotaCurrentValueDao.decrease(CassandraQuotaCurrentValueDao.QuotaKey.of(QuotaComponent.JMAP_UPLOADS,
 username.asString(), QuotaType.SIZE),
+usage.asLong());
+}
+
+@Override
+public Mono getSpaceUsage(Username username) {
+return 
cassandraQuotaCurrentValueDao.getQuotaCurrentValue(CassandraQuotaCurrentValueDao.QuotaKey.of(QuotaComponent.JMAP_UPLOADS,
 username.asString(), QuotaType.SIZE))
+.map(quotaCurrentValue -> 
QuotaSizeUsage.size(quotaCurrentValue.getCurrentValue())).defaultIfEmpty(DEFAULT_QUOTA_SIZE_USAGE);
+}

Review Comment:
   ok so we still return 0, log a warning and run recomputation asynchronously 
immediately. Is it ok?



-- 
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-unsubscr...@james.apache.org

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


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