vttranlina commented on code in PR #2648:
URL: https://github.com/apache/james-project/pull/2648#discussion_r1969245298
##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/RLSSupportPostgresMailboxMapper.java:
##########
@@ -56,30 +57,36 @@ public Flux<Mailbox> findNonPersonalMailboxes(Username
userName, MailboxACL.Righ
@Override
public Mono<ACLDiff> updateACL(Mailbox mailbox, MailboxACL.ACLCommand
mailboxACLCommand) {
- MailboxACL oldACL = mailbox.getACL();
- MailboxACL newACL = Throwing.supplier(() ->
oldACL.apply(mailboxACLCommand)).get();
- ACLDiff aclDiff = ACLDiff.computeDiff(oldACL, newACL);
- PositiveUserACLDiff userACLDiff = new PositiveUserACLDiff(aclDiff);
- return upsertACL(mailbox, newACL, aclDiff, userACLDiff);
+ return postgresMailboxDAO.getACL(mailbox.getMailboxId())
+ .flatMap(pairMailboxACLAndVersion -> {
+ try {
+ MailboxACL newACL =
pairMailboxACLAndVersion.getLeft().apply(mailboxACLCommand);
+ return
postgresMailboxDAO.upsertACL(mailbox.getMailboxId(), newACL,
pairMailboxACLAndVersion.getRight())
+
.thenReturn(ACLDiff.computeDiff(pairMailboxACLAndVersion.getLeft(), newACL));
+ } catch (UnsupportedRightException e) {
+ throw new RuntimeException(e);
+ }
+ }).retryWhen(Retry.backoff(3, Duration.ofMillis(100))
+ .filter(throwable -> throwable instanceof
PostgresACLUpsertException))
+ .flatMap(aclDiff -> updateMembersOfMailbox(mailbox, new
PositiveUserACLDiff(aclDiff))
+ .thenReturn(aclDiff));
}
@Override
public Mono<ACLDiff> setACL(Mailbox mailbox, MailboxACL mailboxACL) {
- MailboxACL oldACL = mailbox.getACL();
- ACLDiff aclDiff = ACLDiff.computeDiff(oldACL, mailboxACL);
- PositiveUserACLDiff userACLDiff = new PositiveUserACLDiff(aclDiff);
- return upsertACL(mailbox, mailboxACL, aclDiff, userACLDiff);
+ return postgresMailboxDAO.getACL(mailbox.getMailboxId())
+ .flatMap(pairMailboxACLAndVersion ->
+ postgresMailboxDAO.upsertACL(mailbox.getMailboxId(),
mailboxACL, pairMailboxACLAndVersion.getRight())
+
.thenReturn(ACLDiff.computeDiff(pairMailboxACLAndVersion.getLeft(),
mailboxACL))).retryWhen(Retry.backoff(3, Duration.ofMillis(100))
+ .filter(throwable -> throwable instanceof
PostgresACLUpsertException))
+ .flatMap(aclDiff -> updateMembersOfMailbox(mailbox, new
PositiveUserACLDiff(aclDiff))
+ .thenReturn(aclDiff));
}
- private Mono<ACLDiff> upsertACL(Mailbox mailbox, MailboxACL newACL,
ACLDiff aclDiff, PositiveUserACLDiff userACLDiff) {
- return postgresMailboxDAO.upsertACL(mailbox.getMailboxId(), newACL)
-
.then(postgresMailboxMemberDAO.delete(PostgresMailboxId.class.cast(mailbox.getMailboxId()),
- userACLDiff.removedEntries().map(entry ->
Username.of(entry.getKey().getName())).toList()))
+ private Mono<Void> updateMembersOfMailbox(Mailbox mailbox,
PositiveUserACLDiff userACLDiff) {
+ return
postgresMailboxMemberDAO.delete(PostgresMailboxId.class.cast(mailbox.getMailboxId()),
+ userACLDiff.removedEntries().map(entry ->
Username.of(entry.getKey().getName())).toList())
Review Comment:
discussed with Hung
resolved
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]