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 2022/04/19 04:03:59 UTC
[james-project] 08/49: JAMES-3737 Reactify IMAP GETQUOTAROOT
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 ebdcda0f2df107783d76a24faf87879b9b76c32d
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 25 17:43:10 2022 +0700
JAMES-3737 Reactify IMAP GETQUOTAROOT
---
.../org/apache/james/mailbox/RightManager.java | 2 +
.../james/mailbox/store/StoreMailboxManager.java | 5 ++
.../james/mailbox/store/StoreMessageManager.java | 2 +-
.../james/mailbox/store/StoreRightManager.java | 1 +
.../imap/processor/GetQuotaRootProcessor.java | 62 +++++++++++++---------
5 files changed, 46 insertions(+), 26 deletions(-)
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
index 7ec2421b74..b8e627d7f9 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
@@ -45,6 +45,8 @@ public interface RightManager {
*/
boolean hasRight(MailboxPath mailboxPath, Right right, MailboxSession session) throws MailboxException;
+ boolean hasRight(Mailbox mailbox, Right right, MailboxSession session) throws MailboxException;
+
/**
* Tells whether the given {@link MailboxSession}'s user has the given
* {@link MailboxACL.Right} for this {@link MessageManager}'s mailbox.
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index d4a8034d74..d27c95088b 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -835,6 +835,11 @@ public class StoreMailboxManager implements MailboxManager {
return storeRightManager.hasRight(mailboxPath, right, session);
}
+ @Override
+ public boolean hasRight(Mailbox mailbox, Right right, MailboxSession session) throws MailboxException {
+ return storeRightManager.hasRight(mailbox, right, session);
+ }
+
@Override
public boolean hasRight(MailboxId mailboxId, Right right, MailboxSession session) throws MailboxException {
return storeRightManager.hasRight(mailboxId, right, session);
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index 7335ee67ca..8407d56c54 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -194,7 +194,7 @@ public class StoreMessageManager implements MessageManager {
* Return the underlying {@link Mailbox}
*/
- public Mailbox getMailboxEntity() throws MailboxException {
+ public Mailbox getMailboxEntity() {
return mailbox;
}
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
index 53b20dab6f..319d353873 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
@@ -83,6 +83,7 @@ public class StoreRightManager implements RightManager {
return block(Mono.from(myRights(mailboxId, session))).contains(right);
}
+ @Override
public boolean hasRight(Mailbox mailbox, Right right, MailboxSession session) {
return myRights(mailbox, session).contains(right);
}
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java
index 5c561b93fe..97a05e3e1d 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java
@@ -41,14 +41,16 @@ import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.Quota;
-import org.apache.james.mailbox.model.QuotaRoot;
import org.apache.james.mailbox.quota.QuotaManager;
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.util.MDCBuilder;
+import com.github.fge.lambdas.Throwing;
import com.google.common.collect.ImmutableList;
+import reactor.core.publisher.Mono;
+
/**
* GETQUOTAROOT Processor
*/
@@ -71,40 +73,50 @@ public class GetQuotaRootProcessor extends AbstractMailboxProcessor<GetQuotaRoot
}
@Override
- protected void processRequest(GetQuotaRootRequest request, ImapSession session, Responder responder) {
+ protected Mono<Void> processRequestReactive(GetQuotaRootRequest request, ImapSession session, Responder responder) {
final MailboxSession mailboxSession = session.getMailboxSession();
final MailboxManager mailboxManager = getMailboxManager();
final MailboxPath mailboxPath = PathConverter.forSession(session).buildFullPath(request.getMailboxName());
// First check mailbox exists
- try {
- if (mailboxManager.hasRight(mailboxPath, MailboxACL.Right.Read, mailboxSession)) {
- QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailboxPath);
- QuotaManager.Quotas quotas = quotaManager.getQuotas(quotaRoot);
- Quota<QuotaCountLimit, QuotaCountUsage> messageQuota = quotas.getMessageQuota();
- Quota<QuotaSizeLimit, QuotaSizeUsage> storageQuota = quotas.getStorageQuota();
- responder.respond(new QuotaRootResponse(request.getMailboxName(), quotaRoot.getValue()));
- if (messageQuota.getLimit().isLimited()) {
- responder.respond(new QuotaResponse(ImapConstants.MESSAGE_QUOTA_RESOURCE, quotaRoot.getValue(), messageQuota));
- }
- if (storageQuota.getLimit().isLimited()) {
- responder.respond(new QuotaResponse(ImapConstants.STORAGE_QUOTA_RESOURCE, quotaRoot.getValue(), storageQuota));
- }
- okComplete(request, responder);
- } else {
- Object[] params = new Object[]{
+ return Mono.from(mailboxManager.getMailboxReactive(mailboxPath, mailboxSession))
+ .flatMap(Throwing.function(messageManager -> {
+ if (mailboxManager.hasRight(messageManager.getMailboxEntity(), MailboxACL.Right.Read, mailboxSession)) {
+ return respondQuotas(request, responder, mailboxPath);
+ } else {
+ Object[] params = new Object[]{
MailboxACL.Right.Read.toString(),
request.getCommand().getName(),
request.getMailboxName()
- };
- HumanReadableText humanReadableText = new HumanReadableText(HumanReadableText.UNSUFFICIENT_RIGHTS_KEY, HumanReadableText.UNSUFFICIENT_RIGHTS_DEFAULT_VALUE, params);
- no(request, responder, humanReadableText);
- }
- } catch (MailboxException me) {
- taggedBad(request, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX);
- }
+ };
+ HumanReadableText humanReadableText = new HumanReadableText(HumanReadableText.UNSUFFICIENT_RIGHTS_KEY, HumanReadableText.UNSUFFICIENT_RIGHTS_DEFAULT_VALUE, params);
+ no(request, responder, humanReadableText);
+ return Mono.empty();
+ }
+ }));
+ }
+ private Mono<Void> respondQuotas(GetQuotaRootRequest request, Responder responder, MailboxPath mailboxPath) {
+ return Mono.from(quotaRootResolver.getQuotaRootReactive(mailboxPath))
+ .flatMap(quotaRoot -> Mono.from(quotaManager.getQuotasReactive(quotaRoot))
+ .doOnNext(quotas -> {
+ Quota<QuotaCountLimit, QuotaCountUsage> messageQuota = quotas.getMessageQuota();
+ Quota<QuotaSizeLimit, QuotaSizeUsage> storageQuota = quotas.getStorageQuota();
+ responder.respond(new QuotaRootResponse(request.getMailboxName(), quotaRoot.getValue()));
+ if (messageQuota.getLimit().isLimited()) {
+ responder.respond(new QuotaResponse(ImapConstants.MESSAGE_QUOTA_RESOURCE, quotaRoot.getValue(), messageQuota));
+ }
+ if (storageQuota.getLimit().isLimited()) {
+ responder.respond(new QuotaResponse(ImapConstants.STORAGE_QUOTA_RESOURCE, quotaRoot.getValue(), storageQuota));
+ }
+ okComplete(request, responder);
+ }))
+ .onErrorResume(MailboxException.class, e -> {
+ taggedBad(request, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX);
+ return Mono.empty();
+ })
+ .then();
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org