You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/10/22 03:17:29 UTC

[james-project] branch master updated: JAMES-2344 UserQuotaRootResolver should allow linking QuotaRoot for other entity than users (#703)

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 663e517  JAMES-2344 UserQuotaRootResolver should allow linking QuotaRoot for other entity than users (#703)
663e517 is described below

commit 663e517d9b9506c0006115ebc0fba17eab7cca15
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Oct 22 10:16:58 2021 +0700

    JAMES-2344 UserQuotaRootResolver should allow linking QuotaRoot for other entity than users (#703)
    
     -> forUser is to be used when the username is strictly linked to a user
     -> forMailAddress is to be used when the username could reference another entity than a user.
---
 .../java/org/apache/james/mailbox/quota/UserQuotaRootResolver.java | 7 +++++++
 .../org/apache/james/quota/search/scanning/ClauseConverter.java    | 2 +-
 .../java/org/apache/james/webadmin/service/UserQuotaService.java   | 7 +++++--
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/UserQuotaRootResolver.java b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/UserQuotaRootResolver.java
index 6d3b7ab..e2c1fd8 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/UserQuotaRootResolver.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/UserQuotaRootResolver.java
@@ -25,4 +25,11 @@ public interface UserQuotaRootResolver extends QuotaRootResolver {
 
     QuotaRoot forUser(Username username);
 
+    /**
+     * When the username might not point to a user entity, and an extra translation step is required
+     * for the quota root.
+     */
+    default QuotaRoot forMailAddress(Username username) {
+        return forUser(username);
+    }
 }
diff --git a/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java b/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java
index 7cd1c61..47d52f9 100644
--- a/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java
+++ b/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java
@@ -94,7 +94,7 @@ public class ClauseConverter {
 
     private double retrieveUserRatio(Username username) {
         try {
-            QuotaRoot quotaRoot = quotaRootResolver.forUser(username);
+            QuotaRoot quotaRoot = quotaRootResolver.forMailAddress(username);
             QuotaManager.Quotas quotas = quotaManager.getQuotas(quotaRoot);
             Quota<QuotaSizeLimit, QuotaSizeUsage> storageQuota = quotas.getStorageQuota();
             Quota<QuotaCountLimit, QuotaCountUsage> messageQuota = quotas.getMessageQuota();
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserQuotaService.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserQuotaService.java
index 1f0c66f..22c9a02 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserQuotaService.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserQuotaService.java
@@ -80,7 +80,10 @@ public class UserQuotaService {
     }
 
     public QuotaDetailsDTO getQuota(Username username) throws MailboxException {
-        QuotaRoot quotaRoot = userQuotaRootResolver.forUser(username);
+        return getQuota(userQuotaRootResolver.forUser(username));
+    }
+
+    private QuotaDetailsDTO getQuota(QuotaRoot quotaRoot) throws MailboxException {
         QuotaManager.Quotas quotas = quotaManager.getQuotas(quotaRoot);
         QuotaDetailsDTO.Builder quotaDetails = QuotaDetailsDTO.builder()
             .occupation(quotas.getStorageQuota(),
@@ -144,7 +147,7 @@ public class UserQuotaService {
             .stream()
             .map(Throwing.function(user -> UsersQuotaDetailsDTO.builder()
                 .user(user)
-                .detail(getQuota(user))
+                .detail(getQuota(userQuotaRootResolver.forMailAddress(user)))
                 .build()))
             .collect(ImmutableList.toImmutableList());
     }

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